diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..6e7798f5 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +# Task 512388: Fix eslint warnings and errors in tests +/node_modules/* +/**/*.js +dist/* \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..4240ccee --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,236 @@ +// TODO: Remove "warn" settings for the rules after resolving them +module.exports = { + "env": { + "browser": true, + "node": true + }, + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "webpack.test.tsconfig.json", + "sourceType": "module" + }, + "plugins": [ + "eslint-plugin-jsdoc", + "eslint-plugin-prefer-arrow", + "eslint-plugin-import", + "@typescript-eslint" + ], + "rules": { + "@typescript-eslint/adjacent-overload-signatures": "warn", + "@typescript-eslint/array-type": "off", + "@typescript-eslint/await-thenable": "warn", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/ban-types": [ + "warn", + { + "types": { + "Object": { + "message": "Avoid using the `Object` type. Did you mean `object`?" + }, + "Function": false, + "object": false, + "Boolean": { + "message": "Avoid using the `Boolean` type. Did you mean `boolean`?" + }, + "Number": { + "message": "Avoid using the `Number` type. Did you mean `number`?" + }, + "String": { + "message": "Avoid using the `String` type. Did you mean `string`?" + }, + "Symbol": { + "message": "Avoid using the `Symbol` type. Did you mean `symbol`?" + } + } + } + ], + "@typescript-eslint/consistent-type-definitions": "warn", + "@typescript-eslint/dot-notation": "off", + "@typescript-eslint/explicit-member-accessibility": [ + "off", + { + "accessibility": "explicit" + } + ], + "@typescript-eslint/explicit-module-boundary-types": [ + "warn", + { "allowArgumentsExplicitlyTypedAsAny": true } + ], + "@typescript-eslint/indent": [ + "warn", + 2, + { + "SwitchCase": 1, + "FunctionDeclaration": { + "parameters": "first" + }, + "FunctionExpression": { + "parameters": "first" + } + } + ], + "@typescript-eslint/member-delimiter-style": [ + "warn", + { + "multiline": { + "delimiter": "semi", + "requireLast": true + }, + "singleline": { + "delimiter": "semi", + "requireLast": false + } + } + ], + "@typescript-eslint/explicit-function-return-type": [ + "error", + { + "allowExpressions": true, + "allowDirectConstAssertionInArrowFunctions": true + } + ], + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/naming-convention": "off", + "@typescript-eslint/no-array-constructor": "warn", + "@typescript-eslint/no-empty-function": "warn", + "@typescript-eslint/no-empty-interface": "warn", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-extra-non-null-assertion": "warn", + "@typescript-eslint/no-extra-semi": "warn", + "@typescript-eslint/no-floating-promises": "off", + "@typescript-eslint/no-for-in-array": "warn", + "@typescript-eslint/no-implied-eval": "warn", + "@typescript-eslint/no-inferrable-types": "off", + "@typescript-eslint/no-misused-new": "warn", + "@typescript-eslint/no-misused-promises": "off", + "@typescript-eslint/no-namespace": "warn", + "@typescript-eslint/no-non-null-asserted-optional-chain": "warn", + "@typescript-eslint/no-non-null-assertion": "warn", + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-this-alias": "warn", + "@typescript-eslint/no-unnecessary-type-assertion": "warn", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-unsafe-call": "off", + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/no-unsafe-return": "off", + "@typescript-eslint/no-unused-expressions": "warn", + "@typescript-eslint/no-unused-vars": [ + "warn", + { + "args": "after-used", "argsIgnorePattern": "^_" + } + ], + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/no-var-requires": "warn", + "@typescript-eslint/prefer-as-const": "warn", + "@typescript-eslint/prefer-for-of": "warn", + "@typescript-eslint/prefer-namespace-keyword": "warn", + "@typescript-eslint/prefer-regexp-exec": "off", + "@typescript-eslint/quotes": [ + "off", + { + "avoidEscape": true + } + ], + "@typescript-eslint/require-await": "warn", + "@typescript-eslint/restrict-plus-operands": "warn", + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/semi": [ + "error", + ], + "@typescript-eslint/triple-slash-reference": [ + "warn", + { + "path": "always", + "types": "prefer-import", + "lib": "always" + } + ], + "@typescript-eslint/type-annotation-spacing": "warn", + "@typescript-eslint/unbound-method": "off", + "@typescript-eslint/unified-signatures": "warn", + "arrow-parens": "off", + "brace-style": [ + "off", + "1tbs" + ], + "comma-dangle": "off", + "complexity": "off", + "constructor-super": "warn", + "eol-last": "warn", + "eqeqeq": [ + "warn", + "smart" + ], + "guard-for-in": "warn", + "id-blacklist": [ + "warn", + "any", + "Number", + "number", + "String", + "string", + "Boolean", + "boolean", + "Undefined", + ], + "id-match": "warn", + "import/order": "off", + "jsdoc/check-alignment": "warn", + "jsdoc/check-indentation": "warn", + "jsdoc/newline-after-description": "warn", + "max-classes-per-file": [ + "warn", + 1 + ], + "max-len": "off", + "new-parens": "warn", + "no-array-constructor": "off", + "no-caller": "warn", + "no-cond-assign": "warn", + "no-console": "off", + "no-debugger": "warn", + "no-empty": "warn", + "no-empty-function": "off", + "no-eval": "warn", + "no-extra-semi": "off", + "no-fallthrough": "off", + "no-implied-eval": "off", + "no-invalid-this": "off", + "no-multiple-empty-lines": ["error", { "max": 1 }], + "no-new-wrappers": "warn", + "no-shadow": "off", + "no-trailing-spaces": "warn", + "no-undef-init": "warn", + "no-underscore-dangle": "off", + "no-unsafe-finally": "warn", + "no-unused-labels": "warn", + "no-var": "warn", + "object-shorthand": "off", + "one-var": "off", + "prefer-const": "off", + "prefer-rest-params": "warn", + "quote-props": [ + "warn", + "consistent-as-needed" + ], + "radix": "warn", + "require-await": "off", + "space-before-function-paren": "off", + "spaced-comment": [ + "warn", + "always", + { + "markers": [ + "/" + ] + } + ], + "use-isnan": "warn", + "valid-typeof": "off" + } +}; diff --git a/.gitignore b/.gitignore index 713cbd07..d8bec088 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules/ -bower_components/ coverage/ docs typings/ @@ -9,4 +8,7 @@ npm-debug.log* dist/powerbi.js.map *.js.map package-lock.json -demo/package-lock.json +.vscode +owners.txt +test/util.spec.ts +.config/tsaoptions.json \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4479811e..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - "editor.tabSize": 2, - "editor.insertSpaces": true, - "editor.detectIndentation": false -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index a7b839de..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "0.1.0", - "command": "npm", - "isShellCommand": true, - "showOutput": "always", - "suppressTaskName": true, - "tasks": [ - { - "taskName": "build", - "args": [ - "run", - "build" - ], - "isBuildCommand": true - }, - { - "taskName": "test", - "args": [ - "run", - "test", - "--", - "--chrome" - ], - "isTestCommand": true - } - ] -} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 9e5bfa50..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,61 +0,0 @@ -# 2.0.0-beta.1 (GA candidate) - -## Breaking - -- DOMContentLoaded handler is now opt-in instead of the default behavior - - Reasons: - - The primary use case will be using the core library within another library which may not have the DOM ready even if DOMContentLoaded has fired. - - Most developers using SPA applications will fetch embed data asynchronously and not know report data by the time the DOMContentLoaded has fired. - - How to opt-in to DOMContentLoaded: - - Call `enableAutoEmbed()` on an instance of the PowerBi service to add the event listener. - - Example: - ``` - - - ``` - - Alternately if you are creating an instance of the service you can pass a configuration parameter `autoEmbedOnContentLoaded` - - Example: - ``` - var powerbiService = new Powerbi({ autoEmbedOnContentLoaded: true }); - ``` -- `powerbi.get(element: HTMLElement)` now only returns the instance of powerbi component associated with the element and does not implicitly emebed. Use `powerbi.embed(element: HTMLElement, config: IEmbedOptions = {})`. - - Reasons: - - powerbi.embed performed the same function and is more semantic. - - Now that overwrite: true is the default behavior for .embed having a separate method (get) for only retrieving compnents is good separation of intents. -- Embed urls must be provided by the server and will not be constructed by the components. This implies that the attributes `powerbi-report` will no longer be used. - - Reasons: - - The construction of these urls was unreliable since it dependeded on assumptions about server configuration (target environment, component type, etc). - Since url would be incorrect in some cases it could cause trouble for developers. Also, since the sever is already returning access tokens it's trival for the server to also provide embed urls and this reduces complexity. - - Previously you could supply the embed information in two ways: - - 1. Using report id: - - `
` - - This would implicitly construct the embed url to be something like: `https://embedded.powerbi.com/reports/5dac7a4a-4452-46b3-99f6-a25915e0fe55` - However - - 2. Using embed url: - - `` - - Now only the latter options (#2) is supported. - -- Embed url attribute changed from `powerbi-embed` to `powerbi-embed-url` -- Component type is specified by attribute `powerbi-type`. Use `powerbi-type="report"` instead of applying the attribute `powerbi-report` -- Configuration settings attributes all start with prefix `powerbi-settings-`. - -## Changes - -- Fix bug to prevent memory leak of holding references to iframe elements which had been removed from the DOM. -- Detect overwriting container with new component and either throw error or properly cleanup and replace old component based on `config.overwrite` setting. -- Fix bug with prematurely attempting to parse post message data until it is known that it originated from embedded iframe. - -# 1.0.0 (Preview) \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f9a082e4..3e7f6be3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,33 +55,10 @@ node node_modules/karma/bin/karma start --browsers=Firefox --single-run=false -- The build and tests use webpack to compile all the source modules into one bundled module that can execute in the browser. -## Running the demo -Navigate to `/demo` directory - -Install bower dependencies: -``` -bower install -``` - -Serve the demo directory: -``` -npm start -``` - -Open the address to view in the browser: -``` -http://127.0.0.1:8080/ -``` - -## Updating the documenatation (For those with push permissions only) +## Updating the documentation (For those with push permissions only) First run the command to build the docs and open it to verify the changes are as expected. ``` npm run gulp -- build:docs ``` > There are errors during the TypeDoc compilation step due to some complication with modules however the documentation should still be generated. It's not clear if these are fixable by including more src files in the gulp task or if it's just the nature of TypeDoc lacking capabilities for this project structure. - -If the docs are correct then you may publish them to gh-pages using this command -``` -npm run gulp -- ghpages -``` \ No newline at end of file diff --git a/README.md b/README.md index c5d7c82e..9fecd37e 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,25 @@ # powerbi-client -JavaScript library for embedding Power BI into your apps. +A client side library for embedding Power BI using JavaScript or TypeScript into your apps. [](https://travis-ci.org/Microsoft/PowerBI-JavaScript) [](https://www.npmjs.com/package/powerbi-client) -[](https://bower.io/search/?q=powerbi-client) [](https://www.nuget.org/packages/Microsoft.PowerBI.JavaScript/) [](https://www.npmjs.com/package/powerbi-client) [](https://www.npmjs.com/package/powerbi-client) [](https://github.com/Microsoft/PowerBI-JavaScript/tags) [](https://gitter.im/Microsoft/PowerBI-JavaScript) -## Wiki -See the [wiki](https://github.com/Microsoft/PowerBI-JavaScript/wiki) for more details about embedding, service configuration, setting a default page, page navigation, dynamically applying filters, and more. +## Documentation +See the [Power BI embedded analytics Client APIs documentation](https://docs.microsoft.com/javascript/api/overview/powerbi/) to learn how to embed a Power BI report in your application and how to use the client APIs. ## Code Docs -See the [code docs](https://microsoft.github.io/PowerBI-JavaScript) for detailed information about classes, interfaces, types, etc. +See the [code docs](https://learn.microsoft.com/en-us/javascript/api/powerbi/powerbi-client) for detailed information about classes, interfaces, types, etc. -## Demo -New [live demo](https://microsoft.github.io/PowerBI-JavaScript/demo) for a sample application using the `powerbi-client` library in scenarios such as page navigation, applying filters, updating settings, and more. +## Sample Application +For examples of applications utilizing the `powerbi-client` library, please refer to the available samples in the [PowerBI-Developer-Samples repository](https://github.com/microsoft/PowerBI-Developer-Samples). + +## Playground +To explore and understand the capabilities of embedded analytics in your applications, please visit the [Power BI Embedded Analytics Playground](https://playground.powerbi.com). ## Installation @@ -29,10 +31,6 @@ Install from NPM: `npm install --save powerbi-client` -Install from Bower: - -`bower install powerbi-client --save` - Installing beta versions: `npm install --save powerbi-client@beta` @@ -48,10 +46,16 @@ import * as pbi from 'powerbi-client'; However, the library is exported as a Universal Module and the powerbi.js script can be included before your app's closing `