├── .github ├── BackwardCompatibility.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── .travis.yml ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── LICENSE ├── README.md ├── generate.bat ├── lib ├── .npmignore ├── autorest │ ├── models │ │ ├── basicCredentials.js │ │ ├── cloneReportRequest.js │ │ ├── column.js │ │ ├── createWorkspaceRequest.js │ │ ├── dataset.js │ │ ├── datasource.js │ │ ├── gatewayDatasource.js │ │ ├── importInfo.js │ │ ├── importModel.js │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── oDataResponseListDataset.js │ │ ├── oDataResponseListDatasource.js │ │ ├── oDataResponseListGatewayDatasource.js │ │ ├── oDataResponseListImport.js │ │ ├── oDataResponseListReport.js │ │ ├── oDataResponseListTable.js │ │ ├── oDataResponseListWorkspace.js │ │ ├── rebindReportRequest.js │ │ ├── report.js │ │ ├── row.js │ │ ├── table.js │ │ └── workspace.js │ ├── operations │ │ ├── datasets.js │ │ ├── gateways.js │ │ ├── imports.js │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── reports.js │ │ └── workspaces.js │ ├── powerBIClient.d.ts │ └── powerBIClient.js ├── client │ ├── models │ │ ├── importFileOptions.ts │ │ └── index.ts │ ├── operations │ │ ├── imports.ts │ │ └── index.ts │ └── powerBIClient.ts ├── core │ ├── powerBIToken.ts │ └── util.ts ├── index.d.ts └── index.ts ├── package.json ├── swagger.json ├── test └── core │ └── PowerBIToken.test.ts ├── tsconfig.json └── typings.json /.github/BackwardCompatibility.md: -------------------------------------------------------------------------------- 1 | # Breaking Change Definition 2 | 3 | Breaking changes in PowerBI SDK for .NET are defined as follows: 4 | 5 | ## Generated classes 6 | 7 | - The class is removed 8 | - The class is renamed 9 | - The class no longer extends another class 10 | 11 | ## Properties of a generated class 12 | 13 | - A property is removed 14 | - A property is renamed 15 | - A property has its type changed 16 | 17 | ## Methods of a generated class 18 | - Methods should not be removed 19 | - Methods should not be renamed 20 | - Methods should not have their return type changed 21 | 22 | ## Parameters of methods in a generated class 23 | - Parameters should not be removed 24 | - Parameters should not have their type changed 25 | - Parameters should preserve their ordering, including when a parameter is added 26 | - Parameters should keep their default value, if they are assigned one 27 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | A few sentences describing the overall goals of the pull request's commits. 3 | 4 | ## Questison 5 | please answer the following questions. put x inside [ ] (e.g. [x]) 6 | 7 | ### What inside? 8 | - [ ] Bug Fixes? 9 | - [ ] New Features? 10 | - [x] Documentation? 11 | 12 | ### Is pull request totally generated from swagger file? 13 | - [ ] Yes. 14 | - [ ] No, part of it is auto-generated. 15 | 16 | ### Backward compatibility break? 17 | - [ ] Yes. Pull request breaks backward compatibility! 18 | 19 | [Learn more about backward compatibility.](BackwardCompatibility.md) 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | typings/ 3 | lib/index.js 4 | lib/index.js.map 5 | lib/client/**/*.js 6 | lib/client/**/*.js.map 7 | lib/client/**/*.d.ts 8 | lib/core/**/*.js 9 | lib/core/**/*.js.map 10 | lib/core/**/*.d.ts 11 | lib/index.js 12 | lib/index.js.map 13 | test/**/*.js 14 | test/**/*.js.map 15 | test/**/*.d.ts -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | **/*.ts 2 | !**/*.d.ts 3 | /.vscode/ 4 | typings/ 5 | test/ 6 | **/*.js.map 7 | generate.bat 8 | swagger.json 9 | tsconfig.json 10 | typings.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4.4' 4 | before_install: 5 | - npm run contrib 6 | script: 7 | - npm test 8 | deploy: 9 | provider: npm 10 | email: nugetpowerbi@microsoft.com 11 | api_key: 12 | secure: PzkBpLAHD4+hTdJfYHXEEYKNWvZo3JMX+OKFBJOr6YWWnZeCmo6FjJlB4EbzxYAG6SnmZ6bTtNsbR0+8xHyzLa6g0z8t+gFqGXzW1RRqpPE6tjIydfjC+0FQw/fKOqKcdVrhYouNJz2ZtZ8+8XOQNx6gMCHOjvyFx4BaVVyvpk5VkfSIP1J7UXIRcsVuQykm/LwZRoDjCn/rNbUY7gnDcVPJ99k8dZS4Ikyv9DJmNDfqSih6tsran2jrR/yK0i4kNMrgUztr5UVShDAx5QXh5Ls/113qBL6LrkVSmFVQeEoPZC85nNG2xWL6i08wKftt7LMlsD3navMkE6YpRk9epire1ne3CyavLbtMdMPQR1lZJUhOigpP6H9DIvphmM12px6+7LgrpwTLqQi6Y8okBa9JBmB/elDXS7rtLMCpm2zsMlmlUdJs+egwxOcV4RrLhMreue0Wi2k7zKUdNMa4T5G2MStCK36AmULCnf90WCpvBTgP9yLDgzi7tIo8r8jKRwI7LwhKqOZrMJtWhsdZQ1ET2GWTi10YAnJX7qybm3Hh9XZ+6pgoC+L1brVOFwdlFqcDurbUdkb9Zxk85ambpql8RIxgAJs93jHvUkbG+22DFvN4oIRANj2M9WOl8LWulMggFMW67BtS4qfwWsF6VGVxRXRfEbAwb/tcU8no5V4= 13 | on: 14 | tags: true 15 | repo: Microsoft/PowerBI-Node 16 | branch: master 17 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch", 6 | "type": "node", 7 | "request": "launch", 8 | "program": "${workspaceRoot}/lib/index.js", 9 | "stopOnEntry": false, 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "preLaunchTask": null, 13 | "runtimeExecutable": null, 14 | "runtimeArgs": [ 15 | "--nolazy" 16 | ], 17 | "env": { 18 | "NODE_ENV": "development" 19 | }, 20 | "externalConsole": false, 21 | "sourceMaps": false, 22 | "outDir": null 23 | }, 24 | { 25 | "name": "Attach", 26 | "type": "node", 27 | "request": "attach", 28 | "port": 5858, 29 | "address": "localhost", 30 | "restart": false, 31 | "sourceMaps": false, 32 | "outDir": null, 33 | "localRoot": "${workspaceRoot}", 34 | "remoteRoot": null 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "**/.git": true, 5 | "**/.DS_Store": true, 6 | "**/*.js.map": true, 7 | "**/*.js": { 8 | "when": "$(basename).ts" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // Available variables which can be used inside of strings. 2 | // ${workspaceRoot}: the root folder of the team 3 | // ${file}: the current opened file 4 | // ${fileBasename}: the current opened file's basename 5 | // ${fileDirname}: the current opened file's dirname 6 | // ${fileExtname}: the current opened file's extension 7 | // ${cwd}: the current working directory of the spawned process 8 | 9 | // A task runner that calls the Typescript compiler (tsc) and 10 | { 11 | "version": "0.1.0", 12 | 13 | // The command is tsc. Assumes that tsc has been installed using npm install -g typescript 14 | "command": "tsc", 15 | 16 | // The command is a shell script 17 | "isShellCommand": true, 18 | 19 | // Show the output window only if unrecognized errors occur. 20 | "showOutput": "silent", 21 | 22 | // args is the HelloWorld program to compile. 23 | "args": [], 24 | 25 | // use the standard tsc problem matcher to find compile problems 26 | // in the output. 27 | "problemMatcher": "$tsc" 28 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | PowerBI-Node 2 | 3 | Copyright (c) Microsoft Corporation 4 | 5 | All rights reserved. 6 | 7 | MIT License 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecation Note 2 | Node SDK is not supported any more. 3 | The Node SDK is no longer supported. If you are interested in this SDK, and would like to see it continue, please vote for it on [the Power BI ideas site](https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/20566726-power-bi-nodejs-sdk). 4 | 5 | # PowerBI-Node 6 | Node SDK and client library for the Power BI Embedded REST APIs. 7 | 8 | [![Build Status](https://img.shields.io/travis/Microsoft/PowerBI-Node/master.svg)](https://travis-ci.org/Microsoft/PowerBI-Node) 9 | [![NPM Version](https://img.shields.io/npm/v/powerbi-api.svg)](https://www.npmjs.com/package/powerbi-api) 10 | [![NPM Total Downloads](https://img.shields.io/npm/dt/powerbi-api.svg)](https://www.npmjs.com/package/powerbi-api) 11 | [![NPM Monthly Downloads](https://img.shields.io/npm/dm/powerbi-api.svg)](https://www.npmjs.com/package/powerbi-api) 12 | 13 | ## Installation 14 | ``` 15 | npm install powerbi-api 16 | ``` 17 | 18 | ## Usage 19 | Creating a new client requires referencing the Power BI SDK as well as the Microsoft Rest Client. For an example of the Node SDK in action see the [Power BI Node CLI](https://github.com/Microsoft/PowerBI-Cli). 20 | ```javascript 21 | var powerbi = require('powerbi-api'); 22 | var msrest = require('ms-rest'); 23 | 24 | var credentials = new msrest.TokenCredentials('{AccessKey}', "AppKey"); 25 | var client = new powerbi.PowerBIClient(credentials); 26 | 27 | // Example API call 28 | client.workspaces.getWorkspacesByCollectionName('{WorkspaceCollection}', function(err, result) { 29 | // Your code here 30 | }); 31 | ``` 32 | 33 | ### APIs 34 | The following APIs groups are available: 35 | - Datasets 36 | - Gateways 37 | - Imports 38 | - Reports 39 | - Workspaces 40 | 41 | ## PowerBI API Calls 42 | All API calls use the AppKey to authenticate the API calls. The AppKey can be retreived from Azure portal. 43 | Each API call sets the following HTTP header: 44 | - Authorization: AppKey {AccessKey} 45 | 46 | **WARNING** - Never expose your access keys client side in your application. If your access key is compromised a malicious user can take over control of your workspace collection. Access keys can be re-generated for your workspace collection within the Azure portal. 47 | 48 | ## Creating Embed Tokens 49 | Power BI Embedded uses embed token, which are HMAC signed JSON Web Tokens. The tokens are signed with the access key from your Azure Power BI Embedded workspace collection. 50 | Embed tokens, by default, are used to provide read only access to a report to embed into an application. 51 | 52 | ### Required Claims 53 | - ver: 0.2.0 54 | - wcn: {WorkspaceCollectionName} 55 | - wid: {WorkspaceId} 56 | - rid: {ReportId} 57 | - aud: https://analysis.windows.net/powerbi/api 58 | - nbp: Token valid not before in Unix EPOCH time 59 | - exp: Token expiration in Unix EPOCH time 60 | 61 | ```javascript 62 | var powerbi = require('powerbi-api'); 63 | var token = powerbi.PowerBIToken.createReportEmbedToken('{WorkspaceCollection}', '{workspaceId}', '{reportId}'); 64 | 65 | var jwt = token.generate('{AccessKey}'); 66 | ``` 67 | 68 | ## Token Example 69 | eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjIuMCIsIndjbiI6IlN1cHBvcnREZW1vIiwid2lkIjoiY2E2NzViMTktNmMzYy00MDAzLTg4MDgtMWM3ZGRjNmJkODA5IiwicmlkIjoiOTYyNDFmMGYtYWJhZS00ZWE5LWEwNjUtOTNiNDI4ZWRkYjE3IiwiaXNzIjoiUG93ZXJCSVNESyIsImF1ZCI6Imh0dHBzOi8vYW5hbHlzaXMud2luZG93cy5uZXQvcG93ZXJiaS9hcGkiLCJleHAiOjEzNjAwNDcwNTYsIm5iZiI6MTM2MDA0MzQ1Nn0.LgG2y0m24gg3vjQHhkXYYWKSVnGIUYT-ycA6JmTB6tg 70 | 71 | ### Decoded 72 | The following decoded JSON web token 73 | **Header** 74 | ```javascript 75 | { 76 | "typ": "JWT", 77 | "alg": "HS256" 78 | } 79 | ``` 80 | 81 | **Payload** 82 | ```javascript 83 | { 84 | "ver": "0.2.0", 85 | "wcn": "SupportDemo", 86 | "wid": "ca675b19-6c3c-4003-8808-1c7ddc6bd809", 87 | "rid": "96241f0f-abae-4ea9-a065-93b428eddb17", 88 | "iss": "PowerBISDK", 89 | "aud": "https://analysis.windows.net/powerbi/api", 90 | "exp": 1360047056, 91 | "nbf": 1360043456 92 | } 93 | ``` 94 | 95 | ## Adding Permission Scopes to Embed Tokens 96 | When using Embed tokens, one might want to restrict usage of the resources he gives access to. For this reason, you can generate a token with scoped permissions. 97 | 98 | ### Required Claims - Scopes 99 | - scp: {scopesClaim} 100 | scopesClaim can be either a string or array of strings, noting the allowed permissions to workspace resources (Report, Dataset, etc.) 101 | 102 | ```javascript 103 | var powerbi = require('powerbi-api'); 104 | var reportReadScope = 'Report.Read'; 105 | var token = powerbi.PowerBIToken.createReportEmbedToken('{WorkspaceCollection}', '{workspaceId}', '{reportId}', '{scopes}'); 106 | 107 | var jwt = token.generate('{AccessKey}'); 108 | ``` 109 | 110 | ## Token Example - With Scopes 111 | eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjIuMCIsIndjbiI6IlN1cHBvcnREZW1vIiwid2lkIjoiY2E2NzViMTktNmMzYy00MDAzLTg4MDgtMWM3ZGRjNmJkODA5IiwicmlkIjoiOTYyNDFmMGYtYWJhZS00ZWE5LWEwNjUtOTNiNDI4ZWRkYjE3Iiwic2NwIjoiUmVwb3J0LlJlYWQiLCJpc3MiOiJQb3dlckJJU0RLIiwiYXVkIjoiaHR0cHM6Ly9hbmFseXNpcy53aW5kb3dzLm5ldC9wb3dlcmJpL2FwaSIsImV4cCI6MTM2MDA0NzA1NiwibmJmIjoxMzYwMDQzNDU2fQ.M1jkWXnkfwJeGQqh1x0vIAYB4EBKbHSZFoDB6n_LZyA 112 | 113 | ### Decoded 114 | The following decoded JSON web token 115 | **Header** 116 | ```javascript 117 | { 118 | "typ": "JWT", 119 | "alg": "HS256" 120 | } 121 | ``` 122 | 123 | **Payload** 124 | ```javascript 125 | { 126 | "ver": "0.2.0", 127 | "wcn": "SupportDemo", 128 | "wid": "ca675b19-6c3c-4003-8808-1c7ddc6bd809", 129 | "rid": "96241f0f-abae-4ea9-a065-93b428eddb17", 130 | "scp": "Report.Read", 131 | "iss": "PowerBISDK", 132 | "aud": "https://analysis.windows.net/powerbi/api", 133 | "exp": 1360047056, 134 | "nbf": 1360043456 135 | } 136 | -------------------------------------------------------------------------------- /generate.bat: -------------------------------------------------------------------------------- 1 | setlocal 2 | 3 | set scriptfolder=%~dp0 4 | set outfolder=%scriptfolder%lib\autorest 5 | rmdir /s /q %outfolder% 6 | AutoRest.exe -CodeGenerator NodeJS -Modeler Swagger -Input https://raw.githubusercontent.com/Microsoft/powerbi-rest-api-specs/master/swagger.json -Namespace powerbi -output %outfolder% -name PowerBIClient -AddCredentials true 7 | 8 | echo "If ServiceClientCredentials is removed from lib/autorest/PowerBIClient.d.ts, revert this change. It is a bug in AutoRest" 9 | 10 | endlocal 11 | 12 | -------------------------------------------------------------------------------- /lib/.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/PowerBI-Node/0841c2a0e58e028ac7b64636142ada16aeb1f191/lib/.npmignore -------------------------------------------------------------------------------- /lib/autorest/models/basicCredentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the BasicCredentials class. 12 | * @constructor 13 | * Object representing basic authentication credentials 14 | * @member {string} [username] Username required to access the datasource 15 | * 16 | * @member {string} [password] Password required to access the datasource 17 | * 18 | */ 19 | function BasicCredentials() { 20 | } 21 | 22 | /** 23 | * Defines the metadata of BasicCredentials 24 | * 25 | * @returns {object} metadata of BasicCredentials 26 | * 27 | */ 28 | BasicCredentials.prototype.mapper = function () { 29 | return { 30 | required: false, 31 | serializedName: 'BasicCredentials', 32 | type: { 33 | name: 'Composite', 34 | className: 'BasicCredentials', 35 | modelProperties: { 36 | username: { 37 | required: false, 38 | serializedName: 'username', 39 | type: { 40 | name: 'String' 41 | } 42 | }, 43 | password: { 44 | required: false, 45 | serializedName: 'password', 46 | type: { 47 | name: 'String' 48 | } 49 | } 50 | } 51 | } 52 | }; 53 | }; 54 | 55 | module.exports = BasicCredentials; 56 | -------------------------------------------------------------------------------- /lib/autorest/models/cloneReportRequest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the CloneReportRequest class. 12 | * @constructor 13 | * Power BI Clone Report Request 14 | * @member {string} [name] The requested report name 15 | * 16 | * @member {string} [targetWorkspaceId] Optional parameter for specifying the 17 | * target workspace id 18 | * 19 | * @member {string} [targetModelId] Optional parameter for specifying the 20 | * target associated model (dataset) id 21 | * 22 | */ 23 | function CloneReportRequest() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of CloneReportRequest 28 | * 29 | * @returns {object} metadata of CloneReportRequest 30 | * 31 | */ 32 | CloneReportRequest.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'CloneReportRequest', 36 | type: { 37 | name: 'Composite', 38 | className: 'CloneReportRequest', 39 | modelProperties: { 40 | name: { 41 | required: false, 42 | serializedName: 'name', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | targetWorkspaceId: { 48 | required: false, 49 | serializedName: 'targetWorkspaceId', 50 | type: { 51 | name: 'String' 52 | } 53 | }, 54 | targetModelId: { 55 | required: false, 56 | serializedName: 'targetModelId', 57 | type: { 58 | name: 'String' 59 | } 60 | } 61 | } 62 | } 63 | }; 64 | }; 65 | 66 | module.exports = CloneReportRequest; 67 | -------------------------------------------------------------------------------- /lib/autorest/models/column.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the Column class. 12 | * @constructor 13 | * A Power BI Column 14 | * @member {string} name The column name 15 | * 16 | * @member {string} dataType The column data type 17 | * 18 | */ 19 | function Column() { 20 | } 21 | 22 | /** 23 | * Defines the metadata of Column 24 | * 25 | * @returns {object} metadata of Column 26 | * 27 | */ 28 | Column.prototype.mapper = function () { 29 | return { 30 | required: false, 31 | serializedName: 'Column', 32 | type: { 33 | name: 'Composite', 34 | className: 'Column', 35 | modelProperties: { 36 | name: { 37 | required: true, 38 | serializedName: 'name', 39 | constraints: { 40 | Pattern: '^[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]+$' 41 | }, 42 | type: { 43 | name: 'String' 44 | } 45 | }, 46 | dataType: { 47 | required: true, 48 | serializedName: 'dataType', 49 | type: { 50 | name: 'String' 51 | } 52 | } 53 | } 54 | } 55 | }; 56 | }; 57 | 58 | module.exports = Column; 59 | -------------------------------------------------------------------------------- /lib/autorest/models/createWorkspaceRequest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the CreateWorkspaceRequest class. 12 | * @constructor 13 | * A Create Workspace Request 14 | * @member {string} [name] The workspace name 15 | * 16 | */ 17 | function CreateWorkspaceRequest() { 18 | } 19 | 20 | /** 21 | * Defines the metadata of CreateWorkspaceRequest 22 | * 23 | * @returns {object} metadata of CreateWorkspaceRequest 24 | * 25 | */ 26 | CreateWorkspaceRequest.prototype.mapper = function () { 27 | return { 28 | required: false, 29 | serializedName: 'CreateWorkspaceRequest', 30 | type: { 31 | name: 'Composite', 32 | className: 'CreateWorkspaceRequest', 33 | modelProperties: { 34 | name: { 35 | required: false, 36 | serializedName: 'name', 37 | type: { 38 | name: 'String' 39 | } 40 | } 41 | } 42 | } 43 | }; 44 | }; 45 | 46 | module.exports = CreateWorkspaceRequest; 47 | -------------------------------------------------------------------------------- /lib/autorest/models/dataset.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the Dataset class. 16 | * @constructor 17 | * A Power BI Dataset 18 | * @member {string} [id] The dataset id 19 | * 20 | * @member {string} name The dataset name 21 | * 22 | * @member {string} [defaultRetentionPolicy] The dataset default data 23 | * retention policy 24 | * 25 | * @member {array} tables The dataset tables 26 | * 27 | * @member {string} [webUrl] The dataset web url 28 | * 29 | * @member {array} [datasources] The datasources associated with this dataset 30 | * 31 | * @member {string} [defaultMode] The dataset mode or type. Possible values 32 | * include: 'AsAzure', 'AsOnPrem', 'Push', 'Streaming', 'PushStreaming' 33 | * 34 | */ 35 | function Dataset() { 36 | } 37 | 38 | /** 39 | * Defines the metadata of Dataset 40 | * 41 | * @returns {object} metadata of Dataset 42 | * 43 | */ 44 | Dataset.prototype.mapper = function () { 45 | return { 46 | required: false, 47 | serializedName: 'Dataset', 48 | type: { 49 | name: 'Composite', 50 | className: 'Dataset', 51 | modelProperties: { 52 | id: { 53 | required: false, 54 | serializedName: 'id', 55 | type: { 56 | name: 'String' 57 | } 58 | }, 59 | name: { 60 | required: true, 61 | serializedName: 'name', 62 | type: { 63 | name: 'String' 64 | } 65 | }, 66 | defaultRetentionPolicy: { 67 | required: false, 68 | serializedName: 'defaultRetentionPolicy', 69 | type: { 70 | name: 'String' 71 | } 72 | }, 73 | tables: { 74 | required: true, 75 | serializedName: 'tables', 76 | type: { 77 | name: 'Sequence', 78 | element: { 79 | required: false, 80 | serializedName: 'TableElementType', 81 | type: { 82 | name: 'Composite', 83 | className: 'Table' 84 | } 85 | } 86 | } 87 | }, 88 | webUrl: { 89 | required: false, 90 | serializedName: 'webUrl', 91 | type: { 92 | name: 'String' 93 | } 94 | }, 95 | datasources: { 96 | required: false, 97 | serializedName: 'datasources', 98 | type: { 99 | name: 'Sequence', 100 | element: { 101 | required: false, 102 | serializedName: 'DatasourceElementType', 103 | type: { 104 | name: 'Composite', 105 | className: 'Datasource' 106 | } 107 | } 108 | } 109 | }, 110 | defaultMode: { 111 | required: false, 112 | serializedName: 'defaultMode', 113 | type: { 114 | name: 'String' 115 | } 116 | } 117 | } 118 | } 119 | }; 120 | }; 121 | 122 | module.exports = Dataset; 123 | -------------------------------------------------------------------------------- /lib/autorest/models/datasource.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the Datasource class. 12 | * @constructor 13 | * A Power BI datasource 14 | * @member {string} [name] The datasource name 15 | * 16 | * @member {string} [connectionString] The datasource connection string 17 | * 18 | */ 19 | function Datasource() { 20 | } 21 | 22 | /** 23 | * Defines the metadata of Datasource 24 | * 25 | * @returns {object} metadata of Datasource 26 | * 27 | */ 28 | Datasource.prototype.mapper = function () { 29 | return { 30 | required: false, 31 | serializedName: 'Datasource', 32 | type: { 33 | name: 'Composite', 34 | className: 'Datasource', 35 | modelProperties: { 36 | name: { 37 | required: false, 38 | serializedName: 'name', 39 | type: { 40 | name: 'String' 41 | } 42 | }, 43 | connectionString: { 44 | required: false, 45 | serializedName: 'connectionString', 46 | type: { 47 | name: 'String' 48 | } 49 | } 50 | } 51 | } 52 | }; 53 | }; 54 | 55 | module.exports = Datasource; 56 | -------------------------------------------------------------------------------- /lib/autorest/models/gatewayDatasource.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | /** 12 | * @class 13 | * Initializes a new instance of the GatewayDatasource class. 14 | * @constructor 15 | * A Power BI gateway datasource 16 | * @member {string} [id] The unique id for this gateway datasource 17 | * 18 | * @member {string} [gatewayId] The associated gateway id 19 | * 20 | * @member {string} [datasourceType] The datasource type 21 | * 22 | * @member {string} [connectionDetails] The datasource connection details 23 | * 24 | * @member {string} [credentialType] The datasource credential type 25 | * 26 | * @member {object} [basicCredentials] 27 | * 28 | * @member {string} [basicCredentials.username] Username required to access 29 | * the datasource 30 | * 31 | * @member {string} [basicCredentials.password] Password required to access 32 | * the datasource 33 | * 34 | */ 35 | function GatewayDatasource() { 36 | } 37 | 38 | /** 39 | * Defines the metadata of GatewayDatasource 40 | * 41 | * @returns {object} metadata of GatewayDatasource 42 | * 43 | */ 44 | GatewayDatasource.prototype.mapper = function () { 45 | return { 46 | required: false, 47 | serializedName: 'GatewayDatasource', 48 | type: { 49 | name: 'Composite', 50 | className: 'GatewayDatasource', 51 | modelProperties: { 52 | id: { 53 | required: false, 54 | serializedName: 'id', 55 | type: { 56 | name: 'String' 57 | } 58 | }, 59 | gatewayId: { 60 | required: false, 61 | serializedName: 'gatewayId', 62 | type: { 63 | name: 'String' 64 | } 65 | }, 66 | datasourceType: { 67 | required: false, 68 | serializedName: 'datasourceType', 69 | type: { 70 | name: 'String' 71 | } 72 | }, 73 | connectionDetails: { 74 | required: false, 75 | serializedName: 'connectionDetails', 76 | type: { 77 | name: 'String' 78 | } 79 | }, 80 | credentialType: { 81 | required: false, 82 | serializedName: 'credentialType', 83 | type: { 84 | name: 'String' 85 | } 86 | }, 87 | basicCredentials: { 88 | required: false, 89 | serializedName: 'basicCredentials', 90 | type: { 91 | name: 'Composite', 92 | className: 'BasicCredentials' 93 | } 94 | } 95 | } 96 | } 97 | }; 98 | }; 99 | 100 | module.exports = GatewayDatasource; 101 | -------------------------------------------------------------------------------- /lib/autorest/models/importInfo.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the ImportInfo class. 12 | * @constructor 13 | * The import info 14 | * @member {string} [filePath] The file path to import 15 | * 16 | * @member {string} [connectionType] The import connection type 17 | * 18 | */ 19 | function ImportInfo() { 20 | } 21 | 22 | /** 23 | * Defines the metadata of ImportInfo 24 | * 25 | * @returns {object} metadata of ImportInfo 26 | * 27 | */ 28 | ImportInfo.prototype.mapper = function () { 29 | return { 30 | required: false, 31 | serializedName: 'ImportInfo', 32 | type: { 33 | name: 'Composite', 34 | className: 'ImportInfo', 35 | modelProperties: { 36 | filePath: { 37 | required: false, 38 | serializedName: 'filePath', 39 | type: { 40 | name: 'String' 41 | } 42 | }, 43 | connectionType: { 44 | required: false, 45 | serializedName: 'connectionType', 46 | type: { 47 | name: 'String' 48 | } 49 | } 50 | } 51 | } 52 | }; 53 | }; 54 | 55 | module.exports = ImportInfo; 56 | -------------------------------------------------------------------------------- /lib/autorest/models/importModel.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ImportModel class. 16 | * @constructor 17 | * The import object 18 | * @member {string} [id] The import id 19 | * 20 | * @member {string} [name] The import name name 21 | * 22 | * @member {string} [importState] The import upload state 23 | * 24 | * @member {array} [reports] The reports associated with this import 25 | * 26 | * @member {array} [datasets] The datasets associated with this import 27 | * 28 | */ 29 | function ImportModel() { 30 | } 31 | 32 | /** 33 | * Defines the metadata of ImportModel 34 | * 35 | * @returns {object} metadata of ImportModel 36 | * 37 | */ 38 | ImportModel.prototype.mapper = function () { 39 | return { 40 | required: false, 41 | serializedName: 'Import', 42 | type: { 43 | name: 'Composite', 44 | className: 'ImportModel', 45 | modelProperties: { 46 | id: { 47 | required: false, 48 | serializedName: 'id', 49 | type: { 50 | name: 'String' 51 | } 52 | }, 53 | name: { 54 | required: false, 55 | serializedName: 'name', 56 | type: { 57 | name: 'String' 58 | } 59 | }, 60 | importState: { 61 | required: false, 62 | serializedName: 'importState', 63 | type: { 64 | name: 'String' 65 | } 66 | }, 67 | reports: { 68 | required: false, 69 | serializedName: 'reports', 70 | type: { 71 | name: 'Sequence', 72 | element: { 73 | required: false, 74 | serializedName: 'ReportElementType', 75 | type: { 76 | name: 'Composite', 77 | className: 'Report' 78 | } 79 | } 80 | } 81 | }, 82 | datasets: { 83 | required: false, 84 | serializedName: 'datasets', 85 | type: { 86 | name: 'Sequence', 87 | element: { 88 | required: false, 89 | serializedName: 'DatasetElementType', 90 | type: { 91 | name: 'Composite', 92 | className: 'Dataset' 93 | } 94 | } 95 | } 96 | } 97 | } 98 | } 99 | }; 100 | }; 101 | 102 | module.exports = ImportModel; 103 | -------------------------------------------------------------------------------- /lib/autorest/models/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 8 | /** 9 | * @class 10 | * Initializes a new instance of the ImportModel class. 11 | * @constructor 12 | * The import object 13 | * @member {string} [id] The import id 14 | * 15 | * @member {string} [name] The import name name 16 | * 17 | * @member {string} [importState] The import upload state 18 | * 19 | * @member {array} [reports] The reports associated with this import 20 | * 21 | * @member {array} [datasets] The datasets associated with this import 22 | * 23 | */ 24 | export interface ImportModel { 25 | id?: string; 26 | name?: string; 27 | importState?: string; 28 | reports?: Report[]; 29 | datasets?: Dataset[]; 30 | } 31 | 32 | /** 33 | * @class 34 | * Initializes a new instance of the Report class. 35 | * @constructor 36 | * A Power BI Report 37 | * @member {string} [id] The report id 38 | * 39 | * @member {string} [name] The report name 40 | * 41 | * @member {string} [webUrl] The report web url 42 | * 43 | * @member {string} [embedUrl] The report embed url 44 | * 45 | */ 46 | export interface Report { 47 | id?: string; 48 | name?: string; 49 | webUrl?: string; 50 | embedUrl?: string; 51 | } 52 | 53 | /** 54 | * @class 55 | * Initializes a new instance of the Dataset class. 56 | * @constructor 57 | * A Power BI Dataset 58 | * @member {string} [id] The dataset id 59 | * 60 | * @member {string} name The dataset name 61 | * 62 | * @member {string} [defaultRetentionPolicy] The dataset default data 63 | * retention policy 64 | * 65 | * @member {array} tables The dataset tables 66 | * 67 | * @member {string} [webUrl] The dataset web url 68 | * 69 | * @member {array} [datasources] The datasources associated with this dataset 70 | * 71 | * @member {string} [defaultMode] The dataset mode or type. Possible values 72 | * include: 'AsAzure', 'AsOnPrem', 'Push', 'Streaming', 'PushStreaming' 73 | * 74 | */ 75 | export interface Dataset { 76 | id?: string; 77 | name: string; 78 | defaultRetentionPolicy?: string; 79 | tables: Table[]; 80 | webUrl?: string; 81 | datasources?: Datasource[]; 82 | defaultMode?: string; 83 | } 84 | 85 | /** 86 | * @class 87 | * Initializes a new instance of the Table class. 88 | * @constructor 89 | * A dataset table 90 | * @member {string} name The table name 91 | * 92 | * @member {array} columns The column schema for this table 93 | * 94 | * @member {array} [rows] The data rows within this tabe 95 | * 96 | */ 97 | export interface Table { 98 | name: string; 99 | columns: Column[]; 100 | rows?: Row[]; 101 | } 102 | 103 | /** 104 | * @class 105 | * Initializes a new instance of the Column class. 106 | * @constructor 107 | * A Power BI Column 108 | * @member {string} name The column name 109 | * 110 | * @member {string} dataType The column data type 111 | * 112 | */ 113 | export interface Column { 114 | name: string; 115 | dataType: string; 116 | } 117 | 118 | /** 119 | * @class 120 | * Initializes a new instance of the Row class. 121 | * @constructor 122 | * A Power BI data row 123 | * @member {string} [id] The unique row id 124 | * 125 | */ 126 | export interface Row { 127 | id?: string; 128 | } 129 | 130 | /** 131 | * @class 132 | * Initializes a new instance of the Datasource class. 133 | * @constructor 134 | * A Power BI datasource 135 | * @member {string} [name] The datasource name 136 | * 137 | * @member {string} [connectionString] The datasource connection string 138 | * 139 | */ 140 | export interface Datasource { 141 | name?: string; 142 | connectionString?: string; 143 | } 144 | 145 | /** 146 | * @class 147 | * Initializes a new instance of the ImportInfo class. 148 | * @constructor 149 | * The import info 150 | * @member {string} [filePath] The file path to import 151 | * 152 | * @member {string} [connectionType] The import connection type 153 | * 154 | */ 155 | export interface ImportInfo { 156 | filePath?: string; 157 | connectionType?: string; 158 | } 159 | 160 | /** 161 | * @class 162 | * Initializes a new instance of the ODataResponseListDataset class. 163 | * @constructor 164 | * A dataset odata list wrapper 165 | * @member {string} [odatacontext] 166 | * 167 | * @member {array} [value] The datasets 168 | * 169 | */ 170 | export interface ODataResponseListDataset { 171 | odatacontext?: string; 172 | value?: Dataset[]; 173 | } 174 | 175 | /** 176 | * @class 177 | * Initializes a new instance of the ODataResponseListTable class. 178 | * @constructor 179 | * Odata response wrapper for a Power BI Table collection 180 | * @member {string} [odatacontext] 181 | * 182 | * @member {array} [value] The Power BI tables 183 | * 184 | */ 185 | export interface ODataResponseListTable { 186 | odatacontext?: string; 187 | value?: Table[]; 188 | } 189 | 190 | /** 191 | * @class 192 | * Initializes a new instance of the ODataResponseListGatewayDatasource class. 193 | * @constructor 194 | * Odata response wrapper for a Power BI Gateway datasource collection 195 | * @member {string} [odatacontext] 196 | * 197 | * @member {array} [value] The gateway datasources 198 | * 199 | */ 200 | export interface ODataResponseListGatewayDatasource { 201 | odatacontext?: string; 202 | value?: GatewayDatasource[]; 203 | } 204 | 205 | /** 206 | * @class 207 | * Initializes a new instance of the GatewayDatasource class. 208 | * @constructor 209 | * A Power BI gateway datasource 210 | * @member {string} [id] The unique id for this gateway datasource 211 | * 212 | * @member {string} [gatewayId] The associated gateway id 213 | * 214 | * @member {string} [datasourceType] The datasource type 215 | * 216 | * @member {string} [connectionDetails] The datasource connection details 217 | * 218 | * @member {string} [credentialType] The datasource credential type 219 | * 220 | * @member {object} [basicCredentials] 221 | * 222 | * @member {string} [basicCredentials.username] Username required to access 223 | * the datasource 224 | * 225 | * @member {string} [basicCredentials.password] Password required to access 226 | * the datasource 227 | * 228 | */ 229 | export interface GatewayDatasource { 230 | id?: string; 231 | gatewayId?: string; 232 | datasourceType?: string; 233 | connectionDetails?: string; 234 | credentialType?: string; 235 | basicCredentials?: BasicCredentials; 236 | } 237 | 238 | /** 239 | * @class 240 | * Initializes a new instance of the BasicCredentials class. 241 | * @constructor 242 | * Object representing basic authentication credentials 243 | * @member {string} [username] Username required to access the datasource 244 | * 245 | * @member {string} [password] Password required to access the datasource 246 | * 247 | */ 248 | export interface BasicCredentials { 249 | username?: string; 250 | password?: string; 251 | } 252 | 253 | /** 254 | * @class 255 | * Initializes a new instance of the ODataResponseListDatasource class. 256 | * @constructor 257 | * Odata response wrapper for a Power BI datasource collection 258 | * @member {string} [odatacontext] 259 | * 260 | * @member {array} [value] The datasource collection 261 | * 262 | */ 263 | export interface ODataResponseListDatasource { 264 | odatacontext?: string; 265 | value?: Datasource[]; 266 | } 267 | 268 | /** 269 | * @class 270 | * Initializes a new instance of the ODataResponseListReport class. 271 | * @constructor 272 | * Odata response wrapper for a Power BI Report collection 273 | * @member {string} [odatacontext] 274 | * 275 | * @member {array} [value] The report collection 276 | * 277 | */ 278 | export interface ODataResponseListReport { 279 | odatacontext?: string; 280 | value?: Report[]; 281 | } 282 | 283 | /** 284 | * @class 285 | * Initializes a new instance of the ODataResponseListImport class. 286 | * @constructor 287 | * Odata response wrapper for a Power BI Import collection 288 | * @member {string} [odatacontext] 289 | * 290 | * @member {array} [value] The imports collection 291 | * 292 | */ 293 | export interface ODataResponseListImport { 294 | odatacontext?: string; 295 | value?: ImportModel[]; 296 | } 297 | 298 | /** 299 | * @class 300 | * Initializes a new instance of the ODataResponseListWorkspace class. 301 | * @constructor 302 | * Odata response wrapper for a Power BI Workspace list 303 | * @member {string} [odatacontext] 304 | * 305 | * @member {array} [value] The workspaces 306 | * 307 | */ 308 | export interface ODataResponseListWorkspace { 309 | odatacontext?: string; 310 | value?: Workspace[]; 311 | } 312 | 313 | /** 314 | * @class 315 | * Initializes a new instance of the Workspace class. 316 | * @constructor 317 | * A Power BI Workspace 318 | * @member {string} [workspaceId] The workspace id 319 | * 320 | * @member {string} [workspaceCollectionName] The workspace collection name 321 | * 322 | * @member {string} [displayName] The workspace display name 323 | * 324 | */ 325 | export interface Workspace { 326 | workspaceId?: string; 327 | workspaceCollectionName?: string; 328 | displayName?: string; 329 | } 330 | 331 | /** 332 | * @class 333 | * Initializes a new instance of the CreateWorkspaceRequest class. 334 | * @constructor 335 | * A Create Workspace Request 336 | * @member {string} [name] The workspace name 337 | * 338 | */ 339 | export interface CreateWorkspaceRequest { 340 | name?: string; 341 | } 342 | 343 | /** 344 | * @class 345 | * Initializes a new instance of the CloneReportRequest class. 346 | * @constructor 347 | * Power BI Clone Report Request 348 | * @member {string} [name] The requested report name 349 | * 350 | * @member {string} [targetWorkspaceId] Optional parameter for specifying the 351 | * target workspace id 352 | * 353 | * @member {string} [targetModelId] Optional parameter for specifying the 354 | * target associated model (dataset) id 355 | * 356 | */ 357 | export interface CloneReportRequest { 358 | name?: string; 359 | targetWorkspaceId?: string; 360 | targetModelId?: string; 361 | } 362 | 363 | /** 364 | * @class 365 | * Initializes a new instance of the RebindReportRequest class. 366 | * @constructor 367 | * Power BI Rebind Report Request 368 | * @member {string} [datasetId] The new dataset of the rebinded report 369 | * 370 | */ 371 | export interface RebindReportRequest { 372 | datasetId?: string; 373 | } 374 | -------------------------------------------------------------------------------- /lib/autorest/models/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | /* jshint latedef:false */ 8 | /* jshint forin:false */ 9 | /* jshint noempty:false */ 10 | 11 | 'use strict'; 12 | 13 | exports.ImportModel = require('./importModel'); 14 | exports.Report = require('./report'); 15 | exports.Dataset = require('./dataset'); 16 | exports.Table = require('./table'); 17 | exports.Column = require('./column'); 18 | exports.Row = require('./row'); 19 | exports.Datasource = require('./datasource'); 20 | exports.ImportInfo = require('./importInfo'); 21 | exports.ODataResponseListDataset = require('./oDataResponseListDataset'); 22 | exports.ODataResponseListTable = require('./oDataResponseListTable'); 23 | exports.ODataResponseListGatewayDatasource = require('./oDataResponseListGatewayDatasource'); 24 | exports.GatewayDatasource = require('./gatewayDatasource'); 25 | exports.BasicCredentials = require('./basicCredentials'); 26 | exports.ODataResponseListDatasource = require('./oDataResponseListDatasource'); 27 | exports.ODataResponseListReport = require('./oDataResponseListReport'); 28 | exports.ODataResponseListImport = require('./oDataResponseListImport'); 29 | exports.ODataResponseListWorkspace = require('./oDataResponseListWorkspace'); 30 | exports.Workspace = require('./workspace'); 31 | exports.CreateWorkspaceRequest = require('./createWorkspaceRequest'); 32 | exports.CloneReportRequest = require('./cloneReportRequest'); 33 | exports.RebindReportRequest = require('./rebindReportRequest'); 34 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListDataset.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListDataset class. 16 | * @constructor 17 | * A dataset odata list wrapper 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The datasets 21 | * 22 | */ 23 | function ODataResponseListDataset() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListDataset 28 | * 29 | * @returns {object} metadata of ODataResponseListDataset 30 | * 31 | */ 32 | ODataResponseListDataset.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Dataset]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListDataset', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'DatasetElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'Dataset' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListDataset; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListDatasource.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListDatasource class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI datasource collection 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The datasource collection 21 | * 22 | */ 23 | function ODataResponseListDatasource() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListDatasource 28 | * 29 | * @returns {object} metadata of ODataResponseListDatasource 30 | * 31 | */ 32 | ODataResponseListDatasource.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Datasource]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListDatasource', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'DatasourceElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'Datasource' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListDatasource; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListGatewayDatasource.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListGatewayDatasource class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI Gateway datasource collection 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The gateway datasources 21 | * 22 | */ 23 | function ODataResponseListGatewayDatasource() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListGatewayDatasource 28 | * 29 | * @returns {object} metadata of ODataResponseListGatewayDatasource 30 | * 31 | */ 32 | ODataResponseListGatewayDatasource.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[GatewayDatasource]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListGatewayDatasource', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'GatewayDatasourceElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'GatewayDatasource' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListGatewayDatasource; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListImport.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListImport class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI Import collection 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The imports collection 21 | * 22 | */ 23 | function ODataResponseListImport() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListImport 28 | * 29 | * @returns {object} metadata of ODataResponseListImport 30 | * 31 | */ 32 | ODataResponseListImport.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Import]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListImport', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'ImportModelElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'ImportModel' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListImport; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListReport.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListReport class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI Report collection 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The report collection 21 | * 22 | */ 23 | function ODataResponseListReport() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListReport 28 | * 29 | * @returns {object} metadata of ODataResponseListReport 30 | * 31 | */ 32 | ODataResponseListReport.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Report]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListReport', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'ReportElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'Report' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListReport; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListTable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListTable class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI Table collection 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The Power BI tables 21 | * 22 | */ 23 | function ODataResponseListTable() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListTable 28 | * 29 | * @returns {object} metadata of ODataResponseListTable 30 | * 31 | */ 32 | ODataResponseListTable.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Table]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListTable', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'TableElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'Table' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListTable; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/oDataResponseListWorkspace.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the ODataResponseListWorkspace class. 16 | * @constructor 17 | * Odata response wrapper for a Power BI Workspace list 18 | * @member {string} [odatacontext] 19 | * 20 | * @member {array} [value] The workspaces 21 | * 22 | */ 23 | function ODataResponseListWorkspace() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of ODataResponseListWorkspace 28 | * 29 | * @returns {object} metadata of ODataResponseListWorkspace 30 | * 31 | */ 32 | ODataResponseListWorkspace.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'ODataResponse[List[Workspace]]', 36 | type: { 37 | name: 'Composite', 38 | className: 'ODataResponseListWorkspace', 39 | modelProperties: { 40 | odatacontext: { 41 | required: false, 42 | serializedName: 'odata\\.context', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | value: { 48 | required: false, 49 | serializedName: 'value', 50 | type: { 51 | name: 'Sequence', 52 | element: { 53 | required: false, 54 | serializedName: 'WorkspaceElementType', 55 | type: { 56 | name: 'Composite', 57 | className: 'Workspace' 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }; 65 | }; 66 | 67 | module.exports = ODataResponseListWorkspace; 68 | -------------------------------------------------------------------------------- /lib/autorest/models/rebindReportRequest.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the RebindReportRequest class. 12 | * @constructor 13 | * Power BI Rebind Report Request 14 | * @member {string} [datasetId] The new dataset of the rebinded report 15 | * 16 | */ 17 | function RebindReportRequest() { 18 | } 19 | 20 | /** 21 | * Defines the metadata of RebindReportRequest 22 | * 23 | * @returns {object} metadata of RebindReportRequest 24 | * 25 | */ 26 | RebindReportRequest.prototype.mapper = function () { 27 | return { 28 | required: false, 29 | serializedName: 'RebindReportRequest', 30 | type: { 31 | name: 'Composite', 32 | className: 'RebindReportRequest', 33 | modelProperties: { 34 | datasetId: { 35 | required: false, 36 | serializedName: 'datasetId', 37 | type: { 38 | name: 'String' 39 | } 40 | } 41 | } 42 | } 43 | }; 44 | }; 45 | 46 | module.exports = RebindReportRequest; 47 | -------------------------------------------------------------------------------- /lib/autorest/models/report.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the Report class. 12 | * @constructor 13 | * A Power BI Report 14 | * @member {string} [id] The report id 15 | * 16 | * @member {string} [name] The report name 17 | * 18 | * @member {string} [webUrl] The report web url 19 | * 20 | * @member {string} [embedUrl] The report embed url 21 | * 22 | */ 23 | function Report() { 24 | } 25 | 26 | /** 27 | * Defines the metadata of Report 28 | * 29 | * @returns {object} metadata of Report 30 | * 31 | */ 32 | Report.prototype.mapper = function () { 33 | return { 34 | required: false, 35 | serializedName: 'Report', 36 | type: { 37 | name: 'Composite', 38 | className: 'Report', 39 | modelProperties: { 40 | id: { 41 | required: false, 42 | serializedName: 'id', 43 | type: { 44 | name: 'String' 45 | } 46 | }, 47 | name: { 48 | required: false, 49 | serializedName: 'name', 50 | type: { 51 | name: 'String' 52 | } 53 | }, 54 | webUrl: { 55 | required: false, 56 | serializedName: 'webUrl', 57 | type: { 58 | name: 'String' 59 | } 60 | }, 61 | embedUrl: { 62 | required: false, 63 | serializedName: 'embedUrl', 64 | type: { 65 | name: 'String' 66 | } 67 | } 68 | } 69 | } 70 | }; 71 | }; 72 | 73 | module.exports = Report; 74 | -------------------------------------------------------------------------------- /lib/autorest/models/row.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the Row class. 12 | * @constructor 13 | * A Power BI data row 14 | * @member {string} [id] The unique row id 15 | * 16 | */ 17 | function Row() { 18 | } 19 | 20 | /** 21 | * Defines the metadata of Row 22 | * 23 | * @returns {object} metadata of Row 24 | * 25 | */ 26 | Row.prototype.mapper = function () { 27 | return { 28 | required: false, 29 | serializedName: 'Row', 30 | type: { 31 | name: 'Composite', 32 | className: 'Row', 33 | modelProperties: { 34 | id: { 35 | required: false, 36 | serializedName: 'id', 37 | type: { 38 | name: 'String' 39 | } 40 | } 41 | } 42 | } 43 | }; 44 | }; 45 | 46 | module.exports = Row; 47 | -------------------------------------------------------------------------------- /lib/autorest/models/table.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var models = require('./index'); 10 | 11 | var util = require('util'); 12 | 13 | /** 14 | * @class 15 | * Initializes a new instance of the Table class. 16 | * @constructor 17 | * A dataset table 18 | * @member {string} name The table name 19 | * 20 | * @member {array} columns The column schema for this table 21 | * 22 | * @member {array} [rows] The data rows within this tabe 23 | * 24 | */ 25 | function Table() { 26 | } 27 | 28 | /** 29 | * Defines the metadata of Table 30 | * 31 | * @returns {object} metadata of Table 32 | * 33 | */ 34 | Table.prototype.mapper = function () { 35 | return { 36 | required: false, 37 | serializedName: 'Table', 38 | type: { 39 | name: 'Composite', 40 | className: 'Table', 41 | modelProperties: { 42 | name: { 43 | required: true, 44 | serializedName: 'name', 45 | constraints: { 46 | Pattern: '^[\x09\x0A\x0D\x20\x23\x2D\x30-\x39\x40-\x5A\x5E-\x5F\x61-\x7A\x7E-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]{1,100}$' 47 | }, 48 | type: { 49 | name: 'String' 50 | } 51 | }, 52 | columns: { 53 | required: true, 54 | serializedName: 'columns', 55 | type: { 56 | name: 'Sequence', 57 | element: { 58 | required: false, 59 | serializedName: 'ColumnElementType', 60 | type: { 61 | name: 'Composite', 62 | className: 'Column' 63 | } 64 | } 65 | } 66 | }, 67 | rows: { 68 | required: false, 69 | serializedName: 'rows', 70 | type: { 71 | name: 'Sequence', 72 | element: { 73 | required: false, 74 | serializedName: 'RowElementType', 75 | type: { 76 | name: 'Composite', 77 | className: 'Row' 78 | } 79 | } 80 | } 81 | } 82 | } 83 | } 84 | }; 85 | }; 86 | 87 | module.exports = Table; 88 | -------------------------------------------------------------------------------- /lib/autorest/models/workspace.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | /** 10 | * @class 11 | * Initializes a new instance of the Workspace class. 12 | * @constructor 13 | * A Power BI Workspace 14 | * @member {string} [workspaceId] The workspace id 15 | * 16 | * @member {string} [workspaceCollectionName] The workspace collection name 17 | * 18 | * @member {string} [displayName] The workspace display name 19 | * 20 | */ 21 | function Workspace() { 22 | } 23 | 24 | /** 25 | * Defines the metadata of Workspace 26 | * 27 | * @returns {object} metadata of Workspace 28 | * 29 | */ 30 | Workspace.prototype.mapper = function () { 31 | return { 32 | required: false, 33 | serializedName: 'Workspace', 34 | type: { 35 | name: 'Composite', 36 | className: 'Workspace', 37 | modelProperties: { 38 | workspaceId: { 39 | required: false, 40 | serializedName: 'workspaceId', 41 | type: { 42 | name: 'String' 43 | } 44 | }, 45 | workspaceCollectionName: { 46 | required: false, 47 | serializedName: 'workspaceCollectionName', 48 | type: { 49 | name: 'String' 50 | } 51 | }, 52 | displayName: { 53 | required: false, 54 | serializedName: 'displayName', 55 | type: { 56 | name: 'String' 57 | } 58 | } 59 | } 60 | } 61 | }; 62 | }; 63 | 64 | module.exports = Workspace; 65 | -------------------------------------------------------------------------------- /lib/autorest/operations/gateways.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var util = require('util'); 10 | var msRest = require('ms-rest'); 11 | var WebResource = msRest.WebResource; 12 | 13 | /** 14 | * @class 15 | * Gateways 16 | * __NOTE__: An instance of this class is automatically created for an 17 | * instance of the PowerBIClient. 18 | * Initializes a new instance of the Gateways class. 19 | * @constructor 20 | * 21 | * @param {PowerBIClient} client Reference to the service client. 22 | */ 23 | function Gateways(client) { 24 | this.client = client; 25 | } 26 | 27 | /** 28 | * @summary Updates the credentials for the specified datasource 29 | * 30 | * @param {string} collectionName The workspace collection name 31 | * 32 | * @param {string} workspaceId The workspace id 33 | * 34 | * @param {string} gatewayId The gateway id 35 | * 36 | * @param {string} datasourceId The datasource id 37 | * 38 | * @param {object} datasourceDelta The datasource changes 39 | * 40 | * @param {object} [options] Optional Parameters. 41 | * 42 | * @param {object} [options.customHeaders] Headers that will be added to the 43 | * request 44 | * 45 | * @param {function} callback 46 | * 47 | * @returns {function} callback(err, result, request, response) 48 | * 49 | * {Error} err - The Error object if an error occurred, null otherwise. 50 | * 51 | * {object} [result] - The deserialized result object. 52 | * 53 | * {object} [request] - The HTTP Request object if an error did not occur. 54 | * 55 | * {stream} [response] - The HTTP Response stream if an error did not occur. 56 | */ 57 | Gateways.prototype.patchDatasource = function (collectionName, workspaceId, gatewayId, datasourceId, datasourceDelta, options, callback) { 58 | var client = this.client; 59 | if(!callback && typeof options === 'function') { 60 | callback = options; 61 | options = null; 62 | } 63 | if (!callback) { 64 | throw new Error('callback cannot be null.'); 65 | } 66 | // Validate 67 | try { 68 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 69 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 70 | } 71 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 72 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 73 | } 74 | if (gatewayId === null || gatewayId === undefined || typeof gatewayId.valueOf() !== 'string') { 75 | throw new Error('gatewayId cannot be null or undefined and it must be of type string.'); 76 | } 77 | if (datasourceId === null || datasourceId === undefined || typeof datasourceId.valueOf() !== 'string') { 78 | throw new Error('datasourceId cannot be null or undefined and it must be of type string.'); 79 | } 80 | if (datasourceDelta === null || datasourceDelta === undefined || typeof datasourceDelta !== 'object') { 81 | throw new Error('datasourceDelta cannot be null or undefined and it must be of type object.'); 82 | } 83 | } catch (error) { 84 | return callback(error); 85 | } 86 | 87 | // Construct URL 88 | var requestUrl = this.client.baseUri + 89 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/gateways/{gatewayId}/datasources/{datasourceId}'; 90 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 91 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 92 | requestUrl = requestUrl.replace('{gatewayId}', encodeURIComponent(gatewayId)); 93 | requestUrl = requestUrl.replace('{datasourceId}', encodeURIComponent(datasourceId)); 94 | // trim all duplicate forward slashes in the url 95 | var regex = /([^:]\/)\/+/gi; 96 | requestUrl = requestUrl.replace(regex, '$1'); 97 | 98 | // Create HTTP transport objects 99 | var httpRequest = new WebResource(); 100 | httpRequest.method = 'PATCH'; 101 | httpRequest.headers = {}; 102 | httpRequest.url = requestUrl; 103 | // Set Headers 104 | if(options) { 105 | for(var headerName in options['customHeaders']) { 106 | if (options['customHeaders'].hasOwnProperty(headerName)) { 107 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 108 | } 109 | } 110 | } 111 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 112 | // Serialize Request 113 | var requestContent = null; 114 | var requestModel = null; 115 | try { 116 | if (datasourceDelta !== null && datasourceDelta !== undefined) { 117 | var requestModelMapper = { 118 | required: true, 119 | serializedName: 'datasourceDelta', 120 | type: { 121 | name: 'Object' 122 | } 123 | }; 124 | requestModel = client.serialize(requestModelMapper, datasourceDelta, 'datasourceDelta'); 125 | requestContent = JSON.stringify(requestModel); 126 | } 127 | } catch (error) { 128 | var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 129 | 'payload - "%s"', error.message, util.inspect(datasourceDelta, {depth: null}))); 130 | return callback(serializationError); 131 | } 132 | httpRequest.body = requestContent; 133 | // Send Request 134 | return client.pipeline(httpRequest, function (err, response, responseBody) { 135 | if (err) { 136 | return callback(err); 137 | } 138 | var statusCode = response.statusCode; 139 | if (statusCode !== 200) { 140 | var error = new Error(responseBody); 141 | error.statusCode = response.statusCode; 142 | error.request = msRest.stripRequest(httpRequest); 143 | error.response = msRest.stripResponse(response); 144 | if (responseBody === '') responseBody = null; 145 | var parsedErrorResponse; 146 | try { 147 | parsedErrorResponse = JSON.parse(responseBody); 148 | if (parsedErrorResponse) { 149 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 150 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 151 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 152 | } 153 | } catch (defaultError) { 154 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 155 | '- "%s" for the default response.', defaultError.message, responseBody); 156 | return callback(error); 157 | } 158 | return callback(error); 159 | } 160 | // Create Result 161 | var result = null; 162 | if (responseBody === '') responseBody = null; 163 | // Deserialize Response 164 | if (statusCode === 200) { 165 | var parsedResponse = null; 166 | try { 167 | parsedResponse = JSON.parse(responseBody); 168 | result = JSON.parse(responseBody); 169 | if (parsedResponse !== null && parsedResponse !== undefined) { 170 | var resultMapper = { 171 | required: false, 172 | serializedName: 'parsedResponse', 173 | type: { 174 | name: 'Object' 175 | } 176 | }; 177 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 178 | } 179 | } catch (error) { 180 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 181 | deserializationError.request = msRest.stripRequest(httpRequest); 182 | deserializationError.response = msRest.stripResponse(response); 183 | return callback(deserializationError); 184 | } 185 | } 186 | 187 | return callback(null, result, httpRequest, response); 188 | }); 189 | }; 190 | 191 | 192 | module.exports = Gateways; 193 | -------------------------------------------------------------------------------- /lib/autorest/operations/imports.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var util = require('util'); 10 | var msRest = require('ms-rest'); 11 | var WebResource = msRest.WebResource; 12 | 13 | /** 14 | * @class 15 | * Imports 16 | * __NOTE__: An instance of this class is automatically created for an 17 | * instance of the PowerBIClient. 18 | * Initializes a new instance of the Imports class. 19 | * @constructor 20 | * 21 | * @param {PowerBIClient} client Reference to the service client. 22 | */ 23 | function Imports(client) { 24 | this.client = client; 25 | } 26 | 27 | /** 28 | * @summary Returns a list of imports for the specified workspace 29 | * 30 | * @param {string} collectionName The workspace collection name 31 | * 32 | * @param {string} workspaceId The workspace id 33 | * 34 | * @param {object} [options] Optional Parameters. 35 | * 36 | * @param {object} [options.customHeaders] Headers that will be added to the 37 | * request 38 | * 39 | * @param {function} callback 40 | * 41 | * @returns {function} callback(err, result, request, response) 42 | * 43 | * {Error} err - The Error object if an error occurred, null otherwise. 44 | * 45 | * {object} [result] - The deserialized result object. 46 | * See {@link ODataResponseListImport} for more 47 | * information. 48 | * 49 | * {object} [request] - The HTTP Request object if an error did not occur. 50 | * 51 | * {stream} [response] - The HTTP Response stream if an error did not occur. 52 | */ 53 | Imports.prototype.getImports = function (collectionName, workspaceId, options, callback) { 54 | var client = this.client; 55 | if(!callback && typeof options === 'function') { 56 | callback = options; 57 | options = null; 58 | } 59 | if (!callback) { 60 | throw new Error('callback cannot be null.'); 61 | } 62 | // Validate 63 | try { 64 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 65 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 66 | } 67 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 68 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 69 | } 70 | } catch (error) { 71 | return callback(error); 72 | } 73 | 74 | // Construct URL 75 | var requestUrl = this.client.baseUri + 76 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports'; 77 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 78 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 79 | // trim all duplicate forward slashes in the url 80 | var regex = /([^:]\/)\/+/gi; 81 | requestUrl = requestUrl.replace(regex, '$1'); 82 | 83 | // Create HTTP transport objects 84 | var httpRequest = new WebResource(); 85 | httpRequest.method = 'GET'; 86 | httpRequest.headers = {}; 87 | httpRequest.url = requestUrl; 88 | // Set Headers 89 | if(options) { 90 | for(var headerName in options['customHeaders']) { 91 | if (options['customHeaders'].hasOwnProperty(headerName)) { 92 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 93 | } 94 | } 95 | } 96 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 97 | httpRequest.body = null; 98 | // Send Request 99 | return client.pipeline(httpRequest, function (err, response, responseBody) { 100 | if (err) { 101 | return callback(err); 102 | } 103 | var statusCode = response.statusCode; 104 | if (statusCode !== 200) { 105 | var error = new Error(responseBody); 106 | error.statusCode = response.statusCode; 107 | error.request = msRest.stripRequest(httpRequest); 108 | error.response = msRest.stripResponse(response); 109 | if (responseBody === '') responseBody = null; 110 | var parsedErrorResponse; 111 | try { 112 | parsedErrorResponse = JSON.parse(responseBody); 113 | if (parsedErrorResponse) { 114 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 115 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 116 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 117 | } 118 | } catch (defaultError) { 119 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 120 | '- "%s" for the default response.', defaultError.message, responseBody); 121 | return callback(error); 122 | } 123 | return callback(error); 124 | } 125 | // Create Result 126 | var result = null; 127 | if (responseBody === '') responseBody = null; 128 | // Deserialize Response 129 | if (statusCode === 200) { 130 | var parsedResponse = null; 131 | try { 132 | parsedResponse = JSON.parse(responseBody); 133 | result = JSON.parse(responseBody); 134 | if (parsedResponse !== null && parsedResponse !== undefined) { 135 | var resultMapper = new client.models['ODataResponseListImport']().mapper(); 136 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 137 | } 138 | } catch (error) { 139 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 140 | deserializationError.request = msRest.stripRequest(httpRequest); 141 | deserializationError.response = msRest.stripResponse(response); 142 | return callback(deserializationError); 143 | } 144 | } 145 | 146 | return callback(null, result, httpRequest, response); 147 | }); 148 | }; 149 | 150 | /** 151 | * @summary Creates a new import using the specified import info 152 | * 153 | * @param {string} collectionName The workspace collection name 154 | * 155 | * @param {string} workspaceId The workspace id 156 | * 157 | * @param {string} datasetDisplayName The display name of the dataset 158 | * 159 | * @param {object} importInfo The import to post 160 | * 161 | * @param {string} [importInfo.filePath] The file path to import 162 | * 163 | * @param {string} [importInfo.connectionType] The import connection type 164 | * 165 | * @param {object} [options] Optional Parameters. 166 | * 167 | * @param {string} [options.nameConflict] Determines what to do if a dataset 168 | * with the same name already exists 169 | * 170 | * @param {object} [options.customHeaders] Headers that will be added to the 171 | * request 172 | * 173 | * @param {function} callback 174 | * 175 | * @returns {function} callback(err, result, request, response) 176 | * 177 | * {Error} err - The Error object if an error occurred, null otherwise. 178 | * 179 | * {object} [result] - The deserialized result object. 180 | * See {@link ImportModel} for more information. 181 | * 182 | * {object} [request] - The HTTP Request object if an error did not occur. 183 | * 184 | * {stream} [response] - The HTTP Response stream if an error did not occur. 185 | */ 186 | Imports.prototype.postImport = function (collectionName, workspaceId, datasetDisplayName, importInfo, options, callback) { 187 | var client = this.client; 188 | if(!callback && typeof options === 'function') { 189 | callback = options; 190 | options = null; 191 | } 192 | if (!callback) { 193 | throw new Error('callback cannot be null.'); 194 | } 195 | var nameConflict = (options && options.nameConflict !== undefined) ? options.nameConflict : undefined; 196 | // Validate 197 | try { 198 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 199 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 200 | } 201 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 202 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 203 | } 204 | if (datasetDisplayName === null || datasetDisplayName === undefined || typeof datasetDisplayName.valueOf() !== 'string') { 205 | throw new Error('datasetDisplayName cannot be null or undefined and it must be of type string.'); 206 | } 207 | if (nameConflict !== null && nameConflict !== undefined && typeof nameConflict.valueOf() !== 'string') { 208 | throw new Error('nameConflict must be of type string.'); 209 | } 210 | if (importInfo === null || importInfo === undefined) { 211 | throw new Error('importInfo cannot be null or undefined.'); 212 | } 213 | } catch (error) { 214 | return callback(error); 215 | } 216 | 217 | // Construct URL 218 | var requestUrl = this.client.baseUri + 219 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports'; 220 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 221 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 222 | var queryParameters = []; 223 | queryParameters.push('datasetDisplayName=' + encodeURIComponent(datasetDisplayName)); 224 | if (nameConflict !== null && nameConflict !== undefined) { 225 | queryParameters.push('nameConflict=' + encodeURIComponent(nameConflict)); 226 | } 227 | if (queryParameters.length > 0) { 228 | requestUrl += '?' + queryParameters.join('&'); 229 | } 230 | // trim all duplicate forward slashes in the url 231 | var regex = /([^:]\/)\/+/gi; 232 | requestUrl = requestUrl.replace(regex, '$1'); 233 | 234 | // Create HTTP transport objects 235 | var httpRequest = new WebResource(); 236 | httpRequest.method = 'POST'; 237 | httpRequest.headers = {}; 238 | httpRequest.url = requestUrl; 239 | // Set Headers 240 | if(options) { 241 | for(var headerName in options['customHeaders']) { 242 | if (options['customHeaders'].hasOwnProperty(headerName)) { 243 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 244 | } 245 | } 246 | } 247 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 248 | // Serialize Request 249 | var requestContent = null; 250 | var requestModel = null; 251 | try { 252 | if (importInfo !== null && importInfo !== undefined) { 253 | var requestModelMapper = new client.models['ImportInfo']().mapper(); 254 | requestModel = client.serialize(requestModelMapper, importInfo, 'importInfo'); 255 | requestContent = JSON.stringify(requestModel); 256 | } 257 | } catch (error) { 258 | var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 259 | 'payload - "%s"', error.message, util.inspect(importInfo, {depth: null}))); 260 | return callback(serializationError); 261 | } 262 | httpRequest.body = requestContent; 263 | // Send Request 264 | return client.pipeline(httpRequest, function (err, response, responseBody) { 265 | if (err) { 266 | return callback(err); 267 | } 268 | var statusCode = response.statusCode; 269 | if (statusCode !== 200) { 270 | var error = new Error(responseBody); 271 | error.statusCode = response.statusCode; 272 | error.request = msRest.stripRequest(httpRequest); 273 | error.response = msRest.stripResponse(response); 274 | if (responseBody === '') responseBody = null; 275 | var parsedErrorResponse; 276 | try { 277 | parsedErrorResponse = JSON.parse(responseBody); 278 | if (parsedErrorResponse) { 279 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 280 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 281 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 282 | } 283 | } catch (defaultError) { 284 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 285 | '- "%s" for the default response.', defaultError.message, responseBody); 286 | return callback(error); 287 | } 288 | return callback(error); 289 | } 290 | // Create Result 291 | var result = null; 292 | if (responseBody === '') responseBody = null; 293 | // Deserialize Response 294 | if (statusCode === 200) { 295 | var parsedResponse = null; 296 | try { 297 | parsedResponse = JSON.parse(responseBody); 298 | result = JSON.parse(responseBody); 299 | if (parsedResponse !== null && parsedResponse !== undefined) { 300 | var resultMapper = new client.models['ImportModel']().mapper(); 301 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 302 | } 303 | } catch (error) { 304 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 305 | deserializationError.request = msRest.stripRequest(httpRequest); 306 | deserializationError.response = msRest.stripResponse(response); 307 | return callback(deserializationError); 308 | } 309 | } 310 | 311 | return callback(null, result, httpRequest, response); 312 | }); 313 | }; 314 | 315 | /** 316 | * @summary Gets the import metadata for the specifed import id 317 | * 318 | * @param {string} collectionName The workspace collection name 319 | * 320 | * @param {string} workspaceId The workspace id 321 | * 322 | * @param {string} importId The import id 323 | * 324 | * @param {object} [options] Optional Parameters. 325 | * 326 | * @param {object} [options.customHeaders] Headers that will be added to the 327 | * request 328 | * 329 | * @param {function} callback 330 | * 331 | * @returns {function} callback(err, result, request, response) 332 | * 333 | * {Error} err - The Error object if an error occurred, null otherwise. 334 | * 335 | * {object} [result] - The deserialized result object. 336 | * See {@link ImportModel} for more information. 337 | * 338 | * {object} [request] - The HTTP Request object if an error did not occur. 339 | * 340 | * {stream} [response] - The HTTP Response stream if an error did not occur. 341 | */ 342 | Imports.prototype.getImportById = function (collectionName, workspaceId, importId, options, callback) { 343 | var client = this.client; 344 | if(!callback && typeof options === 'function') { 345 | callback = options; 346 | options = null; 347 | } 348 | if (!callback) { 349 | throw new Error('callback cannot be null.'); 350 | } 351 | // Validate 352 | try { 353 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 354 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 355 | } 356 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 357 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 358 | } 359 | if (importId === null || importId === undefined || typeof importId.valueOf() !== 'string') { 360 | throw new Error('importId cannot be null or undefined and it must be of type string.'); 361 | } 362 | } catch (error) { 363 | return callback(error); 364 | } 365 | 366 | // Construct URL 367 | var requestUrl = this.client.baseUri + 368 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports/{importId}'; 369 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 370 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 371 | requestUrl = requestUrl.replace('{importId}', encodeURIComponent(importId)); 372 | // trim all duplicate forward slashes in the url 373 | var regex = /([^:]\/)\/+/gi; 374 | requestUrl = requestUrl.replace(regex, '$1'); 375 | 376 | // Create HTTP transport objects 377 | var httpRequest = new WebResource(); 378 | httpRequest.method = 'GET'; 379 | httpRequest.headers = {}; 380 | httpRequest.url = requestUrl; 381 | // Set Headers 382 | if(options) { 383 | for(var headerName in options['customHeaders']) { 384 | if (options['customHeaders'].hasOwnProperty(headerName)) { 385 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 386 | } 387 | } 388 | } 389 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 390 | httpRequest.body = null; 391 | // Send Request 392 | return client.pipeline(httpRequest, function (err, response, responseBody) { 393 | if (err) { 394 | return callback(err); 395 | } 396 | var statusCode = response.statusCode; 397 | if (statusCode !== 200) { 398 | var error = new Error(responseBody); 399 | error.statusCode = response.statusCode; 400 | error.request = msRest.stripRequest(httpRequest); 401 | error.response = msRest.stripResponse(response); 402 | if (responseBody === '') responseBody = null; 403 | var parsedErrorResponse; 404 | try { 405 | parsedErrorResponse = JSON.parse(responseBody); 406 | if (parsedErrorResponse) { 407 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 408 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 409 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 410 | } 411 | } catch (defaultError) { 412 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 413 | '- "%s" for the default response.', defaultError.message, responseBody); 414 | return callback(error); 415 | } 416 | return callback(error); 417 | } 418 | // Create Result 419 | var result = null; 420 | if (responseBody === '') responseBody = null; 421 | // Deserialize Response 422 | if (statusCode === 200) { 423 | var parsedResponse = null; 424 | try { 425 | parsedResponse = JSON.parse(responseBody); 426 | result = JSON.parse(responseBody); 427 | if (parsedResponse !== null && parsedResponse !== undefined) { 428 | var resultMapper = new client.models['ImportModel']().mapper(); 429 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 430 | } 431 | } catch (error) { 432 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 433 | deserializationError.request = msRest.stripRequest(httpRequest); 434 | deserializationError.response = msRest.stripResponse(response); 435 | return callback(deserializationError); 436 | } 437 | } 438 | 439 | return callback(null, result, httpRequest, response); 440 | }); 441 | }; 442 | 443 | 444 | module.exports = Imports; 445 | -------------------------------------------------------------------------------- /lib/autorest/operations/index.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | import { ServiceClientOptions, RequestOptions, ServiceCallback } from 'ms-rest'; 8 | import * as models from '../models'; 9 | 10 | 11 | /** 12 | * @class 13 | * Datasets 14 | * __NOTE__: An instance of this class is automatically created for an 15 | * instance of the PowerBIClient. 16 | */ 17 | export interface Datasets { 18 | 19 | /** 20 | * @summary Returns the datasets 21 | * 22 | * @param {string} collectionName The workspace collection name 23 | * 24 | * @param {string} workspaceId The workspace id 25 | * 26 | * @param {object} [options] Optional Parameters. 27 | * 28 | * @param {object} [options.customHeaders] Headers that will be added to the 29 | * request 30 | * 31 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 32 | * doc in ms-rest index.d.ts for details 33 | */ 34 | getDatasets(collectionName: string, workspaceId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 35 | getDatasets(collectionName: string, workspaceId: string, callback: ServiceCallback): void; 36 | 37 | /** 38 | * @summary Post a new entity to datasets 39 | * 40 | * @param {string} collectionName The workspace collection name 41 | * 42 | * @param {string} workspaceId The workspace id 43 | * 44 | * @param {object} dataset Create dataset parameters 45 | * 46 | * @param {string} [dataset.id] The dataset id 47 | * 48 | * @param {string} [dataset.name] The dataset name 49 | * 50 | * @param {string} [dataset.defaultRetentionPolicy] The dataset default data 51 | * retention policy 52 | * 53 | * @param {array} [dataset.tables] The dataset tables 54 | * 55 | * @param {string} [dataset.webUrl] The dataset web url 56 | * 57 | * @param {array} [dataset.datasources] The datasources associated with this 58 | * dataset 59 | * 60 | * @param {string} [dataset.defaultMode] The dataset mode or type. Possible 61 | * values include: 'AsAzure', 'AsOnPrem', 'Push', 'Streaming', 'PushStreaming' 62 | * 63 | * @param {object} [options] Optional Parameters. 64 | * 65 | * @param {object} [options.customHeaders] Headers that will be added to the 66 | * request 67 | * 68 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 69 | * doc in ms-rest index.d.ts for details 70 | */ 71 | postDataset(collectionName: string, workspaceId: string, dataset: models.Dataset, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 72 | postDataset(collectionName: string, workspaceId: string, dataset: models.Dataset, callback: ServiceCallback): void; 73 | 74 | /** 75 | * @summary Posts new data rows into the specified table 76 | * 77 | * @param {string} collectionName The workspace collection name 78 | * 79 | * @param {string} workspaceId The workspace id 80 | * 81 | * @param {string} datasetKey The dataset id 82 | * 83 | * @param {string} tableName The table name 84 | * 85 | * @param {object} requestMessage The request message 86 | * 87 | * @param {object} [options] Optional Parameters. 88 | * 89 | * @param {object} [options.customHeaders] Headers that will be added to the 90 | * request 91 | * 92 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 93 | * doc in ms-rest index.d.ts for details 94 | */ 95 | postRows(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, requestMessage: any, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 96 | postRows(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, requestMessage: any, callback: ServiceCallback): void; 97 | 98 | /** 99 | * @summary Deletes all rows from the specified table 100 | * 101 | * @param {string} collectionName The workspace collection name 102 | * 103 | * @param {string} workspaceId The workspace id 104 | * 105 | * @param {string} datasetKey The dataset id 106 | * 107 | * @param {string} tableName The table name 108 | * 109 | * @param {object} [options] Optional Parameters. 110 | * 111 | * @param {object} [options.customHeaders] Headers that will be added to the 112 | * request 113 | * 114 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 115 | * doc in ms-rest index.d.ts for details 116 | */ 117 | deleteRows(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 118 | deleteRows(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, callback: ServiceCallback): void; 119 | 120 | /** 121 | * @summary Gets all tables within the specified dataset 122 | * 123 | * @param {string} collectionName The workspace collection name 124 | * 125 | * @param {string} workspaceId The workspace id 126 | * 127 | * @param {string} datasetKey The dataset id 128 | * 129 | * @param {object} [options] Optional Parameters. 130 | * 131 | * @param {object} [options.customHeaders] Headers that will be added to the 132 | * request 133 | * 134 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 135 | * doc in ms-rest index.d.ts for details 136 | */ 137 | getTables(collectionName: string, workspaceId: string, datasetKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 138 | getTables(collectionName: string, workspaceId: string, datasetKey: string, callback: ServiceCallback): void; 139 | 140 | /** 141 | * @summary Updates a schema and metadata for the specified table 142 | * 143 | * @param {string} collectionName The workspace collection name 144 | * 145 | * @param {string} workspaceId The workspace id 146 | * 147 | * @param {string} datasetKey The dataset id 148 | * 149 | * @param {string} tableName The table name 150 | * 151 | * @param {object} requestMessage The request message 152 | * 153 | * @param {object} [options] Optional Parameters. 154 | * 155 | * @param {object} [options.customHeaders] Headers that will be added to the 156 | * request 157 | * 158 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 159 | * doc in ms-rest index.d.ts for details 160 | */ 161 | putTable(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, requestMessage: any, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 162 | putTable(collectionName: string, workspaceId: string, datasetKey: string, tableName: string, requestMessage: any, callback: ServiceCallback): void; 163 | 164 | /** 165 | * @summary Gets the dataset metadata for the specifeid dataset id 166 | * 167 | * @param {string} collectionName The workspace collection name 168 | * 169 | * @param {string} workspaceId The workspace id 170 | * 171 | * @param {string} datasetKey The dataset id 172 | * 173 | * @param {object} [options] Optional Parameters. 174 | * 175 | * @param {object} [options.customHeaders] Headers that will be added to the 176 | * request 177 | * 178 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 179 | * doc in ms-rest index.d.ts for details 180 | */ 181 | getDatasetById(collectionName: string, workspaceId: string, datasetKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 182 | getDatasetById(collectionName: string, workspaceId: string, datasetKey: string, callback: ServiceCallback): void; 183 | 184 | /** 185 | * @summary Deletes the dataset with the specified id 186 | * 187 | * @param {string} collectionName The workspace collection name 188 | * 189 | * @param {string} workspaceId The workspace id 190 | * 191 | * @param {string} datasetKey The dataset id 192 | * 193 | * @param {object} [options] Optional Parameters. 194 | * 195 | * @param {object} [options.customHeaders] Headers that will be added to the 196 | * request 197 | * 198 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 199 | * doc in ms-rest index.d.ts for details 200 | */ 201 | deleteDatasetById(collectionName: string, workspaceId: string, datasetKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 202 | deleteDatasetById(collectionName: string, workspaceId: string, datasetKey: string, callback: ServiceCallback): void; 203 | 204 | /** 205 | * @summary Gets a list of bound gateway datasources for the specified dataset 206 | * 207 | * @param {string} collectionName The workspace collection name 208 | * 209 | * @param {string} workspaceId The workspace id 210 | * 211 | * @param {string} datasetKey The dataset id 212 | * 213 | * @param {object} [options] Optional Parameters. 214 | * 215 | * @param {object} [options.customHeaders] Headers that will be added to the 216 | * request 217 | * 218 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 219 | * doc in ms-rest index.d.ts for details 220 | */ 221 | getGatewayDatasources(collectionName: string, workspaceId: string, datasetKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 222 | getGatewayDatasources(collectionName: string, workspaceId: string, datasetKey: string, callback: ServiceCallback): void; 223 | 224 | /** 225 | * @summary Gets a list of datasource for the specified dataset 226 | * 227 | * @param {string} collectionName The workspace collection name 228 | * 229 | * @param {string} workspaceId The workspace id 230 | * 231 | * @param {string} datasetKey 232 | * 233 | * @param {object} [options] Optional Parameters. 234 | * 235 | * @param {object} [options.customHeaders] Headers that will be added to the 236 | * request 237 | * 238 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 239 | * doc in ms-rest index.d.ts for details 240 | */ 241 | getDatasources(collectionName: string, workspaceId: string, datasetKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 242 | getDatasources(collectionName: string, workspaceId: string, datasetKey: string, callback: ServiceCallback): void; 243 | 244 | /** 245 | * @summary Sets all connections for the specified dataset 246 | * 247 | * @param {string} collectionName The workspace collection name 248 | * 249 | * @param {string} workspaceId The workspace id 250 | * 251 | * @param {string} datasetKey The dataset id 252 | * 253 | * @param {object} parameters The body 254 | * 255 | * @param {object} [options] Optional Parameters. 256 | * 257 | * @param {object} [options.customHeaders] Headers that will be added to the 258 | * request 259 | * 260 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 261 | * doc in ms-rest index.d.ts for details 262 | */ 263 | setAllConnections(collectionName: string, workspaceId: string, datasetKey: string, parameters: { [propertyName: string]: string }, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 264 | setAllConnections(collectionName: string, workspaceId: string, datasetKey: string, parameters: { [propertyName: string]: string }, callback: ServiceCallback): void; 265 | } 266 | 267 | /** 268 | * @class 269 | * Gateways 270 | * __NOTE__: An instance of this class is automatically created for an 271 | * instance of the PowerBIClient. 272 | */ 273 | export interface Gateways { 274 | 275 | /** 276 | * @summary Updates the credentials for the specified datasource 277 | * 278 | * @param {string} collectionName The workspace collection name 279 | * 280 | * @param {string} workspaceId The workspace id 281 | * 282 | * @param {string} gatewayId The gateway id 283 | * 284 | * @param {string} datasourceId The datasource id 285 | * 286 | * @param {object} datasourceDelta The datasource changes 287 | * 288 | * @param {object} [options] Optional Parameters. 289 | * 290 | * @param {object} [options.customHeaders] Headers that will be added to the 291 | * request 292 | * 293 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 294 | * doc in ms-rest index.d.ts for details 295 | */ 296 | patchDatasource(collectionName: string, workspaceId: string, gatewayId: string, datasourceId: string, datasourceDelta: any, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 297 | patchDatasource(collectionName: string, workspaceId: string, gatewayId: string, datasourceId: string, datasourceDelta: any, callback: ServiceCallback): void; 298 | } 299 | 300 | /** 301 | * @class 302 | * Imports 303 | * __NOTE__: An instance of this class is automatically created for an 304 | * instance of the PowerBIClient. 305 | */ 306 | export interface Imports { 307 | 308 | /** 309 | * @summary Returns a list of imports for the specified workspace 310 | * 311 | * @param {string} collectionName The workspace collection name 312 | * 313 | * @param {string} workspaceId The workspace id 314 | * 315 | * @param {object} [options] Optional Parameters. 316 | * 317 | * @param {object} [options.customHeaders] Headers that will be added to the 318 | * request 319 | * 320 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 321 | * doc in ms-rest index.d.ts for details 322 | */ 323 | getImports(collectionName: string, workspaceId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 324 | getImports(collectionName: string, workspaceId: string, callback: ServiceCallback): void; 325 | 326 | /** 327 | * @summary Creates a new import using the specified import info 328 | * 329 | * @param {string} collectionName The workspace collection name 330 | * 331 | * @param {string} workspaceId The workspace id 332 | * 333 | * @param {string} datasetDisplayName The display name of the dataset 334 | * 335 | * @param {object} importInfo The import to post 336 | * 337 | * @param {string} [importInfo.filePath] The file path to import 338 | * 339 | * @param {string} [importInfo.connectionType] The import connection type 340 | * 341 | * @param {object} [options] Optional Parameters. 342 | * 343 | * @param {string} [options.nameConflict] Determines what to do if a dataset 344 | * with the same name already exists 345 | * 346 | * @param {object} [options.customHeaders] Headers that will be added to the 347 | * request 348 | * 349 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 350 | * doc in ms-rest index.d.ts for details 351 | */ 352 | postImport(collectionName: string, workspaceId: string, datasetDisplayName: string, importInfo: models.ImportInfo, options: { nameConflict? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 353 | postImport(collectionName: string, workspaceId: string, datasetDisplayName: string, importInfo: models.ImportInfo, callback: ServiceCallback): void; 354 | 355 | /** 356 | * @summary Gets the import metadata for the specifed import id 357 | * 358 | * @param {string} collectionName The workspace collection name 359 | * 360 | * @param {string} workspaceId The workspace id 361 | * 362 | * @param {string} importId The import id 363 | * 364 | * @param {object} [options] Optional Parameters. 365 | * 366 | * @param {object} [options.customHeaders] Headers that will be added to the 367 | * request 368 | * 369 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 370 | * doc in ms-rest index.d.ts for details 371 | */ 372 | getImportById(collectionName: string, workspaceId: string, importId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 373 | getImportById(collectionName: string, workspaceId: string, importId: string, callback: ServiceCallback): void; 374 | } 375 | 376 | /** 377 | * @class 378 | * Workspaces 379 | * __NOTE__: An instance of this class is automatically created for an 380 | * instance of the PowerBIClient. 381 | */ 382 | export interface Workspaces { 383 | 384 | /** 385 | * @summary Returns a list of workspaces for the specified collection 386 | * 387 | * @param {string} collectionName The workspace collection name 388 | * 389 | * @param {object} [options] Optional Parameters. 390 | * 391 | * @param {object} [options.customHeaders] Headers that will be added to the 392 | * request 393 | * 394 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 395 | * doc in ms-rest index.d.ts for details 396 | */ 397 | getWorkspacesByCollectionName(collectionName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 398 | getWorkspacesByCollectionName(collectionName: string, callback: ServiceCallback): void; 399 | 400 | /** 401 | * @summary Creates a new workspace within a workspace collection 402 | * 403 | * @param {string} collectionName The workspace collection name 404 | * 405 | * @param {object} [options] Optional Parameters. 406 | * 407 | * @param {object} [options.workspaceRequest] The workspace requested to create 408 | * 409 | * @param {string} [options.workspaceRequest.name] The workspace name 410 | * 411 | * @param {object} [options.customHeaders] Headers that will be added to the 412 | * request 413 | * 414 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 415 | * doc in ms-rest index.d.ts for details 416 | */ 417 | postWorkspace(collectionName: string, options: { workspaceRequest? : models.CreateWorkspaceRequest, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 418 | postWorkspace(collectionName: string, callback: ServiceCallback): void; 419 | } 420 | 421 | /** 422 | * @class 423 | * Reports 424 | * __NOTE__: An instance of this class is automatically created for an 425 | * instance of the PowerBIClient. 426 | */ 427 | export interface Reports { 428 | 429 | /** 430 | * @summary Gets a list of reports available within the specified workspace 431 | * 432 | * @param {string} collectionName The workspace collection name 433 | * 434 | * @param {string} workspaceId The workspace id 435 | * 436 | * @param {object} [options] Optional Parameters. 437 | * 438 | * @param {object} [options.customHeaders] Headers that will be added to the 439 | * request 440 | * 441 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 442 | * doc in ms-rest index.d.ts for details 443 | */ 444 | getReports(collectionName: string, workspaceId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 445 | getReports(collectionName: string, workspaceId: string, callback: ServiceCallback): void; 446 | 447 | /** 448 | * @summary Clones the specified report 449 | * 450 | * @param {string} collectionName The workspace collection name 451 | * 452 | * @param {string} workspaceId The workspace id 453 | * 454 | * @param {string} reportKey The report id 455 | * 456 | * @param {object} requestParameters Clone report parameters 457 | * 458 | * @param {string} [requestParameters.name] The requested report name 459 | * 460 | * @param {string} [requestParameters.targetWorkspaceId] Optional parameter 461 | * for specifying the target workspace id 462 | * 463 | * @param {string} [requestParameters.targetModelId] Optional parameter for 464 | * specifying the target associated model (dataset) id 465 | * 466 | * @param {object} [options] Optional Parameters. 467 | * 468 | * @param {object} [options.customHeaders] Headers that will be added to the 469 | * request 470 | * 471 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 472 | * doc in ms-rest index.d.ts for details 473 | */ 474 | cloneReport(collectionName: string, workspaceId: string, reportKey: string, requestParameters: models.CloneReportRequest, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 475 | cloneReport(collectionName: string, workspaceId: string, reportKey: string, requestParameters: models.CloneReportRequest, callback: ServiceCallback): void; 476 | 477 | /** 478 | * @summary Deletes the specified report 479 | * 480 | * @param {string} collectionName The workspace collection name 481 | * 482 | * @param {string} workspaceId The workspace id 483 | * 484 | * @param {string} reportKey The report id 485 | * 486 | * @param {object} [options] Optional Parameters. 487 | * 488 | * @param {object} [options.customHeaders] Headers that will be added to the 489 | * request 490 | * 491 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 492 | * doc in ms-rest index.d.ts for details 493 | */ 494 | deleteReport(collectionName: string, workspaceId: string, reportKey: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 495 | deleteReport(collectionName: string, workspaceId: string, reportKey: string, callback: ServiceCallback): void; 496 | 497 | /** 498 | * @summary Rebinds the specified report to requested dataset id 499 | * 500 | * @param {string} collectionName The workspace collection name 501 | * 502 | * @param {string} workspaceId The workspace id 503 | * 504 | * @param {string} reportKey The report id 505 | * 506 | * @param {object} requestParameters Rebind report parameters 507 | * 508 | * @param {string} [requestParameters.datasetId] The new dataset of the 509 | * rebinded report 510 | * 511 | * @param {object} [options] Optional Parameters. 512 | * 513 | * @param {object} [options.customHeaders] Headers that will be added to the 514 | * request 515 | * 516 | * @param {ServiceCallback} [callback] callback function; see ServiceCallback 517 | * doc in ms-rest index.d.ts for details 518 | */ 519 | rebindReport(collectionName: string, workspaceId: string, reportKey: string, requestParameters: models.RebindReportRequest, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; 520 | rebindReport(collectionName: string, workspaceId: string, reportKey: string, requestParameters: models.RebindReportRequest, callback: ServiceCallback): void; 521 | } 522 | -------------------------------------------------------------------------------- /lib/autorest/operations/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | /* jshint latedef:false */ 8 | /* jshint forin:false */ 9 | /* jshint noempty:false */ 10 | 11 | 'use strict'; 12 | 13 | exports.Datasets = require('./datasets'); 14 | exports.Gateways = require('./gateways'); 15 | exports.Imports = require('./imports'); 16 | exports.Workspaces = require('./workspaces'); 17 | exports.Reports = require('./reports'); 18 | -------------------------------------------------------------------------------- /lib/autorest/operations/reports.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var util = require('util'); 10 | var msRest = require('ms-rest'); 11 | var WebResource = msRest.WebResource; 12 | 13 | /** 14 | * @class 15 | * Reports 16 | * __NOTE__: An instance of this class is automatically created for an 17 | * instance of the PowerBIClient. 18 | * Initializes a new instance of the Reports class. 19 | * @constructor 20 | * 21 | * @param {PowerBIClient} client Reference to the service client. 22 | */ 23 | function Reports(client) { 24 | this.client = client; 25 | } 26 | 27 | /** 28 | * @summary Gets a list of reports available within the specified workspace 29 | * 30 | * @param {string} collectionName The workspace collection name 31 | * 32 | * @param {string} workspaceId The workspace id 33 | * 34 | * @param {object} [options] Optional Parameters. 35 | * 36 | * @param {object} [options.customHeaders] Headers that will be added to the 37 | * request 38 | * 39 | * @param {function} callback 40 | * 41 | * @returns {function} callback(err, result, request, response) 42 | * 43 | * {Error} err - The Error object if an error occurred, null otherwise. 44 | * 45 | * {object} [result] - The deserialized result object. 46 | * See {@link ODataResponseListReport} for more 47 | * information. 48 | * 49 | * {object} [request] - The HTTP Request object if an error did not occur. 50 | * 51 | * {stream} [response] - The HTTP Response stream if an error did not occur. 52 | */ 53 | Reports.prototype.getReports = function (collectionName, workspaceId, options, callback) { 54 | var client = this.client; 55 | if(!callback && typeof options === 'function') { 56 | callback = options; 57 | options = null; 58 | } 59 | if (!callback) { 60 | throw new Error('callback cannot be null.'); 61 | } 62 | // Validate 63 | try { 64 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 65 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 66 | } 67 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 68 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 69 | } 70 | } catch (error) { 71 | return callback(error); 72 | } 73 | 74 | // Construct URL 75 | var requestUrl = this.client.baseUri + 76 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/reports'; 77 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 78 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 79 | // trim all duplicate forward slashes in the url 80 | var regex = /([^:]\/)\/+/gi; 81 | requestUrl = requestUrl.replace(regex, '$1'); 82 | 83 | // Create HTTP transport objects 84 | var httpRequest = new WebResource(); 85 | httpRequest.method = 'GET'; 86 | httpRequest.headers = {}; 87 | httpRequest.url = requestUrl; 88 | // Set Headers 89 | if(options) { 90 | for(var headerName in options['customHeaders']) { 91 | if (options['customHeaders'].hasOwnProperty(headerName)) { 92 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 93 | } 94 | } 95 | } 96 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 97 | httpRequest.body = null; 98 | // Send Request 99 | return client.pipeline(httpRequest, function (err, response, responseBody) { 100 | if (err) { 101 | return callback(err); 102 | } 103 | var statusCode = response.statusCode; 104 | if (statusCode !== 200) { 105 | var error = new Error(responseBody); 106 | error.statusCode = response.statusCode; 107 | error.request = msRest.stripRequest(httpRequest); 108 | error.response = msRest.stripResponse(response); 109 | if (responseBody === '') responseBody = null; 110 | var parsedErrorResponse; 111 | try { 112 | parsedErrorResponse = JSON.parse(responseBody); 113 | if (parsedErrorResponse) { 114 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 115 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 116 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 117 | } 118 | } catch (defaultError) { 119 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 120 | '- "%s" for the default response.', defaultError.message, responseBody); 121 | return callback(error); 122 | } 123 | return callback(error); 124 | } 125 | // Create Result 126 | var result = null; 127 | if (responseBody === '') responseBody = null; 128 | // Deserialize Response 129 | if (statusCode === 200) { 130 | var parsedResponse = null; 131 | try { 132 | parsedResponse = JSON.parse(responseBody); 133 | result = JSON.parse(responseBody); 134 | if (parsedResponse !== null && parsedResponse !== undefined) { 135 | var resultMapper = new client.models['ODataResponseListReport']().mapper(); 136 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 137 | } 138 | } catch (error) { 139 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 140 | deserializationError.request = msRest.stripRequest(httpRequest); 141 | deserializationError.response = msRest.stripResponse(response); 142 | return callback(deserializationError); 143 | } 144 | } 145 | 146 | return callback(null, result, httpRequest, response); 147 | }); 148 | }; 149 | 150 | /** 151 | * @summary Clones the specified report 152 | * 153 | * @param {string} collectionName The workspace collection name 154 | * 155 | * @param {string} workspaceId The workspace id 156 | * 157 | * @param {string} reportKey The report id 158 | * 159 | * @param {object} requestParameters Clone report parameters 160 | * 161 | * @param {string} [requestParameters.name] The requested report name 162 | * 163 | * @param {string} [requestParameters.targetWorkspaceId] Optional parameter 164 | * for specifying the target workspace id 165 | * 166 | * @param {string} [requestParameters.targetModelId] Optional parameter for 167 | * specifying the target associated model (dataset) id 168 | * 169 | * @param {object} [options] Optional Parameters. 170 | * 171 | * @param {object} [options.customHeaders] Headers that will be added to the 172 | * request 173 | * 174 | * @param {function} callback 175 | * 176 | * @returns {function} callback(err, result, request, response) 177 | * 178 | * {Error} err - The Error object if an error occurred, null otherwise. 179 | * 180 | * {object} [result] - The deserialized result object. 181 | * See {@link Report} for more information. 182 | * 183 | * {object} [request] - The HTTP Request object if an error did not occur. 184 | * 185 | * {stream} [response] - The HTTP Response stream if an error did not occur. 186 | */ 187 | Reports.prototype.cloneReport = function (collectionName, workspaceId, reportKey, requestParameters, options, callback) { 188 | var client = this.client; 189 | if(!callback && typeof options === 'function') { 190 | callback = options; 191 | options = null; 192 | } 193 | if (!callback) { 194 | throw new Error('callback cannot be null.'); 195 | } 196 | // Validate 197 | try { 198 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 199 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 200 | } 201 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 202 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 203 | } 204 | if (reportKey === null || reportKey === undefined || typeof reportKey.valueOf() !== 'string') { 205 | throw new Error('reportKey cannot be null or undefined and it must be of type string.'); 206 | } 207 | if (requestParameters === null || requestParameters === undefined) { 208 | throw new Error('requestParameters cannot be null or undefined.'); 209 | } 210 | } catch (error) { 211 | return callback(error); 212 | } 213 | 214 | // Construct URL 215 | var requestUrl = this.client.baseUri + 216 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/reports/{reportKey}/Clone'; 217 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 218 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 219 | requestUrl = requestUrl.replace('{reportKey}', encodeURIComponent(reportKey)); 220 | // trim all duplicate forward slashes in the url 221 | var regex = /([^:]\/)\/+/gi; 222 | requestUrl = requestUrl.replace(regex, '$1'); 223 | 224 | // Create HTTP transport objects 225 | var httpRequest = new WebResource(); 226 | httpRequest.method = 'POST'; 227 | httpRequest.headers = {}; 228 | httpRequest.url = requestUrl; 229 | // Set Headers 230 | if(options) { 231 | for(var headerName in options['customHeaders']) { 232 | if (options['customHeaders'].hasOwnProperty(headerName)) { 233 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 234 | } 235 | } 236 | } 237 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 238 | // Serialize Request 239 | var requestContent = null; 240 | var requestModel = null; 241 | try { 242 | if (requestParameters !== null && requestParameters !== undefined) { 243 | var requestModelMapper = new client.models['CloneReportRequest']().mapper(); 244 | requestModel = client.serialize(requestModelMapper, requestParameters, 'requestParameters'); 245 | requestContent = JSON.stringify(requestModel); 246 | } 247 | } catch (error) { 248 | var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 249 | 'payload - "%s"', error.message, util.inspect(requestParameters, {depth: null}))); 250 | return callback(serializationError); 251 | } 252 | httpRequest.body = requestContent; 253 | // Send Request 254 | return client.pipeline(httpRequest, function (err, response, responseBody) { 255 | if (err) { 256 | return callback(err); 257 | } 258 | var statusCode = response.statusCode; 259 | if (statusCode !== 200) { 260 | var error = new Error(responseBody); 261 | error.statusCode = response.statusCode; 262 | error.request = msRest.stripRequest(httpRequest); 263 | error.response = msRest.stripResponse(response); 264 | if (responseBody === '') responseBody = null; 265 | var parsedErrorResponse; 266 | try { 267 | parsedErrorResponse = JSON.parse(responseBody); 268 | if (parsedErrorResponse) { 269 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 270 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 271 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 272 | } 273 | } catch (defaultError) { 274 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 275 | '- "%s" for the default response.', defaultError.message, responseBody); 276 | return callback(error); 277 | } 278 | return callback(error); 279 | } 280 | // Create Result 281 | var result = null; 282 | if (responseBody === '') responseBody = null; 283 | // Deserialize Response 284 | if (statusCode === 200) { 285 | var parsedResponse = null; 286 | try { 287 | parsedResponse = JSON.parse(responseBody); 288 | result = JSON.parse(responseBody); 289 | if (parsedResponse !== null && parsedResponse !== undefined) { 290 | var resultMapper = new client.models['Report']().mapper(); 291 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 292 | } 293 | } catch (error) { 294 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 295 | deserializationError.request = msRest.stripRequest(httpRequest); 296 | deserializationError.response = msRest.stripResponse(response); 297 | return callback(deserializationError); 298 | } 299 | } 300 | 301 | return callback(null, result, httpRequest, response); 302 | }); 303 | }; 304 | 305 | /** 306 | * @summary Deletes the specified report 307 | * 308 | * @param {string} collectionName The workspace collection name 309 | * 310 | * @param {string} workspaceId The workspace id 311 | * 312 | * @param {string} reportKey The report id 313 | * 314 | * @param {object} [options] Optional Parameters. 315 | * 316 | * @param {object} [options.customHeaders] Headers that will be added to the 317 | * request 318 | * 319 | * @param {function} callback 320 | * 321 | * @returns {function} callback(err, result, request, response) 322 | * 323 | * {Error} err - The Error object if an error occurred, null otherwise. 324 | * 325 | * {object} [result] - The deserialized result object. 326 | * 327 | * {object} [request] - The HTTP Request object if an error did not occur. 328 | * 329 | * {stream} [response] - The HTTP Response stream if an error did not occur. 330 | */ 331 | Reports.prototype.deleteReport = function (collectionName, workspaceId, reportKey, options, callback) { 332 | var client = this.client; 333 | if(!callback && typeof options === 'function') { 334 | callback = options; 335 | options = null; 336 | } 337 | if (!callback) { 338 | throw new Error('callback cannot be null.'); 339 | } 340 | // Validate 341 | try { 342 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 343 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 344 | } 345 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 346 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 347 | } 348 | if (reportKey === null || reportKey === undefined || typeof reportKey.valueOf() !== 'string') { 349 | throw new Error('reportKey cannot be null or undefined and it must be of type string.'); 350 | } 351 | } catch (error) { 352 | return callback(error); 353 | } 354 | 355 | // Construct URL 356 | var requestUrl = this.client.baseUri + 357 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/reports/{reportKey}'; 358 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 359 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 360 | requestUrl = requestUrl.replace('{reportKey}', encodeURIComponent(reportKey)); 361 | // trim all duplicate forward slashes in the url 362 | var regex = /([^:]\/)\/+/gi; 363 | requestUrl = requestUrl.replace(regex, '$1'); 364 | 365 | // Create HTTP transport objects 366 | var httpRequest = new WebResource(); 367 | httpRequest.method = 'DELETE'; 368 | httpRequest.headers = {}; 369 | httpRequest.url = requestUrl; 370 | // Set Headers 371 | if(options) { 372 | for(var headerName in options['customHeaders']) { 373 | if (options['customHeaders'].hasOwnProperty(headerName)) { 374 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 375 | } 376 | } 377 | } 378 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 379 | httpRequest.body = null; 380 | // Send Request 381 | return client.pipeline(httpRequest, function (err, response, responseBody) { 382 | if (err) { 383 | return callback(err); 384 | } 385 | var statusCode = response.statusCode; 386 | if (statusCode !== 200) { 387 | var error = new Error(responseBody); 388 | error.statusCode = response.statusCode; 389 | error.request = msRest.stripRequest(httpRequest); 390 | error.response = msRest.stripResponse(response); 391 | if (responseBody === '') responseBody = null; 392 | var parsedErrorResponse; 393 | try { 394 | parsedErrorResponse = JSON.parse(responseBody); 395 | if (parsedErrorResponse) { 396 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 397 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 398 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 399 | } 400 | } catch (defaultError) { 401 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 402 | '- "%s" for the default response.', defaultError.message, responseBody); 403 | return callback(error); 404 | } 405 | return callback(error); 406 | } 407 | // Create Result 408 | var result = null; 409 | if (responseBody === '') responseBody = null; 410 | // Deserialize Response 411 | if (statusCode === 200) { 412 | var parsedResponse = null; 413 | try { 414 | parsedResponse = JSON.parse(responseBody); 415 | result = JSON.parse(responseBody); 416 | if (parsedResponse !== null && parsedResponse !== undefined) { 417 | var resultMapper = { 418 | required: false, 419 | serializedName: 'parsedResponse', 420 | type: { 421 | name: 'Object' 422 | } 423 | }; 424 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 425 | } 426 | } catch (error) { 427 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 428 | deserializationError.request = msRest.stripRequest(httpRequest); 429 | deserializationError.response = msRest.stripResponse(response); 430 | return callback(deserializationError); 431 | } 432 | } 433 | 434 | return callback(null, result, httpRequest, response); 435 | }); 436 | }; 437 | 438 | /** 439 | * @summary Rebinds the specified report to requested dataset id 440 | * 441 | * @param {string} collectionName The workspace collection name 442 | * 443 | * @param {string} workspaceId The workspace id 444 | * 445 | * @param {string} reportKey The report id 446 | * 447 | * @param {object} requestParameters Rebind report parameters 448 | * 449 | * @param {string} [requestParameters.datasetId] The new dataset of the 450 | * rebinded report 451 | * 452 | * @param {object} [options] Optional Parameters. 453 | * 454 | * @param {object} [options.customHeaders] Headers that will be added to the 455 | * request 456 | * 457 | * @param {function} callback 458 | * 459 | * @returns {function} callback(err, result, request, response) 460 | * 461 | * {Error} err - The Error object if an error occurred, null otherwise. 462 | * 463 | * {object} [result] - The deserialized result object. 464 | * 465 | * {object} [request] - The HTTP Request object if an error did not occur. 466 | * 467 | * {stream} [response] - The HTTP Response stream if an error did not occur. 468 | */ 469 | Reports.prototype.rebindReport = function (collectionName, workspaceId, reportKey, requestParameters, options, callback) { 470 | var client = this.client; 471 | if(!callback && typeof options === 'function') { 472 | callback = options; 473 | options = null; 474 | } 475 | if (!callback) { 476 | throw new Error('callback cannot be null.'); 477 | } 478 | // Validate 479 | try { 480 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 481 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 482 | } 483 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 484 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 485 | } 486 | if (reportKey === null || reportKey === undefined || typeof reportKey.valueOf() !== 'string') { 487 | throw new Error('reportKey cannot be null or undefined and it must be of type string.'); 488 | } 489 | if (requestParameters === null || requestParameters === undefined) { 490 | throw new Error('requestParameters cannot be null or undefined.'); 491 | } 492 | } catch (error) { 493 | return callback(error); 494 | } 495 | 496 | // Construct URL 497 | var requestUrl = this.client.baseUri + 498 | '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/reports/{reportKey}/Rebind'; 499 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 500 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 501 | requestUrl = requestUrl.replace('{reportKey}', encodeURIComponent(reportKey)); 502 | // trim all duplicate forward slashes in the url 503 | var regex = /([^:]\/)\/+/gi; 504 | requestUrl = requestUrl.replace(regex, '$1'); 505 | 506 | // Create HTTP transport objects 507 | var httpRequest = new WebResource(); 508 | httpRequest.method = 'POST'; 509 | httpRequest.headers = {}; 510 | httpRequest.url = requestUrl; 511 | // Set Headers 512 | if(options) { 513 | for(var headerName in options['customHeaders']) { 514 | if (options['customHeaders'].hasOwnProperty(headerName)) { 515 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 516 | } 517 | } 518 | } 519 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 520 | // Serialize Request 521 | var requestContent = null; 522 | var requestModel = null; 523 | try { 524 | if (requestParameters !== null && requestParameters !== undefined) { 525 | var requestModelMapper = new client.models['RebindReportRequest']().mapper(); 526 | requestModel = client.serialize(requestModelMapper, requestParameters, 'requestParameters'); 527 | requestContent = JSON.stringify(requestModel); 528 | } 529 | } catch (error) { 530 | var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 531 | 'payload - "%s"', error.message, util.inspect(requestParameters, {depth: null}))); 532 | return callback(serializationError); 533 | } 534 | httpRequest.body = requestContent; 535 | // Send Request 536 | return client.pipeline(httpRequest, function (err, response, responseBody) { 537 | if (err) { 538 | return callback(err); 539 | } 540 | var statusCode = response.statusCode; 541 | if (statusCode !== 200) { 542 | var error = new Error(responseBody); 543 | error.statusCode = response.statusCode; 544 | error.request = msRest.stripRequest(httpRequest); 545 | error.response = msRest.stripResponse(response); 546 | if (responseBody === '') responseBody = null; 547 | var parsedErrorResponse; 548 | try { 549 | parsedErrorResponse = JSON.parse(responseBody); 550 | if (parsedErrorResponse) { 551 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 552 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 553 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 554 | } 555 | } catch (defaultError) { 556 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 557 | '- "%s" for the default response.', defaultError.message, responseBody); 558 | return callback(error); 559 | } 560 | return callback(error); 561 | } 562 | // Create Result 563 | var result = null; 564 | if (responseBody === '') responseBody = null; 565 | // Deserialize Response 566 | if (statusCode === 200) { 567 | var parsedResponse = null; 568 | try { 569 | parsedResponse = JSON.parse(responseBody); 570 | result = JSON.parse(responseBody); 571 | if (parsedResponse !== null && parsedResponse !== undefined) { 572 | var resultMapper = { 573 | required: false, 574 | serializedName: 'parsedResponse', 575 | type: { 576 | name: 'Object' 577 | } 578 | }; 579 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 580 | } 581 | } catch (error) { 582 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 583 | deserializationError.request = msRest.stripRequest(httpRequest); 584 | deserializationError.response = msRest.stripResponse(response); 585 | return callback(deserializationError); 586 | } 587 | } 588 | 589 | return callback(null, result, httpRequest, response); 590 | }); 591 | }; 592 | 593 | 594 | module.exports = Reports; 595 | -------------------------------------------------------------------------------- /lib/autorest/operations/workspaces.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | 'use strict'; 8 | 9 | var util = require('util'); 10 | var msRest = require('ms-rest'); 11 | var WebResource = msRest.WebResource; 12 | 13 | /** 14 | * @class 15 | * Workspaces 16 | * __NOTE__: An instance of this class is automatically created for an 17 | * instance of the PowerBIClient. 18 | * Initializes a new instance of the Workspaces class. 19 | * @constructor 20 | * 21 | * @param {PowerBIClient} client Reference to the service client. 22 | */ 23 | function Workspaces(client) { 24 | this.client = client; 25 | } 26 | 27 | /** 28 | * @summary Returns a list of workspaces for the specified collection 29 | * 30 | * @param {string} collectionName The workspace collection name 31 | * 32 | * @param {object} [options] Optional Parameters. 33 | * 34 | * @param {object} [options.customHeaders] Headers that will be added to the 35 | * request 36 | * 37 | * @param {function} callback 38 | * 39 | * @returns {function} callback(err, result, request, response) 40 | * 41 | * {Error} err - The Error object if an error occurred, null otherwise. 42 | * 43 | * {object} [result] - The deserialized result object. 44 | * See {@link ODataResponseListWorkspace} for more 45 | * information. 46 | * 47 | * {object} [request] - The HTTP Request object if an error did not occur. 48 | * 49 | * {stream} [response] - The HTTP Response stream if an error did not occur. 50 | */ 51 | Workspaces.prototype.getWorkspacesByCollectionName = function (collectionName, options, callback) { 52 | var client = this.client; 53 | if(!callback && typeof options === 'function') { 54 | callback = options; 55 | options = null; 56 | } 57 | if (!callback) { 58 | throw new Error('callback cannot be null.'); 59 | } 60 | // Validate 61 | try { 62 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 63 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 64 | } 65 | } catch (error) { 66 | return callback(error); 67 | } 68 | 69 | // Construct URL 70 | var requestUrl = this.client.baseUri + 71 | '//v1.0/collections/{collectionName}/workspaces'; 72 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 73 | // trim all duplicate forward slashes in the url 74 | var regex = /([^:]\/)\/+/gi; 75 | requestUrl = requestUrl.replace(regex, '$1'); 76 | 77 | // Create HTTP transport objects 78 | var httpRequest = new WebResource(); 79 | httpRequest.method = 'GET'; 80 | httpRequest.headers = {}; 81 | httpRequest.url = requestUrl; 82 | // Set Headers 83 | if(options) { 84 | for(var headerName in options['customHeaders']) { 85 | if (options['customHeaders'].hasOwnProperty(headerName)) { 86 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 87 | } 88 | } 89 | } 90 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 91 | httpRequest.body = null; 92 | // Send Request 93 | return client.pipeline(httpRequest, function (err, response, responseBody) { 94 | if (err) { 95 | return callback(err); 96 | } 97 | var statusCode = response.statusCode; 98 | if (statusCode !== 200) { 99 | var error = new Error(responseBody); 100 | error.statusCode = response.statusCode; 101 | error.request = msRest.stripRequest(httpRequest); 102 | error.response = msRest.stripResponse(response); 103 | if (responseBody === '') responseBody = null; 104 | var parsedErrorResponse; 105 | try { 106 | parsedErrorResponse = JSON.parse(responseBody); 107 | if (parsedErrorResponse) { 108 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 109 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 110 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 111 | } 112 | } catch (defaultError) { 113 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 114 | '- "%s" for the default response.', defaultError.message, responseBody); 115 | return callback(error); 116 | } 117 | return callback(error); 118 | } 119 | // Create Result 120 | var result = null; 121 | if (responseBody === '') responseBody = null; 122 | // Deserialize Response 123 | if (statusCode === 200) { 124 | var parsedResponse = null; 125 | try { 126 | parsedResponse = JSON.parse(responseBody); 127 | result = JSON.parse(responseBody); 128 | if (parsedResponse !== null && parsedResponse !== undefined) { 129 | var resultMapper = new client.models['ODataResponseListWorkspace']().mapper(); 130 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 131 | } 132 | } catch (error) { 133 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 134 | deserializationError.request = msRest.stripRequest(httpRequest); 135 | deserializationError.response = msRest.stripResponse(response); 136 | return callback(deserializationError); 137 | } 138 | } 139 | 140 | return callback(null, result, httpRequest, response); 141 | }); 142 | }; 143 | 144 | /** 145 | * @summary Creates a new workspace within a workspace collection 146 | * 147 | * @param {string} collectionName The workspace collection name 148 | * 149 | * @param {object} [options] Optional Parameters. 150 | * 151 | * @param {object} [options.workspaceRequest] The workspace requested to create 152 | * 153 | * @param {string} [options.workspaceRequest.name] The workspace name 154 | * 155 | * @param {object} [options.customHeaders] Headers that will be added to the 156 | * request 157 | * 158 | * @param {function} callback 159 | * 160 | * @returns {function} callback(err, result, request, response) 161 | * 162 | * {Error} err - The Error object if an error occurred, null otherwise. 163 | * 164 | * {object} [result] - The deserialized result object. 165 | * See {@link Workspace} for more information. 166 | * 167 | * {object} [request] - The HTTP Request object if an error did not occur. 168 | * 169 | * {stream} [response] - The HTTP Response stream if an error did not occur. 170 | */ 171 | Workspaces.prototype.postWorkspace = function (collectionName, options, callback) { 172 | var client = this.client; 173 | if(!callback && typeof options === 'function') { 174 | callback = options; 175 | options = null; 176 | } 177 | if (!callback) { 178 | throw new Error('callback cannot be null.'); 179 | } 180 | var workspaceRequest = (options && options.workspaceRequest !== undefined) ? options.workspaceRequest : undefined; 181 | // Validate 182 | try { 183 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 184 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 185 | } 186 | } catch (error) { 187 | return callback(error); 188 | } 189 | 190 | // Construct URL 191 | var requestUrl = this.client.baseUri + 192 | '//v1.0/collections/{collectionName}/workspaces'; 193 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 194 | // trim all duplicate forward slashes in the url 195 | var regex = /([^:]\/)\/+/gi; 196 | requestUrl = requestUrl.replace(regex, '$1'); 197 | 198 | // Create HTTP transport objects 199 | var httpRequest = new WebResource(); 200 | httpRequest.method = 'POST'; 201 | httpRequest.headers = {}; 202 | httpRequest.url = requestUrl; 203 | // Set Headers 204 | if(options) { 205 | for(var headerName in options['customHeaders']) { 206 | if (options['customHeaders'].hasOwnProperty(headerName)) { 207 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; 208 | } 209 | } 210 | } 211 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; 212 | // Serialize Request 213 | var requestContent = null; 214 | var requestModel = null; 215 | try { 216 | if (workspaceRequest !== null && workspaceRequest !== undefined) { 217 | var requestModelMapper = new client.models['CreateWorkspaceRequest']().mapper(); 218 | requestModel = client.serialize(requestModelMapper, workspaceRequest, 'workspaceRequest'); 219 | requestContent = JSON.stringify(requestModel); 220 | } 221 | } catch (error) { 222 | var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 223 | 'payload - "%s"', error.message, util.inspect(workspaceRequest, {depth: null}))); 224 | return callback(serializationError); 225 | } 226 | httpRequest.body = requestContent; 227 | // Send Request 228 | return client.pipeline(httpRequest, function (err, response, responseBody) { 229 | if (err) { 230 | return callback(err); 231 | } 232 | var statusCode = response.statusCode; 233 | if (statusCode !== 201) { 234 | var error = new Error(responseBody); 235 | error.statusCode = response.statusCode; 236 | error.request = msRest.stripRequest(httpRequest); 237 | error.response = msRest.stripResponse(response); 238 | if (responseBody === '') responseBody = null; 239 | var parsedErrorResponse; 240 | try { 241 | parsedErrorResponse = JSON.parse(responseBody); 242 | if (parsedErrorResponse) { 243 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 244 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 245 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 246 | } 247 | } catch (defaultError) { 248 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 249 | '- "%s" for the default response.', defaultError.message, responseBody); 250 | return callback(error); 251 | } 252 | return callback(error); 253 | } 254 | // Create Result 255 | var result = null; 256 | if (responseBody === '') responseBody = null; 257 | // Deserialize Response 258 | if (statusCode === 201) { 259 | var parsedResponse = null; 260 | try { 261 | parsedResponse = JSON.parse(responseBody); 262 | result = JSON.parse(responseBody); 263 | if (parsedResponse !== null && parsedResponse !== undefined) { 264 | var resultMapper = new client.models['Workspace']().mapper(); 265 | result = client.deserialize(resultMapper, parsedResponse, 'result'); 266 | } 267 | } catch (error) { 268 | var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 269 | deserializationError.request = msRest.stripRequest(httpRequest); 270 | deserializationError.response = msRest.stripResponse(response); 271 | return callback(deserializationError); 272 | } 273 | } 274 | 275 | return callback(null, result, httpRequest, response); 276 | }); 277 | }; 278 | 279 | 280 | module.exports = Workspaces; 281 | -------------------------------------------------------------------------------- /lib/autorest/powerBIClient.d.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | import { ServiceClientCredentials, ServiceClientOptions, RequestOptions, ServiceCallback } from 'ms-rest'; 8 | import * as operations from "./operations"; 9 | 10 | declare class PowerBIClient { 11 | /** 12 | * @class 13 | * Initializes a new instance of the PowerBIClient class. 14 | * @constructor 15 | * 16 | * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. 17 | * 18 | * @param {string} [baseUri] - The base URI of the service. 19 | * 20 | * @param {object} [options] - The parameter options 21 | * 22 | * @param {Array} [options.filters] - Filters to be added to the request pipeline 23 | * 24 | * @param {object} [options.requestOptions] - Options for the underlying request object 25 | * {@link https://github.com/request/request#requestoptions-callback Options doc} 26 | * 27 | * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy 28 | * 29 | */ 30 | constructor(credentials: ServiceClientCredentials, baseUri: string, options: ServiceClientOptions); 31 | 32 | credentials: ServiceClientCredentials; 33 | 34 | // Operation groups 35 | datasets: operations.Datasets; 36 | gateways: operations.Gateways; 37 | imports: operations.Imports; 38 | workspaces: operations.Workspaces; 39 | reports: operations.Reports; 40 | } 41 | 42 | export = PowerBIClient; 43 | -------------------------------------------------------------------------------- /lib/autorest/powerBIClient.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 3 | * Changes may cause incorrect behavior and will be lost if the code is 4 | * regenerated. 5 | */ 6 | 7 | /* jshint latedef:false */ 8 | /* jshint forin:false */ 9 | /* jshint noempty:false */ 10 | 11 | 'use strict'; 12 | 13 | var util = require('util'); 14 | var msRest = require('ms-rest'); 15 | var ServiceClient = msRest.ServiceClient; 16 | 17 | var models = require('./models'); 18 | var operations = require('./operations'); 19 | 20 | /** 21 | * @class 22 | * Initializes a new instance of the PowerBIClient class. 23 | * @constructor 24 | * 25 | * @param {credentials} credentials - Subscription credentials which uniquely identify client subscription. 26 | * 27 | * @param {string} [baseUri] - The base URI of the service. 28 | * 29 | * @param {object} [options] - The parameter options 30 | * 31 | * @param {Array} [options.filters] - Filters to be added to the request pipeline 32 | * 33 | * @param {object} [options.requestOptions] - Options for the underlying request object 34 | * {@link https://github.com/request/request#requestoptions-callback Options doc} 35 | * 36 | * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy 37 | * 38 | */ 39 | function PowerBIClient(credentials, baseUri, options) { 40 | if (credentials === null || credentials === undefined) { 41 | throw new Error('\'credentials\' cannot be null.'); 42 | } 43 | 44 | if (!options) options = {}; 45 | 46 | PowerBIClient['super_'].call(this, credentials, options); 47 | this.baseUri = baseUri; 48 | if (!this.baseUri) { 49 | this.baseUri = 'https://api.powerbi.com'; 50 | } 51 | this.credentials = credentials; 52 | 53 | this.datasets = new operations.Datasets(this); 54 | this.gateways = new operations.Gateways(this); 55 | this.imports = new operations.Imports(this); 56 | this.workspaces = new operations.Workspaces(this); 57 | this.reports = new operations.Reports(this); 58 | this.models = models; 59 | msRest.addSerializationMixin(this); 60 | } 61 | 62 | util.inherits(PowerBIClient, ServiceClient); 63 | 64 | module.exports = PowerBIClient; 65 | -------------------------------------------------------------------------------- /lib/client/models/importFileOptions.ts: -------------------------------------------------------------------------------- 1 | export interface ImportFileOptions { 2 | datasetDisplayName?: string, 3 | nameConflict?: string, 4 | customHeaders?: { [headerName: string]: string; } 5 | } 6 | -------------------------------------------------------------------------------- /lib/client/models/index.ts: -------------------------------------------------------------------------------- 1 | export * from './importFileOptions'; 2 | export * from '../../autorest/models'; -------------------------------------------------------------------------------- /lib/client/operations/imports.ts: -------------------------------------------------------------------------------- 1 | import { PowerBIClient } from '../powerBIClient'; 2 | import { ServiceClientOptions, RequestOptions, ServiceCallback, WebResource } from 'ms-rest'; 3 | import fs = require('fs'); 4 | import util = require('util'); 5 | import * as operations from '../../autorest/operations'; 6 | import * as models from '../models'; 7 | let AuorestImports = require('../../autorest/operations/imports'); 8 | let msRest = require('ms-rest'); 9 | 10 | export class Imports implements operations.Imports { 11 | private client: any; 12 | private base: operations.Imports; 13 | 14 | constructor(client: PowerBIClient) { 15 | this.base = new AuorestImports(this); 16 | this.client = client; 17 | } 18 | 19 | public getImports(collectionName: string, workspaceId: string, callback: ServiceCallback): void; 20 | public getImports(collectionName: string, workspaceId: string, options: { customHeaders?: { [headerName: string]: string; } }, callback: ServiceCallback): void; 21 | 22 | public getImports(collectionName: string, workspaceId: string, options: any, callback?: ServiceCallback): void { 23 | this.base.getImports(collectionName, workspaceId, options, callback); 24 | } 25 | 26 | public postImport(collectionName: string, workspaceId: string, importInfo: models.ImportInfo, callback: ServiceCallback): void; 27 | public postImport(collectionName: string, workspaceId: string, importInfo: models.ImportInfo, options: models.ImportFileOptions, callback: ServiceCallback): void; 28 | 29 | public postImport(collectionName: string, workspaceId: string, importInfo: models.ImportInfo, options: any, callback?: ServiceCallback): void { 30 | this.base.postImport.apply(this, arguments); 31 | } 32 | 33 | public getImportById(collectionName: string, workspaceId: string, importId: string, options: models.ImportFileOptions, callback: ServiceCallback): void; 34 | public getImportById(collectionName: string, workspaceId: string, importId: string, callback: ServiceCallback): void; 35 | 36 | public getImportById(collectionName: string, workspaceId: string, importId: string, options: any, callback?: ServiceCallback): void { 37 | this.base.getImportById.apply(this, arguments); 38 | } 39 | 40 | public uploadFile(collectionName: string, workspaceId: string, filePath: string, callback: ServiceCallback): void; 41 | public uploadFile(collectionName: string, workspaceId: string, filePath: string, options: models.ImportFileOptions, callback: ServiceCallback): void; 42 | 43 | public uploadFile(collectionName: string, workspaceId: string, filePath: string, options: any, callback?: ServiceCallback): void { 44 | if (!callback && typeof options === 'function') { 45 | callback = options; 46 | options = null; 47 | } 48 | if (!callback) { 49 | throw new Error('callback cannot be null.'); 50 | } 51 | 52 | var datasetDisplayName = (options && options.datasetDisplayName !== undefined) ? options.datasetDisplayName : undefined; 53 | var nameConflict = (options && options.nameConflict !== undefined) ? options.nameConflict : undefined; 54 | // Validate 55 | try { 56 | if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') { 57 | throw new Error('collectionName cannot be null or undefined and it must be of type string.'); 58 | } 59 | if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') { 60 | throw new Error('workspaceId cannot be null or undefined and it must be of type string.'); 61 | } 62 | if (datasetDisplayName !== null && datasetDisplayName !== undefined && typeof datasetDisplayName.valueOf() !== 'string') { 63 | throw new Error('datasetDisplayName must be of type string.'); 64 | } 65 | if (nameConflict !== null && nameConflict !== undefined && typeof nameConflict.valueOf() !== 'string') { 66 | throw new Error('nameConflict must be of type string.'); 67 | } 68 | if (filePath === null || filePath === undefined) { 69 | throw new Error('filePath cannot be null or undefined.'); 70 | } 71 | } catch (error) { 72 | return callback(error, null, null, null); 73 | } 74 | 75 | // Construct URL 76 | var requestUrl = this.client['baseUri'] + '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports'; 77 | requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName)); 78 | requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId)); 79 | 80 | var queryParameters = []; 81 | if (datasetDisplayName !== null && datasetDisplayName !== undefined) { 82 | queryParameters.push('datasetDisplayName=' + encodeURIComponent(datasetDisplayName)); 83 | } 84 | if (nameConflict !== null && nameConflict !== undefined) { 85 | queryParameters.push('nameConflict=' + encodeURIComponent(nameConflict)); 86 | } 87 | if (queryParameters.length > 0) { 88 | requestUrl += '?' + queryParameters.join('&'); 89 | } 90 | // trim all duplicate forward slashes in the url 91 | var regex = /([^:]\/)\/+/gi; 92 | requestUrl = requestUrl.replace(regex, '$1'); 93 | 94 | var formData = { 95 | file: fs.createReadStream(filePath) 96 | }; 97 | 98 | // Create HTTP transport objects 99 | var httpRequest = WebResource.post(requestUrl); 100 | httpRequest['url'] = requestUrl; 101 | httpRequest['method'] = 'POST'; 102 | httpRequest['formData'] = formData; 103 | httpRequest['headers'] = {}; 104 | 105 | // Set Headers 106 | if (options) { 107 | for (var headerName in options.customHeaders) { 108 | if (options.customHeaders.hasOwnProperty(headerName)) { 109 | httpRequest.withHeader(headerName, options.customHeaders[headerName]); 110 | } 111 | } 112 | } 113 | 114 | // Send Request 115 | return this.client.pipeline(httpRequest, (err, response, responseBody) => { 116 | if (err) { 117 | return callback(err, null, null, null); 118 | } 119 | 120 | var statusCode = response.statusCode; 121 | if (statusCode !== 202) { 122 | var error: any = new Error(responseBody); 123 | error.statusCode = response.statusCode; 124 | error.request = msRest.stripRequest(httpRequest); 125 | error.response = msRest.stripResponse(response); 126 | if (responseBody === '') responseBody = null; 127 | var parsedErrorResponse; 128 | try { 129 | parsedErrorResponse = JSON.parse(responseBody); 130 | if (parsedErrorResponse) { 131 | if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; 132 | if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; 133 | if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; 134 | } 135 | } catch (defaultError) { 136 | error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 137 | '- "%s" for the default response.', defaultError.message, responseBody); 138 | return callback(error, null, null, null); 139 | } 140 | return callback(error, null, null, null); 141 | } 142 | // Create Result 143 | var result = null; 144 | if (responseBody === '') responseBody = null; 145 | // Deserialize Response 146 | if (statusCode === 202) { 147 | var parsedResponse = null; 148 | try { 149 | parsedResponse = JSON.parse(responseBody); 150 | result = JSON.parse(responseBody); 151 | if (parsedResponse !== null && parsedResponse !== undefined) { 152 | var resultMapper = new this.client.models['ImportModel']().mapper(); 153 | result = this.client.deserialize(resultMapper, parsedResponse, 'result'); 154 | } 155 | } catch (error) { 156 | var deserializationError: any = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody)); 157 | deserializationError.request = msRest.stripRequest(httpRequest); 158 | deserializationError.response = msRest.stripResponse(response); 159 | return callback(deserializationError, null, null, null); 160 | } 161 | } 162 | 163 | return callback(null, result, httpRequest, response); 164 | }); 165 | } 166 | } -------------------------------------------------------------------------------- /lib/client/operations/index.ts: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | export { Datasets, Gateways, Reports, Workspaces } from '../../autorest/operations'; 3 | export { Imports } from './imports'; 4 | export * from '../models'; 5 | -------------------------------------------------------------------------------- /lib/client/powerBIClient.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import AutorestClient = require('../autorest/powerBIClient'); 4 | import * as operations from './operations'; 5 | import {ServiceClientCredentials, ServiceClientOptions} from 'ms-rest'; 6 | 7 | export class PowerBIClient extends AutorestClient { 8 | public imports:operations.Imports; 9 | 10 | constructor(credentials: ServiceClientCredentials, baseUri: string='https://api.powerbi.com', options?: ServiceClientOptions) { 11 | super(credentials, baseUri, options); 12 | this.imports = new operations.Imports(this); 13 | } 14 | } -------------------------------------------------------------------------------- /lib/core/powerBIToken.ts: -------------------------------------------------------------------------------- 1 | import * as jwt from 'jwt-simple'; 2 | import {Util as util} from './util'; 3 | 4 | export class PowerBIToken { 5 | private claims: any; 6 | private expiration: Date; 7 | 8 | constructor(expiration?: Date) { 9 | this.expiration = expiration; 10 | this.claims = { 11 | ver: '0.2.0', 12 | aud: 'https://analysis.windows.net/powerbi/api', 13 | iss: 'Power BI Node SDK' 14 | }; 15 | } 16 | 17 | public static createReportEmbedToken(workspaceCollectionName: string, workspaceId: string, reportId?: string, datasetId?: string, scopes: string|string[] = '', username: string = null, roles: string|string[] = null, expiration: Date = null): PowerBIToken { 18 | 19 | if (roles && !username) { 20 | throw new Error('Cannot have an empty or null Username claim with the non-empty Roles claim'); 21 | } 22 | 23 | if (!reportId && !datasetId) { 24 | throw new Error('Token must contain either reportId or datasetId claim'); 25 | } 26 | 27 | var token = new PowerBIToken(expiration); 28 | token.addClaim('type', 'embed'); 29 | token.addClaim('wcn', workspaceCollectionName); 30 | token.addClaim('wid', workspaceId); 31 | 32 | if (reportId) { 33 | token.addClaim('rid', reportId); 34 | } 35 | 36 | if (datasetId) { 37 | token.addClaim('did', datasetId); 38 | } 39 | 40 | if(username != null) { 41 | token.addClaim('username', username); 42 | 43 | if(roles != null) { 44 | token.addClaim('roles', roles); 45 | } 46 | } 47 | 48 | if (scopes) { 49 | if (Array.isArray(scopes)) { 50 | scopes = (scopes).join(' '); 51 | } 52 | 53 | token.addClaim('scp', scopes); 54 | } 55 | 56 | return token; 57 | } 58 | 59 | private setTokenExpiration() { 60 | var nowSeconds = util.getUnixTime(new Date()); 61 | var expirationSeconds = this.expiration ? util.getUnixTime(this.expiration) : nowSeconds + 3600 62 | 63 | if (expirationSeconds <= nowSeconds) { 64 | throw new Error('Token expiration must be in the future'); 65 | } 66 | 67 | this.addClaim('nbf', nowSeconds); 68 | this.addClaim('exp', expirationSeconds); 69 | } 70 | 71 | public addClaim(key: string, value: any) { 72 | this.claims[key] = value; 73 | } 74 | 75 | public generate(accessKey: string): string { 76 | this.setTokenExpiration(); 77 | 78 | return jwt.encode(this.claims, accessKey); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /lib/core/util.ts: -------------------------------------------------------------------------------- 1 | export class Util { 2 | public static getUnixTime(date: Date): number { 3 | return Math.floor(date.getTime() / 1000); 4 | } 5 | } -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './client/powerBIClient'; 2 | export * from './client/models'; 3 | export * from './core/powerBIToken'; 4 | export * from './core/util'; 5 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './client/powerBIClient'; 2 | export * from './client/models'; 3 | export * from './core/powerBIToken'; 4 | export * from './core/util'; 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "powerbi-api", 3 | "version": "1.2.3", 4 | "description": "Node client library for Power BI API", 5 | "main": "./lib/index.js", 6 | "typings": "./lib/index.d.ts", 7 | "scripts": { 8 | "precontrib": "npm install -g typings typescript && npm install", 9 | "contrib": "typings install && tsc", 10 | "test": "mocha --recursive" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/Microsoft/PowerBI-Node.git" 15 | }, 16 | "keywords": [ 17 | "powerbi", 18 | "node", 19 | "javascript", 20 | "rest", 21 | "api" 22 | ], 23 | "author": "PowerBI (https://dev.powerbi.com)", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/Microsoft/PowerBI-Node/issues" 27 | }, 28 | "homepage": "https://github.com/Microsoft/PowerBI-Node#readme", 29 | "dependencies": { 30 | "jwt-simple": "^0.5.0", 31 | "ms-rest": "^1.12.0" 32 | }, 33 | "devDependencies": { 34 | "chai": "^3.5.0", 35 | "mocha": "^2.4.5", 36 | "typescript": "^1.8.10", 37 | "typings": "^1.3.0" 38 | }, 39 | "directories": { 40 | "test": "test" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/core/PowerBIToken.test.ts: -------------------------------------------------------------------------------- 1 | import * as chai from 'chai'; 2 | import * as powerbi from '../../lib'; 3 | import * as jwt from 'jwt-simple'; 4 | 5 | let expect = chai.expect; 6 | 7 | describe('Power BI Token', () => { 8 | const version: string = '0.2.0'; 9 | const issuer: string = 'Power BI Node SDK'; 10 | const resource: string = 'https://analysis.windows.net/powerbi/api'; 11 | const workspacCollection: string = 'TestCollection'; 12 | const workspaceId: string = 'fd41b1db-9e26-4103-99a7-f9ad336b99a7'; 13 | const reportId: string = 'fe607ad3-97bf-4dd5-98eb-db4a4d5de4e0'; 14 | const datasetId: string = 'fe123ad3-97bf-4dd5-98eb-db7c432de4e0'; 15 | const accessKey: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; 16 | const username: string = 'TestUser'; 17 | const scopes: string = 'Scope1'; 18 | const scopesArray: string[] = ['Scope1', 'Scope2']; 19 | const scopesArrayDecoded: string = 'Scope1 Scope2'; 20 | 21 | it('is defined', () => { 22 | expect(powerbi.PowerBIToken).to.exist; 23 | }); 24 | 25 | describe('Generic Tokens', () => { 26 | it('can be created with arbitrary claims', () => { 27 | let token = new powerbi.PowerBIToken(); 28 | token.addClaim('foo', 'bar'); 29 | 30 | let genericToken = token.generate(accessKey); 31 | let decoded = jwt.decode(genericToken, accessKey); 32 | 33 | expect(decoded.foo).to.equal('bar'); 34 | }); 35 | 36 | it('are created with a default expiration', () => { 37 | let nbf = powerbi.Util.getUnixTime(new Date()); 38 | let exp = nbf + 3600; 39 | 40 | let token = new powerbi.PowerBIToken(); 41 | let genericToken = token.generate(accessKey); 42 | let decoded = jwt.decode(genericToken, accessKey); 43 | 44 | expect(decoded.nbf).to.equal(nbf); 45 | expect(decoded.exp).to.equal(exp); 46 | }); 47 | 48 | it('cannot be created with a expiration in the past', () => { 49 | let token = new powerbi.PowerBIToken(new Date()); 50 | let hasError = false; 51 | 52 | try { 53 | let genericToken = token.generate(accessKey); 54 | let decoded = jwt.decode(genericToken, accessKey); 55 | } 56 | catch (err) { 57 | hasError = true; 58 | expect(err.message).to.equal('Token expiration must be in the future'); 59 | } 60 | 61 | expect(hasError).to.be.true; 62 | }); 63 | }); 64 | 65 | describe('Embed Tokens', () => { 66 | it('can be created', () => { 67 | let token = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId); 68 | let jwt = token.generate(accessKey); 69 | 70 | expect(jwt).not.to.be.null; 71 | }); 72 | 73 | it('can be created for datasetId', () => { 74 | let token = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, null, datasetId); 75 | let jwt = token.generate(accessKey); 76 | 77 | expect(jwt).not.to.be.null; 78 | }); 79 | 80 | it('are created with a default expiration', () => { 81 | let nbf = powerbi.Util.getUnixTime(new Date()); 82 | let exp = nbf + 3600; 83 | 84 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId); 85 | let token = embedToken.generate(accessKey); 86 | let decoded = jwt.decode(token, accessKey); 87 | 88 | expect(decoded.nbf).to.equal(nbf); 89 | expect(decoded.exp).to.equal(exp) 90 | }); 91 | 92 | it('are created with the correct claims - minimal params', () => { 93 | let nbf = powerbi.Util.getUnixTime(new Date()); 94 | let exp = nbf + 3600; 95 | let expiration = new Date(exp * 1000); 96 | 97 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId); 98 | let token = embedToken.generate(accessKey); 99 | let decoded = jwt.decode(token, accessKey); 100 | 101 | expect(decoded.ver).to.equal(version); 102 | expect(decoded.aud).to.equal(resource); 103 | expect(decoded.iss).to.equal(issuer); 104 | expect(decoded.wcn).to.equal(workspacCollection); 105 | expect(decoded.wid).to.equal(workspaceId); 106 | expect(decoded.rid).to.equal(reportId); 107 | }); 108 | 109 | it('are created with the correct claims', () => { 110 | let nbf = powerbi.Util.getUnixTime(new Date()); 111 | let exp = nbf + 3600; 112 | let expiration = new Date(exp * 1000); 113 | 114 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId, datasetId, scopes, username, 'TestRole', expiration); 115 | let token = embedToken.generate(accessKey); 116 | let decoded = jwt.decode(token, accessKey); 117 | 118 | expect(decoded.ver).to.equal(version); 119 | expect(decoded.aud).to.equal(resource); 120 | expect(decoded.iss).to.equal(issuer); 121 | expect(decoded.wcn).to.equal(workspacCollection); 122 | expect(decoded.wid).to.equal(workspaceId); 123 | expect(decoded.rid).to.equal(reportId); 124 | expect(decoded.did).to.equal(datasetId); 125 | expect(decoded.nbf).to.equal(nbf); 126 | expect(decoded.exp).to.equal(exp); 127 | expect(decoded.scp).to.equal(scopes); 128 | expect(decoded.username).to.equal(username); 129 | expect(decoded.roles).to.equal('TestRole'); 130 | }); 131 | 132 | it('are created with the correct claims - datasetId only', () => { 133 | let nbf = powerbi.Util.getUnixTime(new Date()); 134 | let exp = nbf + 3600; 135 | let expiration = new Date(exp * 1000); 136 | 137 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, null, datasetId, scopes, username, 'TestRole', expiration); 138 | let token = embedToken.generate(accessKey); 139 | let decoded = jwt.decode(token, accessKey); 140 | 141 | expect(decoded.ver).to.equal(version); 142 | expect(decoded.aud).to.equal(resource); 143 | expect(decoded.iss).to.equal(issuer); 144 | expect(decoded.wcn).to.equal(workspacCollection); 145 | expect(decoded.wid).to.equal(workspaceId); 146 | expect(decoded.rid).to.be.undefined; 147 | expect(decoded.did).to.equal(datasetId); 148 | expect(decoded.nbf).to.equal(nbf); 149 | expect(decoded.exp).to.equal(exp); 150 | expect(decoded.scp).to.equal(scopes); 151 | expect(decoded.username).to.equal(username); 152 | expect(decoded.roles).to.equal('TestRole'); 153 | }); 154 | 155 | it('are created with the correct claims - scopes as array', () => { 156 | let nbf = powerbi.Util.getUnixTime(new Date()); 157 | let exp = nbf + 3600; 158 | let expiration = new Date(exp * 1000); 159 | 160 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId, null, scopesArray, username, 'TestRole', expiration); 161 | let token = embedToken.generate(accessKey); 162 | let decoded = jwt.decode(token, accessKey); 163 | 164 | expect(decoded.ver).to.equal(version); 165 | expect(decoded.aud).to.equal(resource); 166 | expect(decoded.iss).to.equal(issuer); 167 | expect(decoded.wcn).to.equal(workspacCollection); 168 | expect(decoded.wid).to.equal(workspaceId); 169 | expect(decoded.rid).to.equal(reportId); 170 | expect(decoded.nbf).to.equal(nbf); 171 | expect(decoded.exp).to.equal(exp); 172 | expect(decoded.scp).to.equal(scopesArrayDecoded); 173 | expect(decoded.username).to.equal(username); 174 | expect(decoded.roles).to.equal('TestRole'); 175 | }); 176 | 177 | it('are created with multiple RLS roles', () => { 178 | let nbf = powerbi.Util.getUnixTime(new Date()); 179 | let exp = nbf + 3600; 180 | let expiration = new Date(exp * 1000); 181 | let roles = ['TestRole1', 'TestRole2']; 182 | 183 | let embedToken = powerbi.PowerBIToken.createReportEmbedToken(workspacCollection, workspaceId, reportId, datasetId, scopes, username, roles, expiration); 184 | let token = embedToken.generate(accessKey); 185 | let decoded = jwt.decode(token, accessKey); 186 | 187 | expect(decoded.username).to.equal(username); 188 | expect(decoded.roles).to.eql(roles); 189 | }); 190 | 191 | it('fail to create when missing reportId and datasetId', () => { 192 | expect(powerbi.PowerBIToken.createReportEmbedToken.bind(powerbi.PowerBIToken, workspacCollection, workspaceId)) 193 | .to 194 | .throw('Token must contain either reportId or datasetId claim'); 195 | }); 196 | 197 | it('fail to create when RLS username is empty and roles is not', () => { 198 | let nbf = powerbi.Util.getUnixTime(new Date()); 199 | let exp = nbf + 3600; 200 | let expiration = new Date(exp * 1000); 201 | let role = 'TestRole1'; 202 | let badUsernames = [null, undefined, '']; 203 | 204 | badUsernames.forEach(badUsername => { 205 | expect(powerbi.PowerBIToken.createReportEmbedToken.bind(powerbi.PowerBIToken, workspacCollection, workspaceId, reportId, datasetId, scopes, badUsername, role, expiration)) 206 | .to 207 | .throw('Cannot have an empty or null Username claim with the non-empty Roles claim'); 208 | } 209 | ); 210 | }); 211 | }); 212 | }); 213 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "allowJs": false, 6 | "declaration": true, 7 | "moduleResolution": "node", 8 | "sourceMap": true 9 | }, 10 | "exclude": [ 11 | "node_modules", 12 | "lib/autorest", 13 | "typings/index.d.ts", 14 | "typings/global" 15 | ] 16 | } -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "globalDependencies": { 3 | "chai": "registry:dt/chai#3.4.0+20160317120654", 4 | "jwt-simple": "registry:dt/jwt-simple#0.2.0+20160316155526", 5 | "mocha": "registry:dt/mocha#2.2.5+20160317120654", 6 | "node": "registry:dt/node#6.0.0+20160608110640" 7 | } 8 | } 9 | --------------------------------------------------------------------------------