Skip to content

Commit

Permalink
Merged PR 209427: Support accessTokenProvider hook - Release version …
Browse files Browse the repository at this point in the history
…2.19.0
  • Loading branch information
aliabufoul committed Jan 13, 2022
1 parent 054c79f commit 9f9e39e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist/powerbi-client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// powerbi-client v2.18.7
// powerbi-client v2.19.0
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
declare module "config" {
Expand Down
55 changes: 38 additions & 17 deletions dist/powerbi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/powerbi.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-client",
"version": "2.18.7",
"version": "2.19.0",
"description": "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 responding to data selection.",
"main": "dist/powerbi.js",
"types": "dist/powerbi-client.d.ts",
Expand Down Expand Up @@ -81,7 +81,7 @@
},
"dependencies": {
"http-post-message": "^0.2",
"powerbi-models": "^1.9.7",
"powerbi-models": "^1.9.8",
"powerbi-router": "^0.1",
"window-post-message-proxy": "^0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/** @ignore *//** */
const config = {
version: '2.18.7',
version: '2.19.0',
type: 'js'
};

Expand Down
9 changes: 8 additions & 1 deletion src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ export abstract class Embed {
return;
}

for (var key in eventHooks) {
for (let key in eventHooks) {
if (eventHooks.hasOwnProperty(key) && typeof eventHooks[key] !== 'function') {
throw new Error(key + " must be a function");
}
Expand All @@ -578,6 +578,13 @@ export abstract class Embed {

this.config.embedUrl = addParamToUrl(this.config.embedUrl, "registerQueryCallback", "true");
}

const accessTokenProvider = eventHooks.accessTokenProvider;
if (!!accessTokenProvider) {
if (this.embedtype.toLowerCase() !== "report" || this.config.tokenType !== models.TokenType.Aad) {
throw new Error("accessTokenProvider is only supported in report SaaS embed");
}
}
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,15 @@ export class Service implements IService {
case "preQuery":
req.body = req.body || {};
req.body.report = embed;
await this.invokeSDKHook(embed.eventHooks.applicationContextProvider, req, _res);
await this.invokeSDKHook(embed.eventHooks?.applicationContextProvider, req, _res);
break;

case "newAccessToken":
req.body = req.body || {};
req.body.report = embed;
await this.invokeSDKHook(embed.eventHooks?.accessTokenProvider, req, _res);
break;

default:
break;
}
Expand Down Expand Up @@ -571,6 +578,11 @@ export class Service implements IService {
}

private async invokeSDKHook(hook: Function, req: IExtendedRequest, res: IExtendedResponse): Promise<void> {
if (!hook) {
res.send(404, null);
return;
}

try {
let result = await hook(req.body);
res.send(200, result);
Expand Down

0 comments on commit 9f9e39e

Please sign in to comment.