Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit d696018

Browse files
committed
utils ok
1 parent b4913b0 commit d696018

22 files changed

+864
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ npm-debug.log*
1313
yarn-debug.log*
1414
yarn-error.log*
1515
yarn.lock
16+
17+
jest.env

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ addons:
1616
- kafkacat
1717
- redis-tools
1818

19-
2019
before_install:
2120
# install kafka
2221
- docker run -d -p 9092:9092 -p 2181:2181 -p 2888:2888 -p 3888:3888 mohamnag/kafka-zookeeper
2322
- sleep 60 # wait for kafka
23+
- kafkacat -b localhost:9092 -L # check for kafka
2424

25-
# install redis
25+
# check redis installation
2626
- redis-cli keys \*
2727

28-
# check kafka
29-
- kafkacat -b localhost:9092 -L
30-
31-
# test
28+
# check version
3229
- node --version
30+
31+
# copy jest.env
32+
- cp jest.env.example jest.env

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ Either its kafka, redis, or, nats, or something else. Thats we start to have a m
99

1010
This curated list i made, is try to put abstraction on top of these libraries.
1111

12+
## Installation
13+
14+
Actually for us personally, we use this curated as "sdk". As it can be used along with chosen framework.
15+
16+
`yarn add sdk@npm:ncurated`
17+
18+
then you can use this so called "sdk".
19+
20+
```javascript
21+
const sdk = require('sdk');
22+
23+
24+
```
25+
1226
## Integration
1327

1428
This curated list is not really binding into a Framework.
@@ -18,8 +32,49 @@ Please feel free to use any framework to use. \*as long as its compatible :-)
1832

1933
### Cache
2034

35+
- cache-manager
36+
- cache-manager-redis-store
37+
38+
Initialized and encapsulated with bluebird. `Promise.promisifyAll(cacheManager)`, thank me later.
39+
40+
This say way we can use something like `sdk.cache.setAsync("a", 1)`.
41+
42+
#### Example
43+
44+
```javascript
45+
46+
await sdk.cache.setAsync("a", 1);
47+
48+
const a = sdk.cache.getAsync("a");
49+
50+
const b = await sdk.cache.wrap('b', () => Promise.resolve('foo'));
51+
```
52+
2153
### Log
2254

55+
After some extensive reading for logger library, we have come a cross decision to use bunyan here.
56+
This bunyan include options for:
57+
58+
- bunyan-debug-stream
59+
- bunyan-slack
60+
- bunyan-teams
61+
- bunyan-cloudwatch
62+
63+
64+
#### Example
65+
66+
```javascript
67+
68+
await sdk.log.info("you can refer to bunyan documentation for this log object :-p");
69+
```
70+
71+
#### Bunyan.RingBuffer
72+
73+
Bunyan ringbuffer is enabled by default. So we can use to track logs, even in unit test mode.
74+
75+
try to get ringBuffer object? this how we do that: `sdk.log.ringBuffer`.
76+
77+
2378
### Metrics
2479

2580

@@ -35,8 +90,20 @@ Please feel free to use any framework to use. \*as long as its compatible :-)
3590
## Mutex
3691

3792

93+
## Awesome Libraries
94+
95+
\*bluebird, rxjs, node-machine, moment. No more explanation for these awesome libraries.
96+
3897
## Requirements
3998

4099
Although some of the packages, it can be running at as log as node 8.11.
41100

42-
Its recommended to run it in current supported LTS version. (Dubnium parhaps?).
101+
Its recommended to run it in current supported LTS version. (Dubnium perhaps?).
102+
103+
## Changelog
104+
105+
Actually this curated list used only for private use before, therefore we have some changelog related to decision
106+
107+
**v1.12.0 (old name)**
108+
109+
Removed bunyan-elasticsearch, as we use cloudwatch more and more. But feel free to raise a request to add it once again.

jest.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
KAFKA_BROKER=localhost
2+
3+
REDIS_CONNECTION_STRING=redis://localhost:6379/1

jest.setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const { matchers: jsonSchemaMatchers } = require('jest-json-schema');
22

3+
// yarn
4+
require('dotenv')
5+
.config({
6+
path: require('path').resolve(process.cwd(), 'jest.env'),
7+
});
8+
39
// extends
410
expect.extend(jsonSchemaMatchers);
511

package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,43 @@
1010
"node": ">=8.11"
1111
},
1212
"devDependencies": {
13+
"dotenv": "^8.2.0",
1314
"eslint": "^6.5.1",
1415
"eslint-config-airbnb-base": "^14.0.0",
1516
"eslint-plugin-import": "^2.18.2",
1617
"eslint-plugin-jest": "^22.20.0",
18+
"faker": "^4.1.0",
1719
"jest": "^24.9.0",
18-
"jest-json-schema": "^2.1.0",
19-
"npm-run-all": "^4.1.5"
20+
"jest-json-schema": "^2.1.0"
2021
},
2122
"scripts": {
2223
"start": "node --trace-warnings node_modules/.bin/jest --passWithNoTests --watch --runInBand --detectOpenHandles",
2324
"test": "node --trace-warnings node_modules/.bin/jest --passWithNoTests --coverage --runInBand --detectOpenHandles",
24-
"lint": "eslint --fix src/ tests/ examples/ snippets/",
25+
"lint": "eslint --fix src/ tests/",
2526
"node:version": "node --version"
2627
},
2728
"jest": {
2829
"testEnvironment": "node",
2930
"setupFilesAfterEnv": [
3031
"./jest.setup.js"
3132
]
33+
},
34+
"dependencies": {
35+
"aws-sdk": "^2.669.0",
36+
"bluebird": "^3.7.2",
37+
"bunyan": "^1.8.12",
38+
"bunyan-cloudwatch": "^2.2.0",
39+
"bunyan-debug-stream": "^2.0.0",
40+
"bunyan-slack": "^0.0.10",
41+
"bunyan-teams": "^1.0.1",
42+
"cache-manager": "^3.3.0",
43+
"cache-manager-redis-store": "^2.0.0",
44+
"connection-string": "^3.2.2",
45+
"flaverr": "^1.10.0",
46+
"lodash": "^4.17.15",
47+
"machine": "^15.2.2",
48+
"moment": "^2.25.3",
49+
"rxjs": "^6.5.5",
50+
"uuid": "^8.0.0"
3251
}
3352
}

src/defaultConfigs/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
APP_NAME: 'UnnamedApp',
3+
APP_LOGO_PRINT: true,
4+
};

src/defaultConfigs/authorization.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
full: {
3+
AUTHORIZATION_DRIVER: 'faker',
4+
AUTHORIZATION_CONNECTION_STRING: 'http://localhost:80/graphql',
5+
AUTHORIZATION_SSL_ENABLE: false,
6+
AUTHORIZATION_SSL_REJECT_UNAUTHORIZED: false,
7+
AUTHORIZATION_SSL_CA_FILE: '',
8+
AUTHORIZATION_SSL_KEY_FILE: '',
9+
AUTHORIZATION_SSL_CERT_FILE: '',
10+
},
11+
development: {
12+
AUTHORIZATION_DRIVER: 'faker',
13+
AUTHORIZATION_CONNECTION_STRING: 'http://localhost:80/graphql',
14+
AUTHORIZATION_SSL_ENABLE: false,
15+
},
16+
production: {
17+
AUTHORIZATION_DRIVER: 'faker',
18+
AUTHORIZATION_CONNECTION_STRING: 'http://localhost:80/graphql',
19+
AUTHORIZATION_SSL_ENABLE: false,
20+
},
21+
};

src/defaultConfigs/cache.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
full: {
3+
CACHE_MEMORY_ENABLE: false,
4+
CACHE_MEMORY_MAX: 1000,
5+
CACHE_MEMORY_TTL: 60,
6+
7+
CACHE_REDIS_ENABLE: false,
8+
CACHE_REDIS_URL: null, // if this provided, then all host port style can be ignored
9+
CACHE_REDIS_HOST: '127.0.0.1',
10+
CACHE_REDIS_PORT: 6379,
11+
CACHE_REDIS_PASS: '',
12+
CACHE_REDIS_DB: 1,
13+
CACHE_REDIS_TTL: 60,
14+
},
15+
development: {
16+
CACHE_MEMORY_ENABLE: true,
17+
},
18+
production: {
19+
CACHE_MEMORY_ENABLE: false,
20+
CACHE_REDIS_ENABLE: false,
21+
},
22+
};

src/defaultConfigs/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const defaultApp = require('./app');
2+
const defaultLog = require('./log');
3+
const defaultCache = require('./cache');
4+
const defaultAuthorization = require('./authorization');
5+
const defaultStream = require('./stream');
6+
const defaultMutex = require('./mutex');
7+
const defaultZipkin = require('./zipkin');
8+
9+
module.exports = {
10+
development: {
11+
...defaultApp,
12+
...defaultLog.full,
13+
...defaultLog.development,
14+
...defaultCache.full,
15+
...defaultCache.development,
16+
...defaultAuthorization.full,
17+
...defaultAuthorization.development,
18+
...defaultStream.full,
19+
...defaultStream.development,
20+
...defaultMutex.full,
21+
...defaultMutex.development,
22+
...defaultZipkin.full,
23+
...defaultZipkin.development,
24+
},
25+
production: {
26+
...defaultApp,
27+
...defaultLog.full,
28+
...defaultLog.production,
29+
...defaultCache.full,
30+
...defaultCache.production,
31+
...defaultAuthorization.full,
32+
...defaultAuthorization.production,
33+
...defaultStream.full,
34+
...defaultStream.production,
35+
...defaultMutex.full,
36+
...defaultMutex.production,
37+
...defaultZipkin.full,
38+
...defaultZipkin.production,
39+
},
40+
};

src/defaultConfigs/log.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
full: {
3+
LOG_DEBUG_ENABLE: false,
4+
5+
LOG_STDOUT_ENABLE: true,
6+
LOG_STDOUT_LEVEL: 'trace',
7+
8+
// ring buffer enabled by default
9+
LOG_RINGBUFFER_LEVEL: 'info',
10+
LOG_RINGBUFFER_LIMIT: 100,
11+
12+
LOG_TEAMS_ENABLE: false,
13+
LOG_TEAMS_LEVEL: 'error',
14+
LOG_TEAMS_URL: 'https://outlook.office.com/webhook/ba57dfc.....d117daf812',
15+
16+
LOG_CLOUDWATCH_ENABLE: false,
17+
LOG_CLOUDWATCH_LEVEL: 'error',
18+
LOG_CLOUDWATCH_GROUP_NAME: '',
19+
LOG_CLOUDWATCH_STREAM_NAME: '',
20+
},
21+
development: {
22+
LOG_STDOUT_ENABLE: false,
23+
LOG_RINGBUFFER_LEVEL: 'trace',
24+
},
25+
production: {
26+
LOG_STDOUT_ENABLE: false,
27+
},
28+
};

src/defaultConfigs/mutex.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
full: {
3+
MUTEX_DRIVER: 'memory',
4+
MUTEX_CONNECTION_STRING: '',
5+
MUTEX_SSL_ENABLE: false,
6+
MUTEX_SSL_REJECT_UNAUTHORIZED: false,
7+
MUTEX_SSL_CA_FILE: '',
8+
MUTEX_SSL_KEY_FILE: '',
9+
MUTEX_SSL_CERT_FILE: '',
10+
},
11+
development: {
12+
MUTEX_DRIVER: 'memory',
13+
MUTEX_CONNECTION_STRING: '',
14+
MUTEX_SSL_ENABLE: false,
15+
},
16+
production: {
17+
MUTEX_DRIVER: 'memory',
18+
MUTEX_CONNECTION_STRING: 'redis://anonymous:redispasshere@localhost:6379/1',
19+
MUTEX_SSL_ENABLE: false,
20+
},
21+
};

src/defaultConfigs/stream.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
full: {
3+
STREAM_DRIVER: 'redis-mock',
4+
STREAM_CONNECTION_STRING: 'redis://localhost:6379/1',
5+
STREAM_SSL_ENABLE: false,
6+
STREAM_SSL_REJECT_UNAUTHORIZED: false,
7+
STREAM_SSL_CA_FILE: '',
8+
STREAM_SSL_KEY_FILE: '',
9+
STREAM_SSL_CERT_FILE: '',
10+
11+
STREAM_FALLBACK_ENABLE: false,
12+
STREAM_FALLBACK_DRIVER: 'redis-mock',
13+
STREAM_FALLBACK_CONNECTION_STRING: 'redis://localhost:6379/1',
14+
STREAM_FALLBACK_SSL_ENABLE: false,
15+
STREAM_FALLBACK_SSL_REJECT_UNAUTHORIZED: false,
16+
STREAM_FALLBACK_SSL_CA_FILE: '',
17+
STREAM_FALLBACK_SSL_KEY_FILE: '',
18+
STREAM_FALLBACK_SSL_CERT_FILE: '',
19+
},
20+
development: {
21+
STREAM_DRIVER: 'redis-mock',
22+
STREAM_CONNECTION_STRING: 'redis://localhost:6379/1',
23+
STREAM_SSL_ENABLE: false,
24+
25+
STREAM_FALLBACK_ENABLE: false,
26+
},
27+
production: {
28+
STREAM_DRIVER: 'redis-mock',
29+
STREAM_CONNECTION_STRING: 'redis://localhost:6379/1',
30+
STREAM_SSL_ENABLE: false,
31+
32+
STREAM_FALLBACK_ENABLE: false,
33+
},
34+
};

src/defaultConfigs/zipkin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
full: {
3+
ZIPKIN_ENABLE: true,
4+
ZIPKIN_DRIVER: 'http',
5+
ZIPKIN_HTTP_ENDPOINT: 'http://zipkin-service:9411/api/v2/spans',
6+
},
7+
development: {
8+
ZIPKIN_ENABLE: false,
9+
ZIPKIN_DRIVER: 'none',
10+
},
11+
production: {
12+
ZIPKIN_ENABLE: false,
13+
ZIPKIN_DRIVER: 'none', // mostly not needed to use zipkin, is it?
14+
},
15+
};

0 commit comments

Comments
 (0)