UNPKG

@commercetools-frontend/application-shell-connectors

Version:
45 lines (44 loc) 2.15 kB
import type { TAppliedPermission, TAppliedActionRight, TStoreDataFence } from "../../types/generated/mc.js"; export type TPermissions = { [key: string]: boolean; }; export type TActionRight = { [key: string]: boolean; }; export type TActionRights = { [key: string]: TActionRight; }; export type TDataFenceGroupedByPermission = { [key: string]: { values: string[]; } | null; }; export type TDataFenceGroupedByResourceType = { [key: string]: TDataFenceGroupedByPermission | null; }; export type TDataFenceStoresGroupByResourceType = { [key: string]: TStoreDataFence[]; }; export type TDataFenceType = 'store'; export type TDataFences = Partial<Record<TDataFenceType, TDataFenceGroupedByResourceType>>; /** * NOTE: * * Permissions and menu visibilities are being fetched though the `allAppliedPermissions` * and the `allAppliedMenuVisibilities` which both return an array of `{ name: string, value: boolean }`. * This gives more flexibility to introduce new values to apps without having to release * the merchant-center-app-kit by adding/exposing them from the mc-be (our proxy service). * * The application below however expects both permissions an menu visibilities to be of the shape * `[name: string]: boolean` which is what the shape above is mapped into here. This object shape is easier * to work with in application level code (while be a non breaking change to other packages) as you can just * do `canViewProducts`. * * This function considering its concern belongs into the `permissions` package. However, * for now it doesn't have to be shared and as a result can be co-located with * the fetching logic. Given this mapping needs to be used elsewere feel free * to move this over to `permissions` and export it there. */ export declare const normalizeAllAppliedPermissions: (allAppliedPermissions?: TAppliedPermission[]) => TPermissions | null; export declare const normalizeAllAppliedActionRights: (allAppliedActionRights?: TAppliedActionRight[]) => TActionRights | null; export declare const normalizeAllAppliedDataFences: (allAppliedDataFences?: TStoreDataFence[]) => TDataFences | null;