1.0.4 • Published 2 years ago

npm-eros v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Staff TGW

Installation

npm i staff-tgw --registry https://npm.thegioiwhey.com

Usage

Import
import Staff from "staff-tgw";
Init class
const staff = new Staff("url-for-auth");
Login
type User = {
  id: number,
  firstName: string,
  lastName: string,
  avatar: string,
  positionName: string,
};

type LoginResponse = {
  accessToken: string,
  user: User,
};

// Solution 1:
staff.login({
  body: {
    username: "your-username",
    password: "your-password",
  },
  onSuccess(data) {
    // do something when success
  },
  onWrongCredentials() {
    //do something when wrong password or username
  },
  onError(error) {
    // do something when other errors
  },
});

// Solution 2:

const { code, data } = await staff.login({
  body: {
    username: "your-username",
    password: "your-password",
  },
});

code = 0; // login success
code = 409; // wrong username or password
Propsis requiredDescription
bodytrueBody of login request, including username and password
onSuccessfalseA function executed when login success
onWrongCredentialsfalseA function executed when wrong username or password
onErrorfalseA function executed when other errors
Check permission
type CheckPermissionBody = {
  resourceCode: string,
  actionCodes: string[],
  type: "one" | "all",
};

type CheckPermissionResponse = {
  hasPermission: boolean,
  userId: number,
};

staff.checkPermission({
  accessToken: "your-access-token",
  body: {
    resourceCode: "your-resource-code",
    type: "all",
    actionCodes: ["action-code-1", "action-code-2"],
  },
  onSuccess(data: CheckPermissionResponse) {},
  onUnauthorized() {},
  onError(error) {},
});
Propsis requiredDescription
accessTokentrueAccess token
bodytrueBody of check permission request
onSuccessfalseA function executed when login success
onUnauthorizedfalseA function executed when wrong access token
onErrorfalseA function executed when other errors
Get roles
type AuthRoleResponse = {
  roleActions: {
    resourceCode: string,
    actions: {
      code: string,
      label: string,
      isAllowed: boolean,
    }[],
  }[],
  userId: number,
};

staff.getRoles({
  accessToken: "your-access-token",
  onSuccess(data: AuthRoleResponse) {},
  onUnauthorized() {},
  onError(error) {},
});
Propsis requiredDescription
accessTokentrueAccess token
onSuccessfalseA function executed when success
onUnauthorizedfalseA function executed when wrong access token
onErrorfalseA function executed when other errors
1.0.2

2 years ago

1.0.4

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago