@bringg/dashboard-sdk

中文文档
10.0.0发布于 2026/11/10ISCTypeScriptCommonJS近 30 天下载 3804

Bringg dashboard SDK

原始使用文档
文档目录13 节
  1. Examples:
  2. Running tests
  3. Running test in watch mode
  4. Linting your code with tsLint
  5. Fixing your code with prettier
  6. Linting your code and fixing it with one command(will run l…
  7. Compile your awesome code for production
  8. Entity Store
  9. Http Service
  10. Public API
  11. BaseStore
  12. Entities Generator
  13. Next Steps:

codecov

BRINGG DASHBOARD SDK

Examples:

Web ( >= ES5 )

<!doctype html>
<html lang="en">
<head>
  <!-- ... -->
  <script src="/bringg-dashboard-sdk.js"></script>
</head>
<body>
<!-- ... -->
<script>
BringgDashboardSDK.initWithEmail(email, password).then(bringgDashboardSDK => {
  bringgDashboardSDK.merchant.get().then(console.log).catch(console.error);
  bringgDashboardSDK.merchantConfiguration.get().then(console.log).catch(console.error);
});

BringgDashboardSDK.initWithAuthToken(region, authToken).then(bringgDashboardSDK => {
  bringgDashboardSDK.merchant.get().then(console.log).catch(console.error);
  bringgDashboardSDK.merchantConfiguration.get().then(console.log).catch(console.error);
});
</script>
</body>
</html>

Node.js ( >= ES5 )

const BringgDashboardSDK = require("bringg-dashboard-sdk");

BringgDashboardSDK.initWithEmail(email, password).then(bringgDashboardSDK => {
  bringgDashboardSDK.merchant.get().then(console.log).catch(console.error);
  bringgDashboardSDK.merchantConfiguration.get().then(console.log).catch(console.error);
});

BringgDashboardSDK.initWithAuthToken(region, authToken).then(bringgDashboardSDK => {
  bringgDashboardSDK.merchant.get().then(console.log).catch(console.error);
  bringgDashboardSDK.merchantConfiguration.get().then(console.log).catch(console.error);
});

TypeScript ( >= 2.6 )

import BringgDashboardSDK = require("bringg-dashboard-sdk");

async function runAwait() {
  try {
    const bringgDashboardSDK = await BringgDashboardSDK.initWithEmail(email, password);
    console.log(await bringgDashboardSDK.merchant.get());
    console.log(await bringgDashboardSDK.merchantConfiguration.get());
  } catch (e) {
    console.error(e);
  }

  try {
    const bringgDashboardSDK = await BringgDashboardSDK.initWithAuthToken(region, authToken);
    console.log(await bringgDashboardSDK.merchant.get());
    console.log(await bringgDashboardSDK.merchantConfiguration.get());
  } catch (e) {
    console.error(e);
  }
}

runAwait();

Running tests

yarn test

Running test in watch mode

yarn jest

Linting your code with tsLint

yarn lint

Fixing your code with prettier

yarn prettier

Linting your code and fixing it with one command(will run lint and prettier)

yarn fix

Compile your awesome code for production

yarn prod

DashboardSDK - Guidelines to writing new entities - 10/4/19

Each entity should have 3 parts - Public API, Entity Store, Http Service.

Previous Status

For example we want to expose VehicleType to our end users, we go to the sdk and first add Actions folder.

Code Example
export enum VehicleTypesActionTypes {
  GET_VEHICLE_TYPES = 'GET_VEHICLE_TYPES',
  MARK_VEHICLE_TYPES_FETCHED = 'MARK_VEHICLE_TYPES_FETCHED',
  SAVE_REQUEST_ERROR = 'SAVE_REQUEST_ERROR',
}

export const Routes = {
  GET_VEHICLE_TYPES: new Route('/vehicle_types', HttpMethod.GET),
};

export function storeVehicleTypesAction(vehicleTypes: VehicleType[]): Actions<VehicleTypesActionTypes> {
  return {
    type: VehicleTypesActionTypes.GET_VEHICLE_TYPES,
    payload: vehicleTypes,
  };
}

export function markVehicleTypesFetchedAction(isFetched: boolean): Actions<VehicleTypesActionTypes> {
  return {
    type: VehicleTypesActionTypes.MARK_VEHICLE_TYPES_FETCHED,
    payload: isFetched,
  };
}

export function saveRequestErrorAction(requestType: VehicleTypesRequests, error: Error): Actions<VehicleTypesActionTypes> {
  return {
    type: VehicleTypesActionTypes.SAVE_REQUEST_ERROR,
    payload: {
      requestType,
      error,
    },
  };
}

export const vehicleTypessExtractor = (response: VehicleTypesResponse) => response.vehicle_types;

export const getVehicleTypesRequestAction = (sessionService: SessionBasedService): any => async (dispatch): Promise<Actions<VehicleTypesActionTypes>> => {
  {
    try {
      const vehicleTypes: VehicleType[] = await sessionService.handleAuthorizedRequest<VehicleTypesResponse, VehicleType[]>(
        Routes.GET_VEHICLE_TYPES,
        vehicleTypessExtractor,
        BringgException.serviceException('failed to get vehicles'),
      );

      dispatch(markVehicleTypesFetchedAction(true));

      return await dispatch(storeVehicleTypesAction(vehicleTypes));
    } catch (e) {
      await dispatch(saveRequestErrorAction(VehicleTypesRequests.GET_VEHICLE_TYPES, e));
      throw e;
    }
  }
};

We continue to next folder Reducers.

Code Example
export const initState = fromJS({
  items: {},
  requests: {},
  fetched: false,
});

type requestErrorLog = requestErrors<VehicleTypesRequests>;

export type vehicleTypesState = ImmutableMap<{
  items: Map<number, VehicleType>;
  requests: ImmutableMap<requestErrorLog>;
  fetched: boolean;
}>;

export const storeVehicleTypes = (state: vehicleTypesState, vehicleTypes: VehicleType[]): vehicleTypesState =>
  state.set('items', immutableKeyBy(vehicleTypes, 'id'));

export const markVehicleTypesFetched = (state: vehicleTypesState, isFetched: boolean = true) => state.setIn(['fetched'], isFetched);

export const logRequestError = (state, requestType: VehicleTypesRequests, error: Error) => {
  return state.withMutations(state =>
    state.setIn(['requests', requestType, 'error'], error.toString()).setIn(['requests', requestType, 'timestamp'], Date.now()),
  );
};

export const vehicleTypesReducers = (state: vehicleTypesState = initState, action): vehicleTypesState => {
  switch (action.type) {
    case VehicleTypesActionTypes.SAVE_REQUEST_ERROR:
      return logRequestError(state, action.payload.requestType, action.payload.error);
    case VehicleTypesActionTypes.GET_VEHICLE_TYPES:
      return storeVehicleTypes(state, action.payload);
    case VehicleTypesActionTypes.MARK_VEHICLE_TYPES_FETCHED:
      return markVehicleTypesFetched(state, action.payload);
    default:
      return state;
  }
};

Then we go on and add a Service folder.

Code Example
export default class VehicleTypesService extends SessionBasedService {
  private store: Redux.Store<CompleteStateStructure>;

  constructor(session: Session) {
    super(session.config.getApiEndpoint(), session);
    this.store = session.state.store;
  }

  @singleConcurrent()
  public async getAll(): Promise<VehicleType[]> {
    if (!this.areVehicleTypesFetched()) {
      await this.store.dispatch(getVehicleTypesRequestAction(this));
    }

    return this.getAllVehicleTypes();
  }

  private getAllVehicleTypes = (): VehicleType[] => {
    return this.store
      .getState()
      .vehicleTypes.getIn(['items'])
      .toList()
      .toJS();
  };

  private areVehicleTypesFetched = (): boolean => {
    return this.store.getState().vehicleTypes.getIn(['fetched']);
  };
}


Then we finally can expose our API folder :)

Code Example
export default class VehicleTypes {
  private vehicleTypesService: VehicleTypesService;

  constructor(session: Session) {
    this.vehicleTypesService = new VehicleTypesService(session);
  }

  public async getAll(): Promise<VehicleType[]> {
    return await this.vehicleTypesService.getAll();
  }
}

Almost 200 hundred lines of code just to expose simply getAll of VehicleTypes.

We tried to simplify the proccess by creating BaseStore and using it in each new entity store instead of rewriting it each time.

Entity Store

We want to keep each entity state up to date always(http requests, realtime events), so we use store managment class to do it.

From now on we can use a new class named BaseStore which will be our base of every entity and manage its state.

For Example:

export default class ChatConversationStore extends BaseStore<ChatConversation>

Here we can extend our BaseStore and use it however we see fit to the new entity we develop(take from store if exists, if not fetch from server and store it).

  async getConversation(id: number): Promise<ChatConversation> {
    const chatConversation = this.getItem(id) || this._fetchConversation(id);

    return await chatConversation;
  }

Http Service

Http service is pretty much the same all over the sdk, here is simple example.

  GET_CHAT_CONVERSATION: new Route('/chat_conversations/{:id}', HttpMethod.GET)

  public async getChatConversation(id): Promise<ChatConversation> {
    const chatConversationResponse:  ChatConversationResponse = await this.handleAuthorizedRequest<ChatConversationResponse, ChatConversationResponse>(
      Routes.GET_CHAT_CONVERSATION, //route
      defaultExtractor, // extractor func can be passed here
      BringgException.serviceException('Failed to get chat conversation'),
      undefined, //payload
      { id }, //route params
      {}, // query params
    );

    return chatConversationResponse.conversation;
  }

Public API

Here we decide which endpoints and events we want to expose to the end user, which will be called from the entity store.

Example from ChatConversation

this.onItemRemoved = this.chatConversationStore.onItemRemoved; // remove event

public getConversation(id: number): Promise<ChatConversation> {
    return this.chatConversationStore.getConversation(id); // get item endpoint
}

BaseStore

Here we implemented RxJS,

we have our main stream of items $items which on each action(create,update,remove) we emit to the stream and accordingly aggregate the most update state.

Each store extends this class can use $items stream to aggregate which data he wants.(for example from tasks stream aggreate only open tasks.. )

  state$: Observable<Map<number, T>>; // aggregated state from main stream
  protected items$: Subject<Action>; // 1 main stream of items

  // Event Handlers
  protected onItemUpdateEvent: (item: T) => void = _.noop;
  protected onItemCreatedEvent: (item: T) => void = _.noop;
  protected onItemRemovedEvent: (item: number) => void = _.noop;
  protected onListUpdateEvent: (items: T[]) => void = _.noop;

  getItem = (itemId): T // Get Item From Store By Id

  addToStore(item: T) // Add item to store

  updateInStore(item: T) // update item in store

  getItems = (): T[] // get array of items of latest state in store

  addItems(items: T[]) // add array of items

  onItemCreated = (fn: (item: T) => void) => // set event handler for item removed

  onItemUpdate = (fn: (item: T) => void) => // set event handler for item updated

  onItemRemoved = (fn: (itemId: number) => void) // set event handler for item removed

  onListUpdate = (fn: (item: T[]) => void) // set event handler for list update

Entities Generator

In order to save time and make your life easier, there is a script to generate the basic implementation needed.

You can run it with : npm run entity-generator [name] [bringg-type-name]

The script will create a folder called [name] inside src folder.

The folder will include Service, Store and a few more files with basic implementation and according to our convention.

Next Steps:

In order to improve our SDK and our developing proccess.

  • Combine Store and Service to one.(instead of copy pasting same service all the time)

版本与发布记录

@bringg/dashboard-sdk 共发布 1,220 个版本,首次发布于 2018/10/04;过去 12 个月发布了 186 个版本。

版本发布日期距今
10.0.0latest2026/11/10今天
9.96.0-pre.5pre2026/11/064 天前
9.96.0-pre.42026/11/036 天前
9.96.0-pre.32026/11/036 天前
9.96.0-pre.12026/11/018 天前
9.95.12026/10/3010 天前

关于 @bringg/dashboard-sdk 的常见问题

@bringg/dashboard-sdk 是什么?

Bringg dashboard SDK

如何安装 @bringg/dashboard-sdk?

在项目目录运行 npm install @bringg/dashboard-sdk,或使用 pnpm add / yarn add / bun add。

@bringg/dashboard-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bringg/dashboard-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bringg/dashboard-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 22.*。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bringg/dashboard-sdk 可以商用吗?

@bringg/dashboard-sdk 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bringg/dashboard-sdk 的下载量有多少?

根据 npm 官方下载统计,@bringg/dashboard-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,804 次,日均约 127 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bringg/dashboard-sdk 还在维护吗?

最新版本 10.0.0 发布于 2026/11/10(今天);至今共发布 1220 个版本,其中过去 12 个月发布了 186 个;首次发布于 2018/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。