Skip to content

Commit a721ad0

Browse files
parth-007mayur007b
authored andcommitted
Merged PR 125682: Resolve npm audit vulnerabilities, TS v3, migrated to @types
## Changes in this PR 1. Resolved all npm audit vulnerabilities (except 1 low severity vulnerability in _gulp-gh-pages_, no fix available for that) 1. Upgraded to TS 3.9 1. Migrated from typings to @types 1. Used async/await to align with the return types of methods 1. Minor docs fixes 1. Fixed types of all methods Related work items: #323592, #323972, #326488, #327505, #330227, #331107, #331778, #331837, #459272, #459826, #460523, #461075, #462110, #462652, #463184, #463185, #463806, #463807, #464436, #468356, #468867
1 parent 9d19361 commit a721ad0

22 files changed

+10010
-8769
lines changed

dist/powerbi-client.d.ts

Lines changed: 79 additions & 68 deletions
Large diffs are not rendered by default.

dist/powerbi.js

Lines changed: 9443 additions & 8263 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,27 @@ gulp.task('ghpages', 'Deploy documentation to gh-pages', ['nojekyll'], function
4040
gulp.task("docs", 'Compile documentation from src code', function () {
4141
return gulp
4242
.src([
43-
"typings/globals/es6-promise/index.d.ts",
43+
"node_modules/es6-promise/es6-promise.d.ts",
4444
"node_modules/powerbi-models/dist/models.d.ts",
4545
"src/**/*.ts"
4646
])
4747
.pipe(typedoc({
4848
mode: 'modules',
4949
includeDeclarations: true,
5050

51-
// Output options (see typedoc docs)
51+
// Output options (see typedoc docs)
5252
out: "./docs",
5353
json: "./docs/json/" + package.name + ".json",
5454

55-
// TypeDoc options (see typedoc docs)
55+
// TypeDoc options (see typedoc docs)
5656
ignoreCompilerErrors: true,
5757
version: true
58-
}))
59-
;
58+
}));
6059
});
6160

6261
gulp.task('copydemotodocs', 'Copy the demo to the docs', function () {
6362
return gulp.src(["demo/**/*"])
64-
.pipe(gulp.dest("docs/demo"))
65-
;
63+
.pipe(gulp.dest("docs/demo"));
6664
});
6765

6866
gulp.task('nojekyll', 'Add .nojekyll file to docs directory', function (done) {
@@ -153,20 +151,32 @@ gulp.task('lint:ts', 'Lints all TypeScript', function () {
153151
});
154152

155153
gulp.task('min:js', 'Creates minified JavaScript file', function () {
156-
return gulp.src(['!./dist/*.min.js', './dist/*.js'])
157-
.pipe(uglify({
158-
preserveComments: 'license'
154+
webpackConfig.plugins = [
155+
new webpack.BannerPlugin(webpackBanner)
156+
];
157+
158+
// Create minified bundle without source map
159+
webpackConfig.mode = 'production';
160+
webpackConfig.devtool = 'none'
161+
162+
return gulp.src(['./src/powerbi-client.ts'])
163+
.pipe(webpackStream({
164+
config: webpackConfig
159165
}))
160166
.pipe(rename({
161167
suffix: '.min'
162168
}))
163-
.pipe(gulp.dest('./dist'));
169+
.pipe(uglify({
170+
preserveComments: 'license'
171+
}))
172+
.pipe(gulp.dest('dist/'));
164173
});
165174

166175
gulp.task('compile:ts', 'Compile typescript for powerbi-client library', function () {
167176
webpackConfig.plugins = [
168177
new webpack.BannerPlugin(webpackBanner)
169178
];
179+
webpackConfig.mode = "development";
170180

171181
return gulp.src(['./src/powerbi-client.ts'])
172182
.pipe(webpackStream(webpackConfig))
@@ -181,7 +191,9 @@ gulp.task('compile:dts', 'Generate one dts file from modules', function () {
181191

182192
var settings = {
183193
out: "powerbi-client.js",
184-
declaration: true
194+
declaration: true,
195+
module: "system",
196+
moduleResolution: "node"
185197
};
186198

187199
var tsResult = tsProject.src()

package.json

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "powerbi-client",
3-
"version": "2.15.2",
3+
"version": "2.16.0",
44
"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.",
55
"main": "dist/powerbi.js",
6-
"typings": "dist/powerbi-client.d.ts",
6+
"types": "dist/powerbi-client.d.ts",
77
"files": [
88
"dist"
99
],
@@ -15,8 +15,7 @@
1515
"start": "http-server ./demo",
1616
"prestart": "cd demo && npm install",
1717
"test": "gulp test",
18-
"gulp": "gulp",
19-
"typings": "typings"
18+
"gulp": "gulp"
2019
},
2120
"keywords": [
2221
"microsoft",
@@ -31,6 +30,12 @@
3130
"author": "Microsoft",
3231
"license": "MIT",
3332
"devDependencies": {
33+
"@types/jasmine": "^3.5.10",
34+
"@types/jquery": "^3.3.34",
35+
"@types/jsen": "0.0.19",
36+
"@types/karma-jasmine": "^3.1.0",
37+
"@types/node": "^14.14.7",
38+
"@types/npm": "^2.0.31",
3439
"del": "^2.2.2",
3540
"es6-promise": "^3.2.1",
3641
"gulp": "^4.0.2",
@@ -40,37 +45,36 @@
4045
"gulp-help-four": "^0.2.3",
4146
"gulp-rename": "^1.2.2",
4247
"gulp-replace": "^0.5.4",
43-
"gulp-tslint": "^4.3.4",
48+
"gulp-tslint": "^7.1.0",
4449
"gulp-typedoc": "^2.0.0",
45-
"gulp-typescript": "^2.12.1",
50+
"gulp-typescript": "^4.0.1",
4651
"gulp-uglify": "^1.5.1",
4752
"gulp4-run-sequence": "^1.0.0",
48-
"http-server": "^0.11.1",
53+
"http-server": "^0.12.1",
4954
"ignore-loader": "^0.1.1",
50-
"jasmine-core": "^2.4.1",
55+
"jasmine-core": "^2.99.1",
5156
"jquery": "^3.3.1",
5257
"json-loader": "^0.5.4",
53-
"karma": "^4.4.1",
58+
"karma": "^5.2.3",
5459
"karma-chrome-launcher": "^3.1.0",
55-
"karma-coverage": "^2.0.1",
60+
"karma-coverage": "^2.0.3",
5661
"karma-firefox-launcher": "^1.2.0",
5762
"karma-jasmine": "^0.3.8",
5863
"karma-phantomjs-launcher": "^1.0.4",
5964
"karma-spec-reporter": "0.0.32",
6065
"moment": "^2.14.1",
61-
"phantomjs-prebuilt": "^2.1.3",
62-
"ts-loader": "^0.8.1",
63-
"tslint": "^3.6.0",
66+
"phantomjs-prebuilt": "^2.1.16",
67+
"ts-loader": "^6.2.2",
68+
"tslint": "^5.20.0",
6469
"typedoc": "^0.15.0",
65-
"typescript": "^1.8.10",
66-
"typings": "^1.3.2",
67-
"webpack": "^1.12.14",
68-
"webpack-stream": "^3.1.0",
69-
"yargs": "^4.4.0"
70+
"typescript": "^3.9.7",
71+
"webpack": "^4.44.2",
72+
"webpack-stream": "^5.2.1",
73+
"yargs": "^16.1.0"
7074
},
7175
"dependencies": {
7276
"http-post-message": "^0.2",
73-
"powerbi-models": "^1.7.0",
77+
"powerbi-models": "^1.7",
7478
"powerbi-router": "^0.1",
7579
"window-post-message-proxy": "^0.2"
7680
},

src/bookmarksManager.ts

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as embed from './embed';
33
import * as models from 'powerbi-models';
44
import * as utils from './util';
55
import * as errors from './errors';
6+
import { IHttpPostMessageResponse } from 'http-post-message';
67

78
/**
89
* APIs for managing the report bookmarks.
@@ -12,10 +13,10 @@ import * as errors from './errors';
1213
*/
1314
export interface IBookmarksManager {
1415
getBookmarks(): Promise<models.IReportBookmark[]>;
15-
apply(bookmarkName: string): Promise<void>;
16-
play(playMode: models.BookmarksPlayMode): Promise<void>;
16+
apply(bookmarkName: string): Promise<IHttpPostMessageResponse<void>>;
17+
play(playMode: models.BookmarksPlayMode): Promise<IHttpPostMessageResponse<void>>;
1718
capture(options?: models.ICaptureBookmarkOptions): Promise<models.IReportBookmark>;
18-
applyState(state: string): Promise<void>;
19+
applyState(state: string): Promise<IHttpPostMessageResponse<void>>;
1920
}
2021

2122
/**
@@ -45,16 +46,17 @@ export class BookmarksManager implements IBookmarksManager {
4546
*
4647
* @returns {Promise<models.IReportBookmark[]>}
4748
*/
48-
getBookmarks(): Promise<models.IReportBookmark[]> {
49+
async getBookmarks(): Promise<models.IReportBookmark[]> {
4950
if (utils.isRDLEmbed(this.config.embedUrl)) {
5051
return Promise.reject(errors.APINotSupportedForRDLError);
5152
}
5253

53-
return this.service.hpm.get<models.IReportBookmark[]>(`/report/bookmarks`, { uid: this.config.uniqueId }, this.iframe.contentWindow)
54-
.then(response => response.body,
55-
response => {
56-
throw response.body;
57-
});
54+
try {
55+
const response = await this.service.hpm.get<models.IReportBookmark[]>(`/report/bookmarks`, { uid: this.config.uniqueId }, this.iframe.contentWindow);
56+
return response.body;
57+
} catch (response) {
58+
throw response.body;
59+
}
5860
}
5961

6062
/**
@@ -65,9 +67,9 @@ export class BookmarksManager implements IBookmarksManager {
6567
* ```
6668
*
6769
* @param {string} bookmarkName The name of the bookmark to be applied
68-
* @returns {Promise<void>}
70+
* @returns {Promise<IHttpPostMessageResponse<void>>}
6971
*/
70-
apply(bookmarkName: string): Promise<void> {
72+
async apply(bookmarkName: string): Promise<IHttpPostMessageResponse<void>> {
7173
if (utils.isRDLEmbed(this.config.embedUrl)) {
7274
return Promise.reject(errors.APINotSupportedForRDLError);
7375
}
@@ -76,10 +78,11 @@ export class BookmarksManager implements IBookmarksManager {
7678
name: bookmarkName
7779
};
7880

79-
return this.service.hpm.post<models.IError[]>(`/report/bookmarks/applyByName`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow)
80-
.catch(response => {
81-
throw response.body;
82-
});
81+
try {
82+
return await this.service.hpm.post<void>(`/report/bookmarks/applyByName`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow);
83+
} catch (response) {
84+
throw response.body;
85+
}
8386
}
8487

8588
/**
@@ -91,9 +94,9 @@ export class BookmarksManager implements IBookmarksManager {
9194
* ```
9295
*
9396
* @param {models.BookmarksPlayMode} playMode Play mode can be either `Presentation` or `Off`
94-
* @returns {Promise<void>}
97+
* @returns {Promise<IHttpPostMessageResponse<void>>}
9598
*/
96-
play(playMode: models.BookmarksPlayMode): Promise<void> {
99+
async play(playMode: models.BookmarksPlayMode): Promise<IHttpPostMessageResponse<void>> {
97100
if (utils.isRDLEmbed(this.config.embedUrl)) {
98101
return Promise.reject(errors.APINotSupportedForRDLError);
99102
}
@@ -102,10 +105,11 @@ export class BookmarksManager implements IBookmarksManager {
102105
playMode: playMode
103106
};
104107

105-
return this.service.hpm.post<models.IError[]>(`/report/bookmarks/play`, playBookmarkRequest, { uid: this.config.uniqueId }, this.iframe.contentWindow)
106-
.catch(response => {
107-
throw response.body;
108-
});
108+
try {
109+
return await this.service.hpm.post<void>(`/report/bookmarks/play`, playBookmarkRequest, { uid: this.config.uniqueId }, this.iframe.contentWindow);
110+
} catch (response) {
111+
throw response.body;
112+
}
109113
}
110114

111115
/**
@@ -118,7 +122,7 @@ export class BookmarksManager implements IBookmarksManager {
118122
* @param {models.ICaptureBookmarkOptions} [options] Options for bookmark capturing
119123
* @returns {Promise<models.IReportBookmark>}
120124
*/
121-
capture(options?: models.ICaptureBookmarkOptions): Promise<models.IReportBookmark> {
125+
async capture(options?: models.ICaptureBookmarkOptions): Promise<models.IReportBookmark> {
122126
if (utils.isRDLEmbed(this.config.embedUrl)) {
123127
return Promise.reject(errors.APINotSupportedForRDLError);
124128
}
@@ -127,11 +131,12 @@ export class BookmarksManager implements IBookmarksManager {
127131
options: options
128132
};
129133

130-
return this.service.hpm.post<models.IReportBookmark>(`/report/bookmarks/capture`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow)
131-
.then(response => response.body,
132-
response => {
133-
throw response.body;
134-
});
134+
try {
135+
const response = await this.service.hpm.post<models.IReportBookmark>(`/report/bookmarks/capture`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow);
136+
return response.body;
137+
} catch (response) {
138+
throw response.body;
139+
}
135140
}
136141

137142
/**
@@ -142,9 +147,9 @@ export class BookmarksManager implements IBookmarksManager {
142147
* ```
143148
*
144149
* @param {string} state A base64 bookmark state to be applied
145-
* @returns {Promise<void>}
150+
* @returns {Promise<IHttpPostMessageResponse<void>>}
146151
*/
147-
applyState(state: string): Promise<void> {
152+
async applyState(state: string): Promise<IHttpPostMessageResponse<void>> {
148153
if (utils.isRDLEmbed(this.config.embedUrl)) {
149154
return Promise.reject(errors.APINotSupportedForRDLError);
150155
}
@@ -153,9 +158,10 @@ export class BookmarksManager implements IBookmarksManager {
153158
state: state
154159
};
155160

156-
return this.service.hpm.post<models.IError[]>(`/report/bookmarks/applyState`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow)
157-
.catch(response => {
158-
throw response.body;
159-
});
161+
try {
162+
return await this.service.hpm.post<void>(`/report/bookmarks/applyState`, request, { uid: this.config.uniqueId }, this.iframe.contentWindow);
163+
} catch (response) {
164+
throw response.body;
165+
}
160166
}
161167
}

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @ignore *//** */
22
const config = {
3-
version: '2.15.2',
3+
version: '2.16.0',
44
type: 'js'
55
};
66

src/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export class Create extends embed.Embed {
8080
*
8181
* @returns {Promise<boolean>}
8282
*/
83-
isSaved(): Promise<boolean> {
84-
return utils.isSavedInternal(this.service.hpm, this.config.uniqueId, this.iframe.contentWindow);
83+
async isSaved(): Promise<boolean> {
84+
return await utils.isSavedInternal(this.service.hpm, this.config.uniqueId, this.iframe.contentWindow);
8585
}
8686

8787
/**

0 commit comments

Comments
 (0)