pptb-standard-sample-tool 0.0.11 → 0.1.2

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
@@ -1,141 +1,237 @@
1
- # PowerPlatform Example Tool
1
+ # HTML Sample Tool
2
2
 
3
- A complete example tool demonstrating the HTML-first architecture with TypeScript for PowerPlatform ToolBox.
3
+ A complete example tool for Power Platform Tool Box built with HTML, CSS, and TypeScript.
4
4
 
5
5
  ## Features
6
6
 
7
- - TypeScript with full type safety
8
- - ✅ HTML+CSS+JS architecture
9
- - ✅ Access to ToolBox API via `window.toolboxAPI`
10
- - Connection URL and access token handling
11
- - Event subscription and handling
12
- - Interactive UI with notifications, clipboard, and data display
7
+ This sample demonstrates:
8
+
9
+ - ✅ **ToolBox API Integration**
10
+ - Connection management and status display
11
+ - Notifications (success, info, warning, error)
12
+ - Clipboard operations
13
+ - File save dialogs
14
+ - Theme detection
15
+ - Terminal creation and command execution
16
+ - Event subscription and handling
17
+
18
+ - ✅ **Dataverse API Usage**
19
+ - FetchXML queries
20
+ - CRUD operations (Create, Read, Update, Delete)
21
+ - Entity metadata retrieval
22
+ - Error handling
23
+
24
+ - ✅ **Best Practices**
25
+ - TypeScript with full type safety
26
+ - Event-driven architecture
27
+ - Proper error handling
28
+ - Clean, modern UI design
29
+ - Responsive layout
13
30
 
14
- ## Structure
31
+ ## Installation
15
32
 
16
- ```
17
- example-tool/
18
- ├── src/
19
- │ ├── index.html # Main UI
20
- │ ├── index.ts # Tool logic (TypeScript)
21
- │ └── styles.css # Styling
22
- ├── dist/ # Compiled output (after build)
23
- │ ├── index.html
24
- │ ├── index.js
25
- │ ├── index.js.map
26
- │ └── styles.css
27
- ├── package.json
28
- ├── tsconfig.json
29
- └── README.md
30
- ```
33
+ ### Prerequisites
31
34
 
32
- ## Installation
35
+ - Node.js 18 or higher
36
+ - Power Platform Tool Box desktop application
33
37
 
34
- Install dependencies:
38
+ ### Install Dependencies
35
39
 
36
40
  ```bash
37
41
  npm install
38
42
  ```
39
43
 
40
- ## Development
41
-
42
- Build the tool:
44
+ ### Build
43
45
 
44
46
  ```bash
45
47
  npm run build
46
48
  ```
47
49
 
48
- Watch mode for development:
50
+ This compiles the TypeScript source in `src/` to JavaScript in `dist/`.
49
51
 
50
- ```bash
51
- npm run watch
52
+ ## Project Structure
53
+
54
+ ```
55
+ html-sample/
56
+ ├── src/
57
+ │ └── app.ts # Main application logic (TypeScript)
58
+ ├── index.html # Main HTML file (entry point)
59
+ ├── styles.css # Stylesheet
60
+ ├── package.json # Package configuration
61
+ ├── tsconfig.json # TypeScript configuration
62
+ └── README.md # This file
52
63
  ```
53
64
 
54
- ## Usage in ToolBox
65
+ ## Usage
55
66
 
56
- 1. Install the tool in ToolBox:
57
- ```javascript
58
- await window.toolboxAPI.installTool('@powerplatform/example-tool');
59
- ```
67
+ ### Install in Power Platform Tool Box
60
68
 
61
- 2. Load the tool:
62
- ```javascript
63
- await window.toolboxAPI.loadTool('@powerplatform/example-tool');
64
- ```
69
+ 1. Open Power Platform Tool Box
70
+ 2. Go to Tools section
71
+ 3. Click "Install Tool"
72
+ 4. Enter the path to this directory or publish to npm and use the package name
65
73
 
66
- 3. Get the tool's HTML with connection context:
67
- ```javascript
68
- const html = await window.toolboxAPI.getToolWebviewHtml(
69
- '@powerplatform/example-tool',
70
- 'https://your-env.crm.dynamics.com',
71
- 'your-access-token'
72
- );
73
- ```
74
+ ### Features Overview
74
75
 
75
- 4. Render the HTML in a webview.
76
+ #### Connection Status
77
+ - Shows current Dataverse connection details
78
+ - Displays environment type (Production, Sandbox, Dev)
79
+ - Updates automatically when connection changes
76
80
 
77
- ## API Usage
81
+ #### ToolBox API Examples
78
82
 
79
- The tool demonstrates various ToolBox API features:
83
+ **Notifications:**
84
+ - Test different notification types
85
+ - Success, info, warning, and error messages
80
86
 
81
- ### Getting Connection Context
87
+ **Utilities:**
88
+ - Copy data to clipboard
89
+ - Get current theme (light/dark)
90
+ - Save data to file with native dialog
82
91
 
83
- ```typescript
84
- const context = await window.toolboxAPI.getToolContext();
85
- console.log(context.connectionUrl);
86
- console.log(context.accessToken);
92
+ **Terminal:**
93
+ - Create isolated terminal instances
94
+ - Execute shell commands
95
+ - View command output
96
+ - Close terminal when done
97
+
98
+ #### Dataverse API Examples
99
+
100
+ **Query Records:**
101
+ - FetchXML query to retrieve top 10 accounts
102
+ - Display results with formatting
103
+
104
+ **CRUD Operations:**
105
+ - Create new account records
106
+ - Update existing records
107
+ - Delete records
108
+ - Full error handling
109
+
110
+ **Metadata:**
111
+ - Retrieve entity metadata
112
+ - Display entity information and attributes
113
+
114
+ #### Event Log
115
+ - Real-time event logging
116
+ - Color-coded by severity
117
+ - Timestamp for each entry
118
+ - Clear log functionality
119
+
120
+ ## Development
121
+
122
+ ### Watch Mode
123
+
124
+ During development, you can use watch mode to automatically recompile on changes:
125
+
126
+ ```bash
127
+ npm run watch
87
128
  ```
88
129
 
89
- ### Showing Notifications
130
+ ### Type Safety
131
+
132
+ This tool uses TypeScript with the `@pptb/types` package for full type safety:
90
133
 
91
134
  ```typescript
92
- await window.toolboxAPI.showNotification({
93
- title: 'Success',
94
- body: 'Operation completed',
95
- type: 'success'
96
- });
135
+ /// <reference types="@pptb/types" />
136
+
137
+ // Type-safe API access
138
+ const toolbox: typeof window.toolboxAPI = window.toolboxAPI;
139
+ const dataverse: typeof window.dataverseAPI = window.dataverseAPI;
97
140
  ```
98
141
 
99
- ### Subscribing to Events
142
+ ### Customization
143
+
144
+ 1. **Modify UI:** Edit `index.html` and `styles.css`
145
+ 2. **Add Features:** Update `src/app.ts`
146
+ 3. **Rebuild:** Run `npm run build`
147
+ 4. **Reload Tool:** In Power Platform Tool Box, close and reopen the tool
148
+
149
+ ## API Usage Examples
150
+
151
+ ### ToolBox API
100
152
 
101
153
  ```typescript
102
- window.toolboxAPI.onToolboxEvent((event, payload) => {
103
- console.log('Event:', payload.event);
104
- console.log('Data:', payload.data);
154
+ // Show notification
155
+ await toolbox.utils.showNotification({
156
+ title: 'Success',
157
+ body: 'Operation completed',
158
+ type: 'success',
159
+ duration: 3000
160
+ });
161
+
162
+ // Get active connection
163
+ const connection = await toolbox.connections.getActiveConnection();
164
+
165
+ // Create terminal
166
+ const terminal = await toolbox.terminal.create({
167
+ name: 'My Terminal'
168
+ });
169
+
170
+ // Subscribe to events
171
+ toolbox.events.on((event, payload) => {
172
+ console.log('Event:', payload.event, payload.data);
105
173
  });
106
174
  ```
107
175
 
108
- ### Accessing Connections
176
+ ### Dataverse API
109
177
 
110
178
  ```typescript
111
- const connections = await window.toolboxAPI.getConnections();
112
- const active = await window.toolboxAPI.getActiveConnection();
179
+ // Query with FetchXML
180
+ const result = await dataverse.fetchXmlQuery(`
181
+ <fetch top="10">
182
+ <entity name="account">
183
+ <attribute name="name" />
184
+ </entity>
185
+ </fetch>
186
+ `);
187
+
188
+ // Create record
189
+ const account = await dataverse.create('account', {
190
+ name: 'Contoso Ltd',
191
+ emailaddress1: 'info@contoso.com'
192
+ });
193
+
194
+ // Update record
195
+ await dataverse.update('account', accountId, {
196
+ telephone1: '555-0100'
197
+ });
198
+
199
+ // Delete record
200
+ await dataverse.delete('account', accountId);
201
+
202
+ // Get metadata
203
+ const metadata = await dataverse.getEntityMetadata('account');
113
204
  ```
114
205
 
115
- ## Type Definitions
206
+ ## Troubleshooting
207
+
208
+ ### Build Errors
209
+
210
+ If you encounter TypeScript errors:
211
+ 1. Ensure `@pptb/types` is installed: `npm install`
212
+ 2. Check TypeScript version: `tsc --version` (should be 5.x)
213
+ 3. Clean and rebuild: `rm -rf dist && npm run build`
214
+
215
+ ### API Not Available
116
216
 
117
- This tool includes TypeScript type definitions in the `types/` folder. The type definitions provide:
217
+ If `toolboxAPI` or `dataverseAPI` is undefined:
218
+ - The tool must be loaded within Power Platform Tool Box
219
+ - These APIs are injected by the toolboxAPIBridge
220
+ - They are not available in a standalone browser
118
221
 
119
- - Full ToolBoxAPI interface
120
- - Event type definitions
121
- - Connection and Tool interfaces
122
- - Notification options
123
- - And more...
222
+ ### Connection Issues
124
223
 
125
- ## TypeScript Configuration
224
+ If connection is null:
225
+ - Open Power Platform Tool Box
226
+ - Create a connection to a Dataverse environment
227
+ - The tool will automatically detect the connection
126
228
 
127
- The tool uses modern TypeScript configuration:
229
+ ## Resources
128
230
 
129
- - **Target**: ES2022
130
- - **Module**: ES2022
131
- - **Module Resolution**: bundler (modern strategy)
132
- - **Strict Mode**: Enabled with additional safety checks:
133
- - `noUnusedLocals`: Warns about unused local variables
134
- - `noUnusedParameters`: Warns about unused function parameters
135
- - `noFallthroughCasesInSwitch`: Ensures all switch cases handle control flow
136
- - `useDefineForClassFields`: Modern class field semantics
137
- - `moduleDetection`: Force module detection
231
+ - [Tool Development Guide](../../docs/TOOL_DEVELOPMENT.md)
232
+ - [API Reference](../../packages/README.md)
233
+ - [Power Platform Tool Box Repository](https://github.com/PowerPlatform-ToolBox/desktop-app)
138
234
 
139
235
  ## License
140
236
 
141
- MIT
237
+ GPL-3.0 - See LICENSE file in repository root