pptb-standard-sample-tool 0.1.9 → 1.0.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.
package/README.md CHANGED
@@ -148,6 +148,32 @@ const dataverse: typeof window.dataverseAPI = window.dataverseAPI;
148
148
 
149
149
  ## API Usage Examples
150
150
 
151
+ ### Advanced Utilities
152
+
153
+ Below demonstrates using `executeParallel` to run multiple Dataverse operations concurrently, and wrapping work with `showLoading` / `hideLoading`:
154
+
155
+ ```typescript
156
+ // Execute multiple operations in parallel
157
+ const [account, contact, opportunities] = await toolboxAPI.utils.executeParallel(
158
+ dataverseAPI.retrieve('account', accountId, ['name']),
159
+ dataverseAPI.retrieve('contact', contactId, ['fullname']),
160
+ dataverseAPI.fetchXmlQuery(opportunityFetchXml)
161
+ );
162
+ console.log('All data fetched:', account, contact, opportunities);
163
+
164
+ // Show loading screen during operations
165
+ await toolboxAPI.utils.showLoading('Processing data...');
166
+ try {
167
+ // Perform operations
168
+ await processData();
169
+ } finally {
170
+ // Always hide loading
171
+ await toolboxAPI.utils.hideLoading();
172
+ }
173
+ ```
174
+
175
+ In this HTML sample, the "Run Parallel Demo" button issues three light FetchXML queries simultaneously using `toolbox.utils.executeParallel`, and the "Run Loading Demo" button shows a loading overlay while either performing a quick query (if connected) or simulating work.
176
+
151
177
  ### ToolBox API
152
178
 
153
179
  ```typescript
package/dist/app.js CHANGED
@@ -135,6 +135,9 @@ function setupEventHandlers() {
135
135
  document.getElementById('get-metadata-btn')?.addEventListener('click', getContactMetadata);
136
136
  // Clear log button
137
137
  document.getElementById('clear-log-btn')?.addEventListener('click', clearLog);
138
+ // Advanced utilities demos
139
+ document.getElementById('parallel-demo-btn')?.addEventListener('click', demoExecuteParallel);
140
+ document.getElementById('loading-demo-btn')?.addEventListener('click', demoLoading);
138
141
  }
139
142
  /**
140
143
  * Show notification
@@ -469,7 +472,8 @@ async function getContactMetadata() {
469
472
  const output = document.getElementById('metadata-output');
470
473
  if (output)
471
474
  output.textContent = 'Retrieving metadata...\n';
472
- const metadata = await dataverse.getEntityMetadata('contact');
475
+ // Adjusted to match current API signature (logical name, includeAttributes?)
476
+ const metadata = await dataverse.getEntityMetadata('contact', true);
473
477
  if (output) {
474
478
  output.textContent = 'Contact Entity Metadata:\n\n';
475
479
  output.textContent += `Logical Name: ${metadata.LogicalName}\n`;
@@ -527,6 +531,86 @@ function clearLog() {
527
531
  logDiv.innerHTML = '';
528
532
  }
529
533
  }
534
+ /**
535
+ * Demonstrate executeParallel utility by performing three Dataverse operations in parallel.
536
+ * Falls back gracefully if no connection is available.
537
+ */
538
+ async function demoExecuteParallel() {
539
+ const output = document.getElementById('parallel-output');
540
+ if (output)
541
+ output.textContent = 'Running parallel operations...\n';
542
+ if (!currentConnection) {
543
+ if (output)
544
+ output.textContent += 'No active Dataverse connection.\n';
545
+ await showNotification('No Connection', 'Connect to a Dataverse environment to run the parallel demo', 'warning');
546
+ return;
547
+ }
548
+ try {
549
+ // Prepare lightweight FetchXML queries (top 1 / top 3) for demo purposes
550
+ const accountFetchXml = `<fetch top="1"><entity name="account"><attribute name="name" /><attribute name="accountid" /></entity></fetch>`;
551
+ const contactFetchXml = `<fetch top="1"><entity name="contact"><attribute name="fullname" /><attribute name="contactid" /></entity></fetch>`;
552
+ const opportunityFetchXml = `<fetch top="3"><entity name="opportunity"><attribute name="name" /><attribute name="opportunityid" /></entity></fetch>`;
553
+ log('Starting parallel Dataverse queries', 'info');
554
+ const [accounts, contacts, opportunities] = await toolbox.utils.executeParallel(dataverse.fetchXmlQuery(accountFetchXml), dataverse.fetchXmlQuery(contactFetchXml), dataverse.fetchXmlQuery(opportunityFetchXml));
555
+ if (output) {
556
+ output.textContent += 'All operations completed!\n\n';
557
+ output.textContent += `Accounts Returned: ${accounts.value.length}\n`;
558
+ accounts.value.forEach((a) => output.textContent += ` • ${a.name} (${a.accountid})\n`);
559
+ output.textContent += `\nContacts Returned: ${contacts.value.length}\n`;
560
+ contacts.value.forEach((c) => output.textContent += ` • ${c.fullname} (${c.contactid})\n`);
561
+ output.textContent += `\nOpportunities Returned: ${opportunities.value.length}\n`;
562
+ opportunities.value.forEach((o) => output.textContent += ` • ${o.name} (${o.opportunityid})\n`);
563
+ }
564
+ await showNotification('Parallel Complete', 'Fetched accounts, contacts & opportunities', 'success');
565
+ log('Parallel queries finished successfully', 'success');
566
+ }
567
+ catch (error) {
568
+ if (output)
569
+ output.textContent += `Error: ${error.message}\n`;
570
+ log(`Parallel query error: ${error.message}`, 'error');
571
+ await showNotification('Parallel Error', error.message, 'error');
572
+ }
573
+ }
574
+ /**
575
+ * Demonstrate showLoading/hideLoading utilities wrapping async work.
576
+ */
577
+ async function demoLoading() {
578
+ const output = document.getElementById('parallel-output');
579
+ if (output)
580
+ output.textContent = 'Showing loading screen...\n';
581
+ try {
582
+ await toolbox.utils.showLoading('Processing data...');
583
+ log('Loading screen displayed', 'info');
584
+ // Simulate async work or perform a lightweight query
585
+ if (currentConnection) {
586
+ const fetchXml = `<fetch top="2"><entity name="account"><attribute name="name" /></entity></fetch>`;
587
+ const result = await dataverse.fetchXmlQuery(fetchXml);
588
+ if (output) {
589
+ output.textContent += `Fetched ${result.value.length} account(s) during loading:\n`;
590
+ result.value.forEach((a) => output.textContent += ` • ${a.name}\n`);
591
+ }
592
+ }
593
+ else {
594
+ // Fallback simulated delay
595
+ await new Promise(r => setTimeout(r, 1500));
596
+ if (output)
597
+ output.textContent += 'Simulated work (no connection).\n';
598
+ }
599
+ }
600
+ catch (error) {
601
+ if (output)
602
+ output.textContent += `Error during loading demo: ${error.message}\n`;
603
+ log(`Loading demo error: ${error.message}`, 'error');
604
+ await showNotification('Loading Demo Error', error.message, 'error');
605
+ }
606
+ finally {
607
+ await toolbox.utils.hideLoading();
608
+ if (output)
609
+ output.textContent += '\nLoading screen hidden.';
610
+ log('Loading screen hidden', 'info');
611
+ await showNotification('Loading Complete', 'Demo finished', 'success');
612
+ }
613
+ }
530
614
  // Initialize when DOM is ready
531
615
  if (document.readyState === 'loading') {
532
616
  document.addEventListener('DOMContentLoaded', initialize);
package/dist/index.html CHANGED
@@ -44,6 +44,16 @@
44
44
  </div>
45
45
  </div>
46
46
 
47
+ <div class="example-group">
48
+ <h3>Advanced Utilities</h3>
49
+ <p style="margin:4px 0 8px; font-size:12px; opacity:.8;">Demonstrates <code>executeParallel</code>, <code>showLoading</code> & <code>hideLoading</code>.</p>
50
+ <div class="button-group">
51
+ <button id="parallel-demo-btn" class="btn btn-primary">Run Parallel Demo</button>
52
+ <button id="loading-demo-btn" class="btn btn-secondary">Run Loading Demo</button>
53
+ </div>
54
+ <div id="parallel-output" class="output"></div>
55
+ </div>
56
+
47
57
  <div class="example-group">
48
58
  <h3>Terminal</h3>
49
59
  <div class="button-group">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptb-standard-sample-tool",
3
- "version": "0.1.9",
3
+ "version": "1.0.0",
4
4
  "displayName": "HTML Sample Tool",
5
5
  "description": "A sample Power Platform Tool Box tool built with HTML, CSS, and TypeScript",
6
6
  "main": "index.html",
@@ -29,7 +29,7 @@
29
29
  "watch": "tsc --watch"
30
30
  },
31
31
  "devDependencies": {
32
- "@pptb/types": "^1.0.1",
32
+ "@pptb/types": "^1.0.8",
33
33
  "typescript": "^5.0.0",
34
34
  "shx": "^0.4.0"
35
35
  },