
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
@hai.dinh/service-libraries
Advanced tools
A collection of utilities for services in mircoservice-poc
The easiest way to install service-libraries is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
$ npm install @hai.dinh/service-libraries
Being inspired by AWS Lambda response for API Gateway styling, this function retrieves your response, which being like AWS Lambda response, then transform to express response
function simpleResponse(req) {
return {
statusCode: 200,
body: {
message: 'Hello World !'
},
headers: {
'Content-Type': 'application/json'
}
}
}
...
import express from 'express';
import { httpHandler } from '@hai.dinh/service-libraries';
const app = express();
app.get('/hello-world', httpHandler(simpleResponse))
schemaValidator is basically instance of ajv (to validate data with the corresponding schema), including pre-defined basic configuration.
To use schemaValidator, follow the instruction
import { schemaValidator } from '@hai.dinh/service-libraries';
const validator = schemaValidator.compile(schema);
const isValid = validator(yourData);
if (!isValid) {
console.log('Your data is invalid.', validator.errors)
}
Taking file service-env.json (render by service-registry-cli pull) as input, ServiceClientFactory acts as service discovery in microservice system to find the endpoint of targeted service. To use this, do the following:
import { ServiceClientFactory } from '@hai.dinh/service-libraries';
...
const serviceClient = await ServiceClientFactory.create(<service-id>);
const response = await serviceClient.request(config)
// Send a POST request
const res = await serviceClient.request({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
ServiceClientFactory uses axios behind the scene. For full configuration, you can get in here.
import { StorageClient } from '@hai.dinh/service-libraries';
const storageClient = await StorageClient.create();
const record = await storageClient.create(documentPath, {
"Content": documentContent,
"Type": documentType,
"Attributes": documentAttributs,
})
const storageClient = await StorageClient.create();
const record = await storageClient.get(documentPath)
const storageClient = await StorageClient.create();
const record = await storageClient.list(options)
const storageClient = await StorageClient.create();
const record = await storageClient.update(documentPath, {
"Content": documentContent,
"Type": documentType,
"Attributes": documentAttributs,
})
const storageClient = await StorageClient.create();
const record = await storageClient.delete(documentPath)
traceRequest middleware allow Express application to capture and foward X-Request-ID from original request headers, then set it to process environment variable for other libraries(logger, http client ...) can consume it
import { traceRequest } from '@hai.dinh/service-libraries/middlewares';
...
// in your service (Express)
const app = express();
app.use(traceRequest)
console.log(process.env['X-Request-Id'])
useInstrumentation provides instrumentation to support logging for application. Log will be streamed to stdout and saved to file log/app.log
import { useInstrumentation } from '@hai.dinh/service-libraries/middlewares';
...
// in your service (Express)
const app = express();
app.use(useInstrumentation)
// get instrumentation from your request
app.get('/', (req, res) => {
const { instrumentation } = res;
})
instrumentation.trace('Process started!');
// Output
// If X-Request-ID is NA
// [2010-01-17 11:43:37.987] [TRACE] - - Process started!
// IF X-Request-ID is available (by useTraceRequest)
// [2010-01-17 11:43:37.987] [TRACE] 1212121 - Process started!
instrumentation.debug('Got notification');
// Output
// If X-Request-ID is NA
// [2010-01-17 11:43:37.987] [DEBUG] - - Got notification!
// IF X-Request-ID is available (by useTraceRequest)
// [2010-01-17 11:43:37.987] [DEBUG] 1212121 - Got notification!
instrumentation.info('Hello World!');
// Output
// If X-Request-ID is NA
// [2010-01-17 11:43:37.987] [INFO] - - Hello World!
// IF X-Request-ID is available (by useTraceRequest)
// [2010-01-17 11:43:37.987] [INFO] 1212121 - Hello World!
instrumentation.warn('Warn!');
// Output
// If X-Request-ID is NA
// [2010-01-17 11:43:37.987] [WARN] - - Warn!
// IF X-Request-ID is available (by useTraceRequest)
// [2010-01-17 11:43:37.987] [WARN] 121313 - Warn!
instrumentation.error('Error!');
// Output
// If X-Request-ID is NA
// [2010-01-17 11:43:37.987] [ERROR] - - Error!
// IF X-Request-ID is available (by useTraceRequest)
// [2010-01-17 11:43:37.987] [ERROR] 123212 - Error!
useHttpLogger allow your Express server to log http as CSL format.
Below is the example of log
127.0.0.1 - haidv@gmail.com [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://referer.com" "PostmanRuntime/7.23.0" vxve23sdgs45sdvw
log-format = %(addr) %(ident) %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status)
%(size) "%(referer)" "%(uagent)" %(requestid)
import { useHttpLogger } from '@hai.dinh/service-libraries/middlewares';
...
// in your service (Express)
const app = express();
app.use(useHttpLogger)
FAQs
Utilized libraries for services
We found that @hai.dinh/service-libraries demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.