@maxbuild/common
v0.0.6
Published
Common library in MAXBUILD
Downloads
63
Readme
Common library in MAXBUILD
Setup
npm i @maxbuild/common
set config in tsconfig.json
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
Distributed identity
use api
import {identity} from '@maxbuild/common'
// a unique id.
let id = identity.nextId();
// test id.
if (!identity.isValidId(id)) {
}
// id length.
identity.idLength == 32
use decorator
import {Identity} from '@maxbuild/common'
class Demo {
@Identity
id: string;
}
// a unique id.
new Demo().id
ErrorCode
import {errorCode, isErrorCode, getErrorCodeMsg} from '@maxbuild/common';
// get the errCode
errorCode.OK // 200
errorCode.OK_SYNC // 202
errorCode.PARAMETER_ERROR // 400
errorCode.UNAUTHORIZE // 401
errorCode.NOT_FOUND // 404
errorCode.OPERATOR_EXPIRED // 408
errorCode.OPERATOR_ERROR // 417
errorCode.APPCALL_LIMITED // 444
errorCode.OPERATOR_LIMITED // 445
errorCode.SERVICE_ERROR // 500
errorCode.SERVICE_UNAVAILABLE // 504
isErrorCode(200) == true
getErrorCodeMsg(errorCode.OPERATOR_EXPIRED) // 'OPERATOR_EXPIRED'
Msg
Network message package.
import {Msg, errorCode} from '@maxbuild/common';
let msg:Msg = {
err_code: errorCode.OK,
err_msg: 'error message',
err_subcode: 'bll error code',
data: {
...
}
}
Auth
Get response user auth info.
import {auth} from '@maxbuild/common';
auth.headerTenantIdKey // of-tid
auth.headerUserIdKey // of-uid
auth.getTenantId(restObj)
auth.getUserId(restObj)
auth.getFeignData(restObj)