Common library
Setup
npm i @bpfaas/common
set config in tsconfig.json
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
Distributed identity
use api
import {identity} from '@bpfaas/common'
let id = identity.nextId();
if (!identity.isValidId(id)) {
}
identity.idLength == 32
use decorator
import {Identity} from '@bpfaas/common'
class Demo {
@Identity
id: string;
}
new Demo().id
ErrorCode
import {errorCode, isErrorCode, getErrorCodeMsg} from '@bpfaas/common';
errorCode.OK
errorCode.OK_SYNC
errorCode.PARAMETER_ERROR
errorCode.UNAUTHORIZE
errorCode.NOT_FOUND
errorCode.OPERATOR_EXPIRED
errorCode.OPERATOR_ERROR
errorCode.APPCALL_LIMITED
errorCode.OPERATOR_LIMITED
errorCode.SERVICE_ERROR
errorCode.SERVICE_UNAVAILABLE
isErrorCode(200) == true
getErrorCodeMsg(errorCode.OPERATOR_EXPIRED)
Msg
Network message package.
import {Msg, errorCode} from '@bpfaas/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 '@bpfaas/common';
auth.headerTenantIdKey
auth.headerUserIdKey
auth.getTenantId(restObj)
auth.getUserId(restObj)
auth.getFeignData(restObj)