UNPKG

powerbi-client

Version:

JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and res

1,531 lines 93.6 kB
// powerbi-client v2.18.7 // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. declare module "config" { /** @ignore */ /** */ const config: { version: string; type: string; }; export default config; } declare module "errors" { export const APINotSupportedForRDLError = "This API is currently not supported for RDL reports"; export const EmbedUrlNotSupported = "Embed URL is invalid for this scenario. Please use Power BI REST APIs to get the valid URL"; } declare module "util" { import { HttpPostMessage } from 'http-post-message'; /** * Raises a custom event with event data on the specified HTML element. * * @export * @param {HTMLElement} element * @param {string} eventName * @param {*} eventData */ export function raiseCustomEvent(element: HTMLElement, eventName: string, eventData: any): void; /** * Finds the index of the first value in an array that matches the specified predicate. * * @export * @template T * @param {(x: T) => boolean} predicate * @param {T[]} xs * @returns {number} */ export function findIndex<T>(predicate: (x: T) => boolean, xs: T[]): number; /** * Finds the first value in an array that matches the specified predicate. * * @export * @template T * @param {(x: T) => boolean} predicate * @param {T[]} xs * @returns {T} */ export function find<T>(predicate: (x: T) => boolean, xs: T[]): T; export function remove<T>(predicate: (x: T) => boolean, xs: T[]): void; /** * Copies the values of all enumerable properties from one or more source objects to a target object, and returns the target object. * * @export * @param {any} args * @returns */ export function assign(...args: any[]): any; /** * Generates a random 5 to 6 character string. * * @export * @returns {string} */ export function createRandomString(): string; /** * Generates a 20 character uuid. * * @export * @returns {string} */ export function generateUUID(): string; /** * Adds a parameter to the given url * * @export * @param {string} url * @param {string} paramName * @param {string} value * @returns {string} */ export function addParamToUrl(url: string, paramName: string, value: string): string; /** * Checks if the report is saved. * * @export * @param {HttpPostMessage} hpm * @param {string} uid * @param {Window} contentWindow * @returns {Promise<boolean>} */ export function isSavedInternal(hpm: HttpPostMessage, uid: string, contentWindow: Window): Promise<boolean>; /** * Checks if the embed url is for RDL report. * * @export * @param {string} embedUrl * @returns {boolean} */ export function isRDLEmbed(embedUrl: string): boolean; /** * Checks if the embed url contains autoAuth=true. * * @export * @param {string} embedUrl * @returns {boolean} */ export function autoAuthInEmbedUrl(embedUrl: string): boolean; /** * Returns random number */ export function getRandomValue(): number; /** * Returns the time interval between two dates in milliseconds * * @export * @param {Date} start * @param {Date} end * @returns {number} */ export function getTimeDiffInMilliseconds(start: Date, end: Date): number; } declare module "embed" { import * as models from 'powerbi-models'; import { ICustomEvent, IEvent, IEventHandler, Service } from "service"; global { interface Document { mozCancelFullScreen: any; msExitFullscreen: any; webkitExitFullscreen: void; } interface HTMLIFrameElement { mozRequestFullScreen: Function; msRequestFullscreen: Function; webkitRequestFullscreen: { (): void; }; } } export type IBootstrapEmbedConfiguration = models.IBootstrapEmbedConfiguration; export type IEmbedConfigurationBase = models.IEmbedConfigurationBase; export type IEmbedConfiguration = models.IEmbedConfiguration; export type IVisualEmbedConfiguration = models.IVisualEmbedConfiguration; export type IReportEmbedConfiguration = models.IReportEmbedConfiguration; export type IDashboardEmbedConfiguration = models.IDashboardEmbedConfiguration; export type ITileEmbedConfiguration = models.ITileEmbedConfiguration; export type IQnaEmbedConfiguration = models.IQnaEmbedConfiguration; export type ILocaleSettings = models.ILocaleSettings; export type IQnaSettings = models.IQnaSettings; export type IEmbedSettings = models.ISettings; /** @hidden */ export interface IInternalEventHandler<T> { test(event: IEvent<T>): boolean; handle(event: ICustomEvent<T>): void; } /** * Base class for all Power BI embed components * * @export * @abstract * @hidden * @class Embed */ export abstract class Embed { /** @hidden */ static allowedEvents: string[]; /** @hidden */ static accessTokenAttribute: string; /** @hidden */ static embedUrlAttribute: string; /** @hidden */ static nameAttribute: string; /** @hidden */ static typeAttribute: string; /** @hidden */ static defaultEmbedHostName: string; /** @hidden */ static type: string; /** @hidden */ static maxFrontLoadTimes: number; /** @hidden */ allowedEvents: string[]; /** @hidden */ protected commands: models.ICommandExtension[]; /** @hidden */ protected initialLayoutType: models.LayoutType; /** @hidden */ groups: models.IMenuGroupExtension[]; /** * Gets or sets the event handler registered for this embed component. * * @type {IInternalEventHandler<any>[]} * @hidden */ eventHandlers: IInternalEventHandler<any>[]; /** * Gets or sets the Power BI embed service. * * @type {service.Service} * @hidden */ service: Service; /** * Gets or sets the HTML element that contains the Power BI embed component. * * @type {HTMLElement} * @hidden */ element: HTMLElement; /** * Gets or sets the HTML iframe element that renders the Power BI embed component. * * @type {HTMLIFrameElement} * @hidden */ iframe: HTMLIFrameElement; /** * Saves the iframe state. Each iframe should be loaded only once. * After first load, .embed will go into embedExisting path which will send * a postMessage of /report/load instead of creating a new iframe. * * @type {boolean} * @hidden */ iframeLoaded: boolean; /** * Gets or sets the configuration settings for the Power BI embed component. * * @type {IEmbedConfigurationBase} * @hidden */ config: IEmbedConfigurationBase; /** * Gets or sets the bootstrap configuration for the Power BI embed component received by powerbi.bootstrap(). * * @type {IBootstrapEmbedConfiguration} * @hidden */ bootstrapConfig: IBootstrapEmbedConfiguration; /** * Gets or sets the configuration settings for creating report. * * @type {models.IReportCreateConfiguration} * @hidden */ createConfig: models.IReportCreateConfiguration; /** * Url used in the load request. * * @hidden */ loadPath: string; /** * Url used in the load request. * * @hidden */ phasedLoadPath: string; /** * Type of embed * * @hidden */ embedtype: string; /** * Handler function for the 'ready' event * * @hidden */ frontLoadHandler: () => any; /** * The time the last /load request was sent * * @hidden */ lastLoadRequest: Date; /** * Creates an instance of Embed. * * Note: there is circular reference between embeds and the service, because * the service has a list of all embeds on the host page, and each embed has a reference to the service that created it. * * @param {service.Service} service * @param {HTMLElement} element * @param {IEmbedConfigurationBase} config * @hidden */ constructor(service: Service, element: HTMLElement, config: IEmbedConfigurationBase, iframe?: HTMLIFrameElement, phasedRender?: boolean, isBootstrap?: boolean); /** * Sends createReport configuration data. * * ```javascript * createReport({ * datasetId: '5dac7a4a-4452-46b3-99f6-a25915e0fe55', * accessToken: 'eyJ0eXA ... TaE2rTSbmg', * ``` * * @hidden * @param {models.IReportCreateConfiguration} config * @returns {Promise<void>} */ createReport(config: models.IReportCreateConfiguration): Promise<void>; /** * Saves Report. * * @returns {Promise<void>} */ save(): Promise<void>; /** * SaveAs Report. * * @returns {Promise<void>} */ saveAs(saveAsParameters: models.ISaveAsParameters): Promise<void>; /** * Get the correlationId for the current embed session. * * ```javascript * // Get the correlationId for the current embed session * report.getCorrelationId() * .then(correlationId => { * ... * }); * ``` * * @returns {Promise<string>} */ getCorrelationId(): Promise<string>; /** * Sends load configuration data. * * ```javascript * report.load({ * type: 'report', * id: '5dac7a4a-4452-46b3-99f6-a25915e0fe55', * accessToken: 'eyJ0eXA ... TaE2rTSbmg', * settings: { * navContentPaneEnabled: false * }, * pageName: "DefaultPage", * filters: [ * { * ... DefaultReportFilter ... * } * ] * }) * .catch(error => { ... }); * ``` * * @hidden * @param {models.ILoadConfiguration} config * @param {boolean} phasedRender * @returns {Promise<void>} */ load(phasedRender?: boolean): Promise<void>; /** * Removes one or more event handlers from the list of handlers. * If a reference to the existing handle function is specified, remove the specific handler. * If the handler is not specified, remove all handlers for the event name specified. * * ```javascript * report.off('pageChanged') * * or * * const logHandler = function (event) { * console.log(event); * }; * * report.off('pageChanged', logHandler); * ``` * * @template T * @param {string} eventName * @param {IEventHandler<T>} [handler] */ off<T>(eventName: string, handler?: IEventHandler<T>): void; /** * Adds an event handler for a specific event. * * ```javascript * report.on('pageChanged', (event) => { * console.log('PageChanged: ', event.page.name); * }); * ``` * * @template T * @param {string} eventName * @param {service.IEventHandler<T>} handler */ on<T>(eventName: string, handler: IEventHandler<T>): void; /** * Reloads embed using existing configuration. * E.g. For reports this effectively clears all filters and makes the first page active which simulates resetting a report back to loaded state. * * ```javascript * report.reload(); * ``` */ reload(): Promise<void>; /** * Set accessToken. * * @returns {Promise<void>} */ setAccessToken(accessToken: string): Promise<void>; /** * Gets an access token from the first available location: config, attribute, global. * * @private * @param {string} globalAccessToken * @returns {string} * @hidden */ private getAccessToken; /** * Populate config for create and load * * @hidden * @param {IEmbedConfiguration} * @returns {void} */ populateConfig(config: IBootstrapEmbedConfiguration, isBootstrap: boolean): void; /** * Adds locale parameters to embedUrl * * @private * @param {IEmbedConfiguration | models.ICommonEmbedConfiguration} config * @hidden */ private addLocaleToEmbedUrl; /** * Gets an embed url from the first available location: options, attribute. * * @private * @returns {string} * @hidden */ private getEmbedUrl; /** * @hidden */ private getDefaultEmbedUrl; /** * Gets a unique ID from the first available location: options, attribute. * If neither is provided generate a unique string. * * @private * @returns {string} * @hidden */ private getUniqueId; /** * Gets the group ID from the first available location: options, embeddedUrl. * * @private * @returns {string} * @hidden */ private getGroupId; /** * Gets the report ID from the first available location: options, attribute. * * @abstract * @returns {string} */ abstract getId(): string; /** * Raise a config changed event. * * @hidden * @returns {void} */ abstract configChanged(isBootstrap: boolean): void; /** * Gets default embed endpoint for each entity. * For example: report embed endpoint is reportEmbed. * This will help creating a default embed URL such as: https://app.powerbi.com/reportEmbed * * @hidden * @returns {string} endpoint. */ abstract getDefaultEmbedUrlEndpoint(): string; /** * Requests the browser to render the component's iframe in fullscreen mode. */ fullscreen(): void; /** * Requests the browser to exit fullscreen mode. */ exitFullscreen(): void; /** * Returns true if the iframe is rendered in fullscreen mode, * otherwise returns false. * * @private * @param {HTMLIFrameElement} iframe * @returns {boolean} * @hidden */ private isFullscreen; /** * Validate load and create configuration. * * @hidden */ abstract validate(config: IEmbedConfigurationBase): models.IError[]; /** * Sets Iframe for embed * * @hidden */ private setIframe; /** * Set the component title for accessibility. In case of iframes, this method will change the iframe title. */ setComponentTitle(title: string): void; /** * Sets element's tabindex attribute */ setComponentTabIndex(tabIndex?: number): void; /** * Removes element's tabindex attribute */ removeComponentTabIndex(_tabIndex?: number): void; /** * Adds the ability to get groupId from url. * By extracting the ID we can ensure that the ID is always explicitly provided as part of the load configuration. * * @hidden * @static * @param {string} url * @returns {string} */ static findGroupIdFromEmbedUrl(url: string): string; /** * Sends the config for front load calls, after 'ready' message is received from the iframe * * @hidden */ private frontLoadSendConfig; } } declare module "ifilterable" { import { FiltersOperations, IFilter } from 'powerbi-models'; import { IHttpPostMessageResponse } from 'http-post-message'; /** * Decorates embed components that support filters * Examples include reports and pages * * @export * @interface IFilterable */ export interface IFilterable { /** * Gets the filters currently applied to the object. * * @returns {(Promise<IFilter[]>)} */ getFilters(): Promise<IFilter[]>; /** * Update the filters for the current instance according to the operation: Add, replace all, replace by target or remove. * * @param {(FiltersOperations)} operation * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Removes all filters from the current object. * * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Replaces all filters on the current object with the specified filter values. * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>>; } } declare module "visualDescriptor" { import { ExportDataType, FiltersOperations, ICloneVisualRequest, ICloneVisualResponse, IExportDataResult, IFilter, ISlicerState, ISortByVisualRequest, IVisualLayout, VisualContainerDisplayMode } from 'powerbi-models'; import { IHttpPostMessageResponse } from 'http-post-message'; import { IFilterable } from "ifilterable"; import { IPageNode } from "page"; /** * A Visual node within a report hierarchy * * @export * @interface IVisualNode */ export interface IVisualNode { name: string; title: string; type: string; layout: IVisualLayout; page: IPageNode; } /** * A Power BI visual within a page * * @export * @class VisualDescriptor * @implements {IVisualNode} */ export class VisualDescriptor implements IVisualNode, IFilterable { /** * The visual name * * @type {string} */ name: string; /** * The visual title * * @type {string} */ title: string; /** * The visual type * * @type {string} */ type: string; /** * The visual layout: position, size and visibility. * * @type {string} */ layout: IVisualLayout; /** * The parent Power BI page that contains this visual * * @type {IPageNode} */ page: IPageNode; /** * @hidden */ constructor(page: IPageNode, name: string, title: string, type: string, layout: IVisualLayout); /** * Gets all visual level filters of the current visual. * * ```javascript * visual.getFilters() * .then(filters => { ... }); * ``` * * @returns {(Promise<IFilter[]>)} */ getFilters(): Promise<IFilter[]>; /** * Update the filters for the current visual according to the operation: Add, replace all, replace by target or remove. * * ```javascript * visual.updateFilters(FiltersOperations.Add, filters) * .catch(errors => { ... }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Removes all filters from the current visual. * * ```javascript * visual.removeFilters(); * ``` * * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Sets the filters on the current visual to 'filters'. * * ```javascript * visual.setFilters(filters); * .catch(errors => { ... }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Exports Visual data. * Can export up to 30K rows. * * @param rows: Optional. Default value is 30K, maximum value is 30K as well. * @param exportDataType: Optional. Default is ExportDataType.Summarized. * ```javascript * visual.exportData() * .then(data => { ... }); * ``` * * @returns {(Promise<IExportDataResult>)} */ exportData(exportDataType?: ExportDataType, rows?: number): Promise<IExportDataResult>; /** * Set slicer state. * Works only for visuals of type slicer. * * @param state: A new state which contains the slicer filters. * ```javascript * visual.setSlicerState() * .then(() => { ... }); * ``` */ setSlicerState(state: ISlicerState): Promise<IHttpPostMessageResponse<void>>; /** * Get slicer state. * Works only for visuals of type slicer. * * ```javascript * visual.getSlicerState() * .then(state => { ... }); * ``` * * @returns {(Promise<ISlicerState>)} */ getSlicerState(): Promise<ISlicerState>; /** * Clone existing visual to a new instance. * * @returns {(Promise<ICloneVisualResponse>)} */ clone(request?: ICloneVisualRequest): Promise<ICloneVisualResponse>; /** * Sort a visual by dataField and direction. * * @param request: Sort by visual request. * * ```javascript * visual.sortBy(request) * .then(() => { ... }); * ``` */ sortBy(request: ISortByVisualRequest): Promise<IHttpPostMessageResponse<void>>; /** * Updates the position of a visual. * * ```javascript * visual.moveVisual(x, y, z) * .catch(error => { ... }); * ``` * * @param {number} x * @param {number} y * @param {number} z * @returns {Promise<IHttpPostMessageResponse<void>>} */ moveVisual(x: number, y: number, z?: number): Promise<IHttpPostMessageResponse<void>>; /** * Updates the display state of a visual. * * ```javascript * visual.setVisualDisplayState(displayState) * .catch(error => { ... }); * ``` * * @param {VisualContainerDisplayMode} displayState * @returns {Promise<IHttpPostMessageResponse<void>>} */ setVisualDisplayState(displayState: VisualContainerDisplayMode): Promise<IHttpPostMessageResponse<void>>; /** * Resize a visual. * * ```javascript * visual.resizeVisual(width, height) * .catch(error => { ... }); * ``` * * @param {number} width * @param {number} height * @returns {Promise<IHttpPostMessageResponse<void>>} */ resizeVisual(width: number, height: number): Promise<IHttpPostMessageResponse<void>>; } } declare module "page" { import { IHttpPostMessageResponse } from 'http-post-message'; import { DisplayOption, FiltersOperations, ICustomPageSize, IFilter, IVisual, LayoutType, PageSizeType, SectionVisibility, VisualContainerDisplayMode, IPageBackground, IPageWallpaper } from 'powerbi-models'; import { IFilterable } from "ifilterable"; import { IReportNode } from "report"; import { VisualDescriptor } from "visualDescriptor"; /** * A Page node within a report hierarchy * * @export * @interface IPageNode */ export interface IPageNode { report: IReportNode; name: string; } /** * A Power BI report page * * @export * @class Page * @implements {IPageNode} * @implements {IFilterable} */ export class Page implements IPageNode, IFilterable { /** * The parent Power BI report that this page is a member of * * @type {IReportNode} */ report: IReportNode; /** * The report page name * * @type {string} */ name: string; /** * The user defined display name of the report page, which is undefined if the page is created manually * * @type {string} */ displayName: string; /** * Is this page is the active page * * @type {boolean} */ isActive: boolean; /** * The visibility of the page. * 0 - Always Visible * 1 - Hidden in View Mode * * @type {SectionVisibility} */ visibility: SectionVisibility; /** * Page size as saved in the report. * * @type {ICustomPageSize} */ defaultSize: ICustomPageSize; /** * Mobile view page size (if defined) as saved in the report. * * @type {ICustomPageSize} */ mobileSize: ICustomPageSize; /** * Page display options as saved in the report. * * @type {ICustomPageSize} */ defaultDisplayOption: DisplayOption; /** * Page background color. * * @type {IPageBackground} */ background: IPageBackground; /** * Page wallpaper color. * * @type {IPageWallpaper} */ wallpaper: IPageWallpaper; /** * Creates an instance of a Power BI report page. * * @param {IReportNode} report * @param {string} name * @param {string} [displayName] * @param {boolean} [isActivePage] * @param {SectionVisibility} [visibility] * @hidden */ constructor(report: IReportNode, name: string, displayName?: string, isActivePage?: boolean, visibility?: SectionVisibility, defaultSize?: ICustomPageSize, defaultDisplayOption?: DisplayOption, mobileSize?: ICustomPageSize, background?: IPageBackground, wallpaper?: IPageWallpaper); /** * Gets all page level filters within the report. * * ```javascript * page.getFilters() * .then(filters => { ... }); * ``` * * @returns {(Promise<IFilter[]>)} */ getFilters(): Promise<IFilter[]>; /** * Update the filters for the current page according to the operation: Add, replace all, replace by target or remove. * * ```javascript * page.updateFilters(FiltersOperations.Add, filters) * .catch(errors => { ... }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Removes all filters from this page of the report. * * ```javascript * page.removeFilters(); * ``` * * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Sets all filters on the current page. * * ```javascript * page.setFilters(filters) * .catch(errors => { ... }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Delete the page from the report * * ```javascript * // Delete the page from the report * page.delete(); * ``` * * @returns {Promise<void>} */ delete(): Promise<void>; /** * Makes the current page the active page of the report. * * ```javascript * page.setActive(); * ``` * * @returns {Promise<IHttpPostMessageResponse<void>>} */ setActive(): Promise<IHttpPostMessageResponse<void>>; /** * Set displayName to the current page. * * ```javascript * page.setName(displayName); * ``` * * @returns {Promise<IHttpPostMessageResponse<void>>} */ setDisplayName(displayName: string): Promise<IHttpPostMessageResponse<void>>; /** * Gets all the visuals on the page. * * ```javascript * page.getVisuals() * .then(visuals => { ... }); * ``` * * @returns {Promise<VisualDescriptor[]>} */ getVisuals(): Promise<VisualDescriptor[]>; /** * Gets a visual by name on the page. * * ```javascript * page.getVisualByName(visualName: string) * .then(visual => { * ... * }); * ``` * * @param {string} visualName * @returns {Promise<VisualDescriptor>} */ getVisualByName(visualName: string): Promise<VisualDescriptor>; /** * Updates the display state of a visual in a page. * * ```javascript * page.setVisualDisplayState(visualName, displayState) * .catch(error => { ... }); * ``` * * @param {string} visualName * @param {VisualContainerDisplayMode} displayState * @returns {Promise<IHttpPostMessageResponse<void>>} */ setVisualDisplayState(visualName: string, displayState: VisualContainerDisplayMode): Promise<IHttpPostMessageResponse<void>>; /** * Updates the position of a visual in a page. * * ```javascript * page.moveVisual(visualName, x, y, z) * .catch(error => { ... }); * ``` * * @param {string} visualName * @param {number} x * @param {number} y * @param {number} z * @returns {Promise<IHttpPostMessageResponse<void>>} */ moveVisual(visualName: string, x: number, y: number, z?: number): Promise<IHttpPostMessageResponse<void>>; /** * Resize a visual in a page. * * ```javascript * page.resizeVisual(visualName, width, height) * .catch(error => { ... }); * ``` * * @param {string} visualName * @param {number} width * @param {number} height * @returns {Promise<IHttpPostMessageResponse<void>>} */ resizeVisual(visualName: string, width: number, height: number): Promise<IHttpPostMessageResponse<void>>; /** * Updates the size of active page. * * ```javascript * page.resizePage(pageSizeType, width, height) * .catch(error => { ... }); * ``` * * @param {PageSizeType} pageSizeType * @param {number} width * @param {number} height * @returns {Promise<IHttpPostMessageResponse<void>>} */ resizePage(pageSizeType: PageSizeType, width?: number, height?: number): Promise<IHttpPostMessageResponse<void>>; /** * Gets the list of slicer visuals on the page. * * ```javascript * page.getSlicers() * .then(slicers => { * ... * }); * ``` * * @returns {Promise<IVisual[]>} */ getSlicers(): Promise<IVisual[]>; /** * Checks if page has layout. * * ```javascript * page.hasLayout(layoutType) * .then(hasLayout: boolean => { ... }); * ``` * * @returns {(Promise<boolean>)} */ hasLayout(layoutType: LayoutType): Promise<boolean>; } } declare module "report" { import { IReportLoadConfiguration, IReportEmbedConfiguration, FiltersOperations, IError, IFilter, IReportTheme, ISettings, LayoutType, SectionVisibility, ViewMode, IEmbedConfiguration, IEmbedConfigurationBase, MenuLocation, PageSizeType, VisualContainerDisplayMode } from 'powerbi-models'; import { IHttpPostMessageResponse } from 'http-post-message'; import { IService, Service } from "service"; import { Embed } from "embed"; import { IFilterable } from "ifilterable"; import { Page } from "page"; import { BookmarksManager } from "bookmarksManager"; /** * A Report node within a report hierarchy * * @export * @interface IReportNode */ export interface IReportNode { iframe: HTMLIFrameElement; service: IService; config: IEmbedConfiguration | IReportEmbedConfiguration; } /** * The Power BI Report embed component * * @export * @class Report * @extends {Embed} * @implements {IReportNode} * @implements {IFilterable} */ export class Report extends Embed implements IReportNode, IFilterable { /** @hidden */ static allowedEvents: string[]; /** @hidden */ static reportIdAttribute: string; /** @hidden */ static filterPaneEnabledAttribute: string; /** @hidden */ static navContentPaneEnabledAttribute: string; /** @hidden */ static typeAttribute: string; /** @hidden */ static type: string; bookmarksManager: BookmarksManager; /** * Creates an instance of a Power BI Report. * * @param {Service} service * @param {HTMLElement} element * @param {IEmbedConfiguration} config * @hidden */ constructor(service: Service, element: HTMLElement, baseConfig: IEmbedConfigurationBase, phasedRender?: boolean, isBootstrap?: boolean, iframe?: HTMLIFrameElement); /** * Adds backwards compatibility for the previous load configuration, which used the reportId query parameter to specify the report ID * (e.g. http://embedded.powerbi.com/appTokenReportEmbed?reportId=854846ed-2106-4dc2-bc58-eb77533bf2f1). * * By extracting the ID we can ensure that the ID is always explicitly provided as part of the load configuration. * * @hidden * @static * @param {string} url * @returns {string} */ static findIdFromEmbedUrl(url: string): string; /** * Render a preloaded report, using phased embedding API * * ```javascript * // Load report * var report = powerbi.load(element, config); * * ... * * // Render report * report.render() * ``` * * @returns {Promise<void>} */ render(config?: IReportLoadConfiguration | IReportEmbedConfiguration): Promise<void>; /** * Add an empty page to the report * * ```javascript * // Add a page to the report with "Sales" as the page display name * report.addPage("Sales"); * ``` * * @returns {Promise<Page>} */ addPage(displayName?: string): Promise<Page>; /** * Delete a page from a report * * ```javascript * // Delete a page from a report by pageName (PageName is different than the display name and can be acquired from the getPages API) * report.deletePage("ReportSection145"); * ``` * * @returns {Promise<void>} */ deletePage(pageName: string): Promise<void>; /** * Rename a page from a report * * ```javascript * // Rename a page from a report by changing displayName (pageName is different from the display name and can be acquired from the getPages API) * report.renamePage("ReportSection145", "Sales"); * ``` * * @returns {Promise<void>} */ renamePage(pageName: string, displayName: string): Promise<void>; /** * Gets filters that are applied at the report level. * * ```javascript * // Get filters applied at report level * report.getFilters() * .then(filters => { * ... * }); * ``` * * @returns {Promise<IFilter[]>} */ getFilters(): Promise<IFilter[]>; /** * Update the filters at the report level according to the operation: Add, replace all, replace by target or remove. * * ```javascript * report.updateFilters(FiltersOperations.Add, filters) * .catch(errors => { ... }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Removes all filters at the report level. * * ```javascript * report.removeFilters(); * ``` * * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Sets filters at the report level. * * ```javascript * const filters: [ * ... * ]; * * report.setFilters(filters) * .catch(errors => { * ... * }); * ``` * * @param {(IFilter[])} filters * @returns {Promise<IHttpPostMessageResponse<void>>} */ setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>>; /** * Gets the report ID from the first available location: options, attribute, embed url. * * @returns {string} */ getId(): string; /** * Gets the list of pages within the report. * * ```javascript * report.getPages() * .then(pages => { * ... * }); * ``` * * @returns {Promise<Page[]>} */ getPages(): Promise<Page[]>; /** * Gets a report page by its name. * * ```javascript * report.getPageByName(pageName) * .then(page => { * ... * }); * ``` * * @param {string} pageName * @returns {Promise<Page>} */ getPageByName(pageName: string): Promise<Page>; /** * Gets the active report page. * * ```javascript * report.getActivePage() * .then(activePage => { * ... * }); * ``` * * @returns {Promise<Page>} */ getActivePage(): Promise<Page>; /** * Creates an instance of a Page. * * Normally you would get Page objects by calling `report.getPages()`, but in the case * that the page name is known and you want to perform an action on a page without having to retrieve it * you can create it directly. * * Note: Because you are creating the page manually there is no guarantee that the page actually exists in the report, and subsequent requests could fail. * * @param {string} name * @param {string} [displayName] * @param {boolean} [isActive] * @returns {Page} * @hidden */ page(name: string, displayName?: string, isActive?: boolean, visibility?: SectionVisibility): Page; /** * Prints the active page of the report by invoking `window.print()` on the embed iframe component. */ print(): Promise<void>; /** * Sets the active page of the report. * * ```javascript * report.setPage("page2") * .catch(error => { ... }); * ``` * * @param {string} pageName * @returns {Promise<IHttpPostMessageResponse<void>>} */ setPage(pageName: string): Promise<IHttpPostMessageResponse<void>>; /** * Updates visibility settings for the filter pane and the page navigation pane. * * ```javascript * const newSettings = { * panes: { * filters: { * visible: false * } * } * }; * * report.updateSettings(newSettings) * .catch(error => { ... }); * ``` * * @param {ISettings} settings * @returns {Promise<IHttpPostMessageResponse<void>>} */ updateSettings(settings: ISettings): Promise<IHttpPostMessageResponse<void>>; /** * Validate load configuration. * * @hidden */ validate(config: IEmbedConfigurationBase): IError[]; /** * Handle config changes. * * @returns {void} */ configChanged(isBootstrap: boolean): void; /** * @hidden * @returns {string} */ getDefaultEmbedUrlEndpoint(): string; /** * Switch Report view mode. * * @returns {Promise<void>} */ switchMode(viewMode: ViewMode | string): Promise<void>; /** * Refreshes data sources for the report. * * ```javascript * report.refresh(); * ``` */ refresh(): Promise<void>; /** * checks if the report is saved. * * ```javascript * report.isSaved() * ``` * * @returns {Promise<boolean>} */ isSaved(): Promise<boolean>; /** * Apply a theme to the report * * ```javascript * report.applyTheme(theme); * ``` */ applyTheme(theme: IReportTheme): Promise<void>; /** * Reset and apply the default theme of the report * * ```javascript * report.resetTheme(); * ``` */ resetTheme(): Promise<void>; /** * get the theme of the report * * ```javascript * report.getTheme(); * ``` */ getTheme(): Promise<IReportTheme>; /** * Reset user's filters, slicers, and other data view changes to the default state of the report * * ```javascript * report.resetPersistentFilters(); * ``` */ resetPersistentFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Save user's filters, slicers, and other data view changes of the report * * ```javascript * report.savePersistentFilters(); * ``` */ savePersistentFilters(): Promise<IHttpPostMessageResponse<void>>; /** * Returns if there are user's filters, slicers, or other data view changes applied on the report. * If persistent filters is disable, returns false. * * ```javascript * report.arePersistentFiltersApplied(); * ``` * * @returns {Promise<boolean>} */ arePersistentFiltersApplied(): Promise<boolean>; /** * Remove context menu extension command. * * ```javascript * report.removeContextMenuCommand(commandName, contextMenuTitle) * .catch(error => { * ... * }); * ``` * * @param {string} commandName * @param {string} contextMenuTitle * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeContextMenuCommand(commandName: string, contextMenuTitle: string): Promise<IHttpPostMessageResponse<void>>; /** * Add context menu extension command. * * ```javascript * report.addContextMenuCommand(commandName, commandTitle, contextMenuTitle, menuLocation, visualName, visualType, groupName) * .catch(error => { * ... * }); * ``` * * @param {string} commandName * @param {string} commandTitle * @param {string} contextMenuTitle * @param {MenuLocation} menuLocation * @param {string} visualName * @param {string} visualType * @param {string} groupName * @returns {Promise<IHttpPostMessageResponse<void>>} */ addContextMenuCommand(commandName: string, commandTitle: string, contextMenuTitle: string, menuLocation: MenuLocation, visualName: string, visualType: string, groupName?: string): Promise<IHttpPostMessageResponse<void>>; /** * Remove options menu extension command. * * ```javascript * report.removeOptionsMenuCommand(commandName, optionsMenuTitle) * .then({ * ... * }); * ``` * * @param {string} commandName * @param {string} optionsMenuTitle * @returns {Promise<IHttpPostMessageResponse<void>>} */ removeOptionsMenuCommand(commandName: string, optionsMenuTitle: string): Promise<IHttpPostMessageResponse<void>>; /** * Add options menu extension command. * * ```javascript * report.addOptionsMenuCommand(commandName, commandTitle, optionsMenuTitle, menuLocation, visualName, visualType, groupName, commandIcon) * .catch(error => { * ... * }); * ``` * * @param {string} commandName * @param {string} commandTitle * @param {string} optionMenuTitle * @param {MenuLocation} menuLocation * @param {string} visualName * @param {string} visualType * @param {string} groupName * @param {string} commandIcon * @returns {Promise<IHttpPostMessageResponse<void>>} */ addOptionsMenuCommand(commandName: string, commandTitle: string, optionsMenuTitle?: string, menuLocation?: MenuLocation, visualName?: string, visualType?: string, groupName?: string, commandIcon?: string): Promise<IHttpPostMessageResponse<void>>; /** * Updates the display state of a visual in a page. * * ```javascript * report.setVisualDisplayState(pageName, visualName, displayState) * .catch(error => { ... }); * ``` * * @param {string} pageName * @param {string} visualName * @param {VisualContainerDisplayMode} displayState * @returns {Promise<IHttpPostMessageResponse<void>>} */ setVisualDisplayState(pageName: string, visualName: string, displayState: VisualContainerDisplayMode): Promise<IHttpPostMessageResponse<void>>; /** * Resize a visual in a page. * * ```javascript * report.resizeVisual(pageName, visualName, width, height) * .catch(error => { ... }); * ``` * * @param {string} pageName * @param {string} visualName * @param {number} width * @param {number} height * @returns {Promise<IHttpPostMessageResponse<void>>} */ resizeVisual(pageName: string, visualName: string, width: number, height: number): Promise<IHttpPostMessageResponse<void>>; /** * Updates the size of active page in report. * * ```javascript * report.resizeActivePage(pageSizeType, width, height) * .catch(error => { ... }); * ``` * * @param {PageSizeType} pageSizeType * @param {number} width * @param {number} height * @returns {Promise<IHttpPostMessageResponse<void>>} */ resizeAc