pptb-standard-sample-tool 1.0.3 → 1.0.5

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
@@ -11,6 +11,7 @@ This sample demonstrates:
11
11
  - Notifications (success, info, warning, error)
12
12
  - Clipboard operations
13
13
  - File save dialogs
14
+ - Tool settings storage (save/load/clear)
14
15
  - Theme detection
15
16
  - Terminal creation and command execution
16
17
  - Event subscription and handling
@@ -100,6 +101,7 @@ html-sample/
100
101
  **Query Records:**
101
102
  - FetchXML query to retrieve top 10 accounts
102
103
  - Display results with formatting
104
+ - If a FetchXML is saved in Tool Settings, the Query button will use that instead of the default
103
105
 
104
106
  **CRUD Operations:**
105
107
  - Create new account records
@@ -174,6 +176,23 @@ try {
174
176
 
175
177
  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
178
 
179
+ ### Tool Settings Storage
180
+
181
+ Use the tool settings API to persist user preferences and configuration for your tool. This storage is scoped per tool.
182
+
183
+ ```typescript
184
+ // Save a setting
185
+ await toolboxAPI.settings.set('demo.fetchxml', myFetchXmlString);
186
+
187
+ // Read a setting
188
+ const saved = await toolboxAPI.settings.get('demo.fetchxml');
189
+
190
+ // Delete a setting
191
+ await toolboxAPI.settings.delete('demo.fetchxml');
192
+ ```
193
+
194
+ In this sample, the “Tool Settings” section lets you save a FetchXML snippet. The “Query Top 10 Accounts” button will use the saved FetchXML if present, otherwise it falls back to the default.
195
+
177
196
  ### ToolBox API
178
197
 
179
198
  ```typescript
package/dist/app.js CHANGED
@@ -31,6 +31,8 @@ async function initialize() {
31
31
  setupEventHandlers();
32
32
  // Apply theme
33
33
  await applyTheme();
34
+ // Load any previously saved setting into UI
35
+ await loadToolSetting();
34
36
  log('Tool initialized successfully', 'success');
35
37
  }
36
38
  catch (error) {
@@ -138,6 +140,9 @@ function setupEventHandlers() {
138
140
  // Advanced utilities demos
139
141
  document.getElementById('parallel-demo-btn')?.addEventListener('click', demoExecuteParallel);
140
142
  document.getElementById('loading-demo-btn')?.addEventListener('click', demoLoading);
143
+ // Settings buttons
144
+ document.getElementById('load-setting-btn')?.addEventListener('click', loadToolSetting);
145
+ document.getElementById('save-setting-btn')?.addEventListener('click', saveToolSetting);
141
146
  }
142
147
  /**
143
148
  * Show notification
@@ -318,17 +323,19 @@ async function queryAccounts() {
318
323
  const output = document.getElementById('query-output');
319
324
  if (output)
320
325
  output.textContent = 'Querying accounts...\n';
321
- const fetchXml = `
326
+ // If user saved a FetchXML in settings, prefer that; otherwise use default
327
+ const saved = await getSetting('demo.fetchxml');
328
+ const fetchXml = (saved && saved.trim().length > 0) ? saved : `
322
329
  <fetch top="10">
323
- <entity name="account">
324
- <attribute name="name" />
325
- <attribute name="accountid" />
326
- <attribute name="emailaddress1" />
327
- <attribute name="telephone1" />
328
- <order attribute="name" />
329
- </entity>
330
+ <entity name="account">
331
+ <attribute name="name" />
332
+ <attribute name="accountid" />
333
+ <attribute name="emailaddress1" />
334
+ <attribute name="telephone1" />
335
+ <order attribute="name" />
336
+ </entity>
330
337
  </fetch>
331
- `.trim();
338
+ `.trim();
332
339
  const result = await dataverse.fetchXmlQuery(fetchXml);
333
340
  if (output) {
334
341
  output.textContent = `Found ${result.value.length} account(s):\n\n`;
@@ -531,6 +538,68 @@ function clearLog() {
531
538
  logDiv.innerHTML = '';
532
539
  }
533
540
  }
541
+ // -----------------------------
542
+ // Tool Settings helpers & demos
543
+ // -----------------------------
544
+ const SETTINGS_KEY = 'demo.fetchxml';
545
+ async function getSetting(key) {
546
+ try {
547
+ // Tool settings are scoped to the tool; implementation provided by the host app
548
+ // API shape (based on docs): toolbox.settings.get(key)
549
+ const value = await toolbox.settings?.getSettings?.(key);
550
+ return value;
551
+ }
552
+ catch (error) {
553
+ log(`Error reading setting: ${error.message}`, 'error');
554
+ return undefined;
555
+ }
556
+ }
557
+ async function setSetting(key, value) {
558
+ try {
559
+ await toolbox.settings?.setSetting?.(key, value);
560
+ }
561
+ catch (error) {
562
+ log(`Error saving setting: ${error.message}`, 'error');
563
+ throw error;
564
+ }
565
+ }
566
+ async function loadToolSetting() {
567
+ const textarea = document.getElementById('settings-fetchxml');
568
+ const output = document.getElementById('settings-output');
569
+ try {
570
+ const val = await getSetting(SETTINGS_KEY);
571
+ if (textarea)
572
+ textarea.value = val || '';
573
+ if (output)
574
+ output.textContent = val ? 'Loaded saved FetchXML from settings.' : 'No saved FetchXML found.';
575
+ log('Loaded tool setting', 'info');
576
+ }
577
+ catch (error) {
578
+ if (output)
579
+ output.textContent = `Error loading setting: ${error.message}`;
580
+ }
581
+ }
582
+ async function saveToolSetting() {
583
+ const textarea = document.getElementById('settings-fetchxml');
584
+ const output = document.getElementById('settings-output');
585
+ const value = (textarea?.value || '').trim();
586
+ if (!value) {
587
+ await showNotification('Nothing to save', 'Enter FetchXML before saving.', 'warning');
588
+ return;
589
+ }
590
+ try {
591
+ await setSetting(SETTINGS_KEY, value);
592
+ if (output)
593
+ output.textContent = 'Saved FetchXML to tool settings.';
594
+ await showNotification('Setting Saved', 'Your FetchXML has been saved.', 'success');
595
+ log('Saved tool setting', 'success');
596
+ }
597
+ catch (error) {
598
+ if (output)
599
+ output.textContent = `Error saving setting: ${error.message}`;
600
+ await showNotification('Save Failed', error.message, 'error');
601
+ }
602
+ }
534
603
  /**
535
604
  * Demonstrate executeParallel utility by performing three Dataverse operations in parallel.
536
605
  * Falls back gracefully if no connection is available.
@@ -549,7 +618,7 @@ async function demoExecuteParallel() {
549
618
  // Prepare lightweight FetchXML queries (top 1 / top 3) for demo purposes
550
619
  const accountFetchXml = `<fetch top="1"><entity name="account"><attribute name="name" /><attribute name="accountid" /></entity></fetch>`;
551
620
  const contactFetchXml = `<fetch top="1"><entity name="contact"><attribute name="fullname" /><attribute name="contactid" /></entity></fetch>`;
552
- const userFetchXml = `<fetch top="3"><entity name="systemuser"><attribute name="name" /><attribute name="systemuserid" /></entity></fetch>`;
621
+ const userFetchXml = `<fetch top="3"><entity name="systemuser"><attribute name="fullname" /><attribute name="systemuserid" /></entity></fetch>`;
553
622
  log('Starting parallel Dataverse queries', 'info');
554
623
  const [accounts, contacts, users] = await toolbox.utils.executeParallel(dataverse.fetchXmlQuery(accountFetchXml), dataverse.fetchXmlQuery(contactFetchXml), dataverse.fetchXmlQuery(userFetchXml));
555
624
  if (output) {
package/dist/index.html CHANGED
@@ -68,6 +68,20 @@
68
68
  <!-- Dataverse API Examples -->
69
69
  <section class="card">
70
70
  <h2>💾 Dataverse API Examples</h2>
71
+
72
+ <div class="example-group">
73
+ <h3>Tool Settings</h3>
74
+ <p style="margin:4px 0 10px;font-size:12px;opacity:.85">Persist simple configuration values per tool instance using the Tool Settings storage API.</p>
75
+ <div class="input-group">
76
+ <label for="settings-fetchxml">Saved FetchXML (used for Account Query demo if present):</label>
77
+ <textarea id="settings-fetchxml" style="width:100%;min-height:110px;padding:10px;border:2px solid #e0e0e0;border-radius:6px;font-family:monospace;font-size:12px;line-height:1.4" placeholder="Enter FetchXML here and click Save Setting"></textarea>
78
+ </div>
79
+ <div class="button-group">
80
+ <button id="load-setting-btn" class="btn">Load Setting</button>
81
+ <button id="save-setting-btn" class="btn btn-primary">Save Setting</button>
82
+ </div>
83
+ <div id="settings-output" class="output"></div>
84
+ </div>
71
85
 
72
86
  <div class="example-group">
73
87
  <h3>Query Records</h3>
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pptb-standard-sample-tool",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pptb-standard-sample-tool",
9
- "version": "1.0.1",
9
+ "version": "1.0.4",
10
10
  "license": "GPL-3.0",
11
11
  "devDependencies": {
12
12
  "@pptb/types": "^1.0.8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptb-standard-sample-tool",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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",