Common library in MAXBUILD
npm install @maxbuild/commonCommon library in MAXBUILD
- Setup
- Distributed identity
- ErrorCode
- Msg
- Auth
npm i @maxbuild/common
set config in tsconfig.json
```
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
use api
`js
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
`js
import {Identity} from '@maxbuild/common'
class Demo {
@Identity
id: string;
}
// a unique id.
new Demo().id
`
`js
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'
`
Network message package.
`js
import {Msg, errorCode} from '@maxbuild/common';
let msg:Msg = {
err_code: errorCode.OK,
err_msg: 'error message',
err_subcode: 'bll error code',
data: {
...
}
}
`
Get response user auth info.
`js
import {auth} from '@maxbuild/common';
auth.headerTenantIdKey // of-tid
auth.headerUserIdKey // of-uid
auth.getTenantId(restObj)
auth.getUserId(restObj)
auth.getFeignData(restObj)
``