powerbi-visuals-tools 7.0.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,608 @@
1
+ /*
2
+ * Power BI Visual CLI - MCP Server - Available APIs Tool
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ */
8
+ "use strict";
9
+ import fs from 'fs-extra';
10
+ import path from 'path';
11
+ import { getSourceFiles } from '../../utils.js';
12
+ const AVAILABLE_APIS = [
13
+ // Data APIs
14
+ {
15
+ name: 'fetchMoreData',
16
+ category: 'data',
17
+ description: 'Enables loading additional data in chunks. Essential for large datasets that exceed the initial row limit.',
18
+ minApiVersion: '2.6.0',
19
+ codePatterns: [/fetchMoreData/],
20
+ example: `// In update method
21
+ if (options.dataViews[0].metadata.segment) {
22
+ host.fetchMoreData();
23
+ }`,
24
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/fetch-more-data'
25
+ },
26
+ {
27
+ name: 'getDataViewSnapshot',
28
+ category: 'data',
29
+ description: 'Gets a snapshot of the current DataView for async processing.',
30
+ minApiVersion: '5.1.0',
31
+ codePatterns: [/getDataViewSnapshot/],
32
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/fetch-more-data'
33
+ },
34
+ {
35
+ name: 'persistProperties',
36
+ category: 'data',
37
+ description: 'Allows visual to save properties that persist across sessions. Saved along with the visual definition.',
38
+ minApiVersion: '1.3.0',
39
+ codePatterns: [/persistProperties/],
40
+ example: `host.persistProperties({
41
+ replace: [{
42
+ objectName: "settings",
43
+ selector: null,
44
+ properties: { myProperty: value }
45
+ }]
46
+ });`,
47
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
48
+ },
49
+ {
50
+ name: 'applyJsonFilter (Basic Filter)',
51
+ category: 'data',
52
+ description: 'Apply a basic filter to filter data by specific values (In, NotIn, All operators). Uses IBasicFilter interface from powerbi-models.',
53
+ minApiVersion: '1.7.0',
54
+ codePatterns: [/applyJsonFilter/, /BasicFilter/],
55
+ example: `import { BasicFilter } from "powerbi-models";
56
+
57
+ const filter = new BasicFilter(
58
+ { table: "Sales", column: "Region" },
59
+ "In",
60
+ ["East", "West"]
61
+ );
62
+ host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);`,
63
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/filter-api'
64
+ },
65
+ {
66
+ name: 'applyJsonFilter (Advanced Filter)',
67
+ category: 'data',
68
+ description: 'Apply an advanced filter with complex conditions (LessThan, GreaterThan, Contains, IsBlank, etc.). Supports And/Or logic.',
69
+ minApiVersion: '1.7.0',
70
+ codePatterns: [/AdvancedFilter/],
71
+ example: `import { AdvancedFilter } from "powerbi-models";
72
+ const filter = new AdvancedFilter(
73
+ { table: "Sales", column: "Amount" },
74
+ "And",
75
+ { operator: "GreaterThan", value: 100 },
76
+ { operator: "LessThan", value: 1000 }
77
+ );
78
+ host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);`,
79
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/filter-api'
80
+ },
81
+ {
82
+ name: 'applyJsonFilter (Tuple Filter)',
83
+ category: 'data',
84
+ description: 'Apply a multi-column filter to filter data by combinations of values across multiple columns and tables.',
85
+ minApiVersion: '2.3.0',
86
+ codePatterns: [/TupleFilter/, /ITupleFilter/],
87
+ example: `const filter: ITupleFilter = {
88
+ $schema: "https://powerbi.com/product/schema#tuple",
89
+ filterType: FilterType.Tuple,
90
+ operator: "In",
91
+ target: [
92
+ { table: "DataTable", column: "Team" },
93
+ { table: "DataTable", column: "Value" }
94
+ ],
95
+ values: [
96
+ [{ value: "Team1" }, { value: 5 }],
97
+ [{ value: "Team2" }, { value: 6 }]
98
+ ]
99
+ };
100
+ host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);`,
101
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/filter-api'
102
+ },
103
+ {
104
+ name: 'applyCustomSort',
105
+ category: 'data',
106
+ description: 'Allows visual to apply custom sorting options to the data.',
107
+ minApiVersion: '4.4.0',
108
+ codePatterns: [/applyCustomSort/],
109
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/sort-options'
110
+ },
111
+ {
112
+ name: 'refreshHostData',
113
+ category: 'data',
114
+ description: 'Requests the host to refresh the data for the visual.',
115
+ minApiVersion: '2.6.0',
116
+ codePatterns: [/refreshHostData/],
117
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
118
+ },
119
+ // Formatting APIs
120
+ {
121
+ name: 'colorPalette',
122
+ category: 'formatting',
123
+ description: 'Access the Power BI color palette for consistent theming.',
124
+ minApiVersion: '2.1.0',
125
+ codePatterns: [/colorPalette/, /getColor/],
126
+ example: `const colors = host.colorPalette;
127
+ const color = colors.getColor("category1").value;`,
128
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
129
+ },
130
+ {
131
+ name: 'getFormattingModel',
132
+ category: 'formatting',
133
+ description: 'Modern formatting pane API. Returns formatting cards and groups for the Format pane.',
134
+ minApiVersion: '5.1.0',
135
+ codePatterns: [/getFormattingModel/, /FormattingModel/],
136
+ example: `public getFormattingModel(): FormattingModel {
137
+ return {
138
+ cards: [{
139
+ displayName: "My Settings",
140
+ groups: [{
141
+ displayName: "Font",
142
+ slices: [
143
+ { displayName: "Size", control: { type: "NumUpDown", properties: { descriptor: { objectName: "font", propertyName: "size" } } } }
144
+ ]
145
+ }]
146
+ }]
147
+ };
148
+ }`,
149
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/format-pane'
150
+ },
151
+ {
152
+ name: 'applyCustomColor',
153
+ category: 'formatting',
154
+ description: 'Apply custom colors that override theme colors for specific data points.',
155
+ minApiVersion: '3.8.0',
156
+ codePatterns: [/applyCustomColor/],
157
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
158
+ },
159
+ {
160
+ name: 'isHighContrastModeSupported',
161
+ category: 'formatting',
162
+ description: 'Detect and support Windows High Contrast mode for accessibility',
163
+ minApiVersion: '2.6.0',
164
+ codePatterns: [/allowHighContrast/, /highContrast/, /isHighContrast/],
165
+ example: `if (host.hostCapabilities.allowHighContrast) {
166
+ // Apply high contrast styling using colorPalette
167
+ const foreground = host.colorPalette.foreground.value;
168
+ const background = host.colorPalette.background.value;
169
+ }`,
170
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
171
+ },
172
+ {
173
+ name: 'conditionalFormatting',
174
+ category: 'formatting',
175
+ description: 'Support conditional formatting on visual properties. Users can set rules-based formatting in the format pane.',
176
+ minApiVersion: '3.8.0',
177
+ codePatterns: [/conditionalFormatting/],
178
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/conditional-format'
179
+ },
180
+ {
181
+ name: 'onObjectFormatting',
182
+ category: 'formatting',
183
+ description: 'On-Object formatting allows users to format visual elements directly by clicking on them, without opening the format pane.',
184
+ minApiVersion: '5.1.0',
185
+ codePatterns: [/onObjectFormatting/, /SubSelectionService/],
186
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/on-object-formatting-api'
187
+ },
188
+ // Interaction APIs
189
+ {
190
+ name: 'selectionManager',
191
+ category: 'interaction',
192
+ description: 'Handle data point selection and cross-filtering with other visuals.',
193
+ minApiVersion: '1.0.0',
194
+ codePatterns: [/selectionManager/, /createSelectionManager/],
195
+ example: `const selectionManager = host.createSelectionManager();
196
+ const selectionId = host.createSelectionIdBuilder()
197
+ .withCategory(categories, index)
198
+ .createSelectionId();
199
+ // On click:
200
+ selectionManager.select(selectionId);`,
201
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/selection-api'
202
+ },
203
+ {
204
+ name: 'tooltipService',
205
+ category: 'interaction',
206
+ description: 'Show rich tooltip/tooltips on hover with data details. Supports show, move, and hide operations.',
207
+ minApiVersion: '1.7.0',
208
+ codePatterns: [/tooltipService/, /ITooltipService/],
209
+ example: `host.tooltipService.show({
210
+ dataItems: [{ displayName: "Category", value: "East" }],
211
+ coordinates: [x, y],
212
+ isTouchEvent: false,
213
+ identities: [selectionId]
214
+ });`,
215
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/add-tooltips'
216
+ },
217
+ {
218
+ name: 'reportPageTooltips',
219
+ category: 'interaction',
220
+ description: 'Enable report page tooltip support. Users can create custom tooltip pages and assign them to the visual from the format pane.',
221
+ minApiVersion: '2.6.0',
222
+ codePatterns: [/canvas.*true/, /supportedTypes/],
223
+ example: `// In capabilities.json:
224
+ {
225
+ "tooltips": {
226
+ "supportedTypes": { "default": true, "canvas": true },
227
+ "roles": ["tooltips"]
228
+ }
229
+ }`,
230
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/add-tooltips'
231
+ },
232
+ {
233
+ name: 'modernTooltips',
234
+ category: 'interaction',
235
+ description: 'Modern visual tooltip with drill actions and report theme styling. Add supportEnhancedTooltips in capabilities.json.',
236
+ minApiVersion: '3.8.3',
237
+ codePatterns: [/supportEnhancedTooltips/],
238
+ example: `// In capabilities.json:
239
+ {
240
+ "tooltips": {
241
+ "supportedTypes": { "default": true, "canvas": true },
242
+ "supportEnhancedTooltips": true,
243
+ "roles": ["tooltips"]
244
+ }
245
+ }`,
246
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/add-tooltips'
247
+ },
248
+ {
249
+ name: 'contextMenuService',
250
+ category: 'interaction',
251
+ description: 'Show Power BI context menu on right-click with drill, filter, copy, and other actions.',
252
+ minApiVersion: '2.5.0',
253
+ codePatterns: [/contextMenuService/, /contextmenu/],
254
+ example: `element.addEventListener("contextmenu", (e) => {
255
+ host.contextMenuService.show({
256
+ dataItems: contextMenuData,
257
+ position: { x: e.clientX, y: e.clientY }
258
+ });
259
+ e.preventDefault();
260
+ });`,
261
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
262
+ },
263
+ {
264
+ name: 'launchUrl',
265
+ category: 'interaction',
266
+ description: 'Open external URLs in a new browser tab. Must be HTTPS for security.',
267
+ minApiVersion: '1.7.0',
268
+ codePatterns: [/launchUrl/],
269
+ example: `host.launchUrl("https://example.com");`,
270
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/launch-url'
271
+ },
272
+ {
273
+ name: 'drilldown',
274
+ category: 'interaction',
275
+ description: 'Enable drill-down/drill-up functionality for hierarchical data.',
276
+ minApiVersion: '2.0.0',
277
+ codePatterns: [/\.drill\(/, /drilldown/, /drillDown/],
278
+ example: `// Drill down on a data point
279
+ host.drill({ dataRoles: ["category"], down: true });`,
280
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/drill-down-support'
281
+ },
282
+ {
283
+ name: 'displayWarningIcon',
284
+ category: 'interaction',
285
+ description: 'Show a warning icon in the visual header with a custom title and detail message.',
286
+ minApiVersion: '4.0.0',
287
+ codePatterns: [/displayWarningIcon/],
288
+ example: `host.displayWarningIcon("Data may be incomplete", "Some rows were filtered out due to data limits.");`,
289
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-display-warning-icon'
290
+ },
291
+ {
292
+ name: 'allowInteractions',
293
+ category: 'interaction',
294
+ description: 'Check if visual interactions are allowed. Non-interactive in dashboard tiles, interactive in reports.',
295
+ minApiVersion: '1.0.0',
296
+ codePatterns: [/allowInteractions/],
297
+ example: `const allowInteractions = options.host.hostCapabilities.allowInteractions;
298
+ bars.on('click', function(d) {
299
+ if (allowInteractions) {
300
+ selectionManager.select(d.selectionId);
301
+ }
302
+ });`,
303
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visuals-interactions'
304
+ },
305
+ {
306
+ name: 'bookmarkSupport',
307
+ category: 'interaction',
308
+ description: 'Save and restore visual state with Power BI bookmarks. Supports selection-based and filter-based bookmarks.',
309
+ minApiVersion: '1.11.0',
310
+ codePatterns: [/registerOnSelectCallback/, /bookmark/i],
311
+ example: `// Register callback to restore selections from bookmark
312
+ selectionManager.registerOnSelectCallback(
313
+ (ids: ISelectionId[]) => {
314
+ dataPoints.forEach(dp => {
315
+ dp.selected = ids.some(id => id.equals(dp.selectionId));
316
+ });
317
+ }
318
+ );`,
319
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/bookmarks-support'
320
+ },
321
+ {
322
+ name: 'switchFocusModeState',
323
+ category: 'interaction',
324
+ description: 'Programmatically change the focus mode state of the visual (expand/collapse).',
325
+ minApiVersion: '2.6.0',
326
+ codePatterns: [/switchFocusModeState/],
327
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
328
+ },
329
+ {
330
+ name: 'selectionIdBuilder',
331
+ category: 'interaction',
332
+ description: 'Generate unique selection IDs for data points to enable cross-highlighting and cross-filtering.',
333
+ minApiVersion: '1.0.0',
334
+ codePatterns: [/selectionIdBuilder/, /createSelectionIdBuilder/, /SelectionId/],
335
+ example: `const selectionId = host.createSelectionIdBuilder()
336
+ .withCategory(categories, index)
337
+ .withSeries(dataView.categorical.values, seriesValue)
338
+ .withMeasure(measure.queryName)
339
+ .createSelectionId();`,
340
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/selection-api'
341
+ },
342
+ // Utility APIs
343
+ {
344
+ name: 'createLocalizationManager',
345
+ category: 'utility',
346
+ description: 'Support multiple languages with string localization. Uses stringResources folder with JSON files per locale.',
347
+ minApiVersion: '2.3.0',
348
+ codePatterns: [/createLocalizationManager/, /getDisplayName/, /stringResources/],
349
+ example: `const locManager = host.createLocalizationManager();
350
+ const text = locManager.getDisplayName("myKey");`,
351
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/localization'
352
+ },
353
+ {
354
+ name: 'storageService',
355
+ category: 'utility',
356
+ description: 'Store data locally (up to 1MB) that persists across sessions. Uses key-value pair storage.',
357
+ minApiVersion: '2.1.0',
358
+ codePatterns: [/storageService/, /localStorageService/],
359
+ example: `await host.storageService.set("myKey", "myValue");
360
+ const value = await host.storageService.get("myKey");`,
361
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/local-storage'
362
+ },
363
+ {
364
+ name: 'storageV2Service',
365
+ category: 'utility',
366
+ description: 'Version 2 of the local storage service with improved API.',
367
+ minApiVersion: '4.5.0',
368
+ codePatterns: [/storageV2Service/],
369
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/local-storage'
370
+ },
371
+ {
372
+ name: 'downloadService',
373
+ category: 'utility',
374
+ description: 'Trigger file download from the visual (e.g., export data to CSV, Excel, PDF).',
375
+ minApiVersion: '3.8.0',
376
+ codePatterns: [/downloadService/, /exportVisualsContent/],
377
+ example: `host.downloadService.exportVisualsContent(
378
+ csvContent,
379
+ "data.csv",
380
+ "text/csv"
381
+ );`,
382
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/file-download-api'
383
+ },
384
+ {
385
+ name: 'eventService',
386
+ category: 'utility',
387
+ description: 'Report rendering events (started, finished, failed) for performance tracking. Required for certification.',
388
+ minApiVersion: '2.7.0',
389
+ codePatterns: [/eventService/, /renderingStarted/, /renderingFinished/, /renderingFailed/],
390
+ example: `// Must be called in update():
391
+ host.eventService.renderingStarted(options);
392
+ try {
393
+ // ... rendering logic
394
+ host.eventService.renderingFinished(options);
395
+ } catch (e) {
396
+ host.eventService.renderingFailed(options, e);
397
+ }`,
398
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/event-service'
399
+ },
400
+ {
401
+ name: 'modalDialog',
402
+ category: 'utility',
403
+ description: 'Open a modal dialog for extended UI (configuration wizards, data entry forms, detailed views).',
404
+ minApiVersion: '4.5.0',
405
+ codePatterns: [/openModalDialog/, /modalDialog/, /DialogSizeOption/],
406
+ example: `const dialogResult = await host.openModalDialog(
407
+ dialogPage,
408
+ { title: "Settings", size: DialogSizeOption.Medium }
409
+ );`,
410
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/create-display-dialog-box'
411
+ },
412
+ {
413
+ name: 'authentication',
414
+ category: 'utility',
415
+ description: 'Get Microsoft Entra ID (Azure AD) token for accessing external services requiring authentication.',
416
+ minApiVersion: '4.0.0',
417
+ codePatterns: [/acquireAADTokenService/, /acquireToken/],
418
+ example: `const token = await host.acquireAADTokenService.acquireToken({
419
+ resource: "https://graph.microsoft.com"
420
+ });`,
421
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/authentication-api'
422
+ },
423
+ {
424
+ name: 'webAccessService',
425
+ category: 'utility',
426
+ description: 'Check permission status for accessing remote resources. Requires WebAccess privilege in capabilities.json.',
427
+ minApiVersion: '4.0.0',
428
+ codePatterns: [/webAccessService/],
429
+ example: `const result = await host.webAccessService.check("https://api.example.com");
430
+ if (result.accessAllowed) {
431
+ // fetch data from external service
432
+ }`,
433
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/permissions-api'
434
+ },
435
+ {
436
+ name: 'licenseManager',
437
+ category: 'utility',
438
+ description: 'Manage visual licensing. Check if user has specific license for premium features.',
439
+ minApiVersion: '5.1.0',
440
+ codePatterns: [/licenseManager/, /LicenseInfoResult/],
441
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/licensing-api'
442
+ },
443
+ {
444
+ name: 'landingPage',
445
+ category: 'utility',
446
+ description: 'Show a custom landing page when the visual has no data. Set supportsLandingPage in capabilities.json.',
447
+ minApiVersion: '2.6.0',
448
+ codePatterns: [/supportsLandingPage/, /landingPage/],
449
+ example: `// In capabilities.json:
450
+ { "supportsLandingPage": true }
451
+
452
+ // In update():
453
+ if (options.dataViews.length === 0) {
454
+ this.showLandingPage();
455
+ }`,
456
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/landing-page'
457
+ },
458
+ {
459
+ name: 'subtotals',
460
+ category: 'utility',
461
+ description: 'Enable subtotals and totals support in matrix/table visuals. Configure via capabilities.json.',
462
+ minApiVersion: '4.1.0',
463
+ codePatterns: [/subtotals/, /SubtotalType/],
464
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/total-subtotal-api'
465
+ },
466
+ {
467
+ name: 'telemetry',
468
+ category: 'utility',
469
+ description: 'Send telemetry trace events for diagnostics and performance monitoring.',
470
+ minApiVersion: '2.6.0',
471
+ codePatterns: [/telemetry/, /trace\(/],
472
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
473
+ },
474
+ {
475
+ name: 'instanceId',
476
+ category: 'utility',
477
+ description: 'Get a unique string identifier for the current visual instance. Useful for caching and state management.',
478
+ minApiVersion: '2.1.0',
479
+ codePatterns: [/instanceId/],
480
+ example: `const id = host.instanceId; // unique per visual instance`,
481
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/visual-api'
482
+ },
483
+ {
484
+ name: 'locale',
485
+ category: 'utility',
486
+ description: 'Get the current locale string (e.g., "en-US", "de-DE") for formatting numbers, dates, and strings.',
487
+ minApiVersion: '1.3.0',
488
+ codePatterns: [/host\.locale/, /\.locale/],
489
+ example: `const locale = host.locale; // "en-US"
490
+ const formatter = new Intl.NumberFormat(locale);`,
491
+ docsUrl: 'https://learn.microsoft.com/power-bi/developer/visuals/localization'
492
+ }
493
+ ];
494
+ async function scanProjectForApiUsage(rootPath) {
495
+ const usageMap = new Map();
496
+ const srcPath = path.join(rootPath, 'src');
497
+ const sourceFiles = await getSourceFiles(srcPath);
498
+ // Also scan capabilities.json for config-based APIs
499
+ const capabilitiesPath = path.join(rootPath, 'capabilities.json');
500
+ let capabilitiesContent = '';
501
+ if (fs.existsSync(capabilitiesPath)) {
502
+ capabilitiesContent = await fs.readFile(capabilitiesPath, 'utf-8');
503
+ }
504
+ // Read all source files
505
+ const fileContents = [];
506
+ for (const file of sourceFiles) {
507
+ const content = await fs.readFile(file, 'utf-8');
508
+ fileContents.push({ file, content });
509
+ }
510
+ for (const api of AVAILABLE_APIS) {
511
+ const info = { used: false, files: [] };
512
+ if (api.codePatterns) {
513
+ for (const pattern of api.codePatterns) {
514
+ // Check source files
515
+ for (const { file, content } of fileContents) {
516
+ if (pattern.test(content)) {
517
+ const relativePath = path.relative(rootPath, file);
518
+ if (!info.files.includes(relativePath)) {
519
+ info.files.push(relativePath);
520
+ }
521
+ info.used = true;
522
+ }
523
+ }
524
+ // Check capabilities.json
525
+ if (capabilitiesContent && pattern.test(capabilitiesContent)) {
526
+ if (!info.files.includes('capabilities.json')) {
527
+ info.files.push('capabilities.json');
528
+ }
529
+ info.used = true;
530
+ }
531
+ }
532
+ }
533
+ usageMap.set(api.name, info);
534
+ }
535
+ return usageMap;
536
+ }
537
+ export async function getAvailableApis(category, rootPath) {
538
+ const filterCategory = category.toLowerCase();
539
+ let apis = AVAILABLE_APIS;
540
+ if (filterCategory !== 'all') {
541
+ apis = AVAILABLE_APIS.filter(api => api.category === filterCategory);
542
+ }
543
+ if (apis.length === 0) {
544
+ return `No APIs found for category: ${category}
545
+
546
+ Available categories:
547
+ - **data**: Data loading and persistence
548
+ - **formatting**: Colors, themes, and format pane
549
+ - **interaction**: Selection, tooltips, context menu, drill-down
550
+ - **utility**: Localization, storage, events, dialogs
551
+ - **all**: Show all APIs`;
552
+ }
553
+ // Scan project for API usage if rootPath is provided
554
+ let usageMap = null;
555
+ if (rootPath) {
556
+ try {
557
+ usageMap = await scanProjectForApiUsage(rootPath);
558
+ }
559
+ catch {
560
+ // If scanning fails, continue without usage info
561
+ }
562
+ }
563
+ let output = `# 🔌 Power BI Visual APIs\n\n`;
564
+ if (filterCategory !== 'all') {
565
+ output += `Showing APIs in category: **${filterCategory}**\n\n`;
566
+ }
567
+ if (usageMap) {
568
+ const usedCount = Array.from(usageMap.values()).filter(u => u.used).length;
569
+ output += `**Project scan**: ${usedCount} of ${AVAILABLE_APIS.length} APIs detected in use\n\n`;
570
+ }
571
+ // Group by category
572
+ const categories = ['data', 'formatting', 'interaction', 'utility'];
573
+ for (const cat of categories) {
574
+ const catApis = apis.filter(api => api.category === cat);
575
+ if (catApis.length === 0)
576
+ continue;
577
+ const catEmoji = {
578
+ data: '📊',
579
+ formatting: '🎨',
580
+ interaction: '🖱️',
581
+ utility: '🔧'
582
+ }[cat];
583
+ output += `## ${catEmoji} ${cat.charAt(0).toUpperCase() + cat.slice(1)} APIs\n\n`;
584
+ for (const api of catApis) {
585
+ const usage = usageMap?.get(api.name);
586
+ const statusIcon = usage ? (usage.used ? '✅' : '❌') : '';
587
+ output += `### ${statusIcon} \`${api.name}\`\n`;
588
+ output += `${api.description}\n\n`;
589
+ output += `- **Minimum API Version**: ${api.minApiVersion}\n`;
590
+ if (usage?.used && usage.files.length > 0) {
591
+ output += `- **Used in**: ${usage.files.join(', ')}\n`;
592
+ }
593
+ else if (usage && !usage.used) {
594
+ output += `- **Status**: Not used in this project\n`;
595
+ }
596
+ if (api.docsUrl) {
597
+ output += `- **Documentation**: ${api.docsUrl}\n`;
598
+ }
599
+ if (api.example) {
600
+ output += `\n**Example:**\n\`\`\`typescript\n${api.example}\n\`\`\`\n`;
601
+ }
602
+ output += '\n';
603
+ }
604
+ }
605
+ output += `---\n`;
606
+ output += `Full API reference: https://learn.microsoft.com/power-bi/developer/visuals/visuals-api\n`;
607
+ return output;
608
+ }