0.0.6 • Published 3 years ago

@maxbuild/common v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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)
0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago