@pptb/types 1.0.0 → 1.0.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,6 +1,6 @@
1
1
  # @pptb/types
2
2
 
3
- TypeScript type definitions for Power Platform Tool Box API.
3
+ TypeScript type definitions for Power Platform Tool Box APIs.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,238 +8,339 @@ TypeScript type definitions for Power Platform Tool Box API.
8
8
  npm install --save-dev @pptb/types
9
9
  ```
10
10
 
11
+ ## Overview
12
+
13
+ The `@pptb/types` package provides TypeScript definitions for two main APIs:
14
+
15
+ 1. **ToolBox API** (`window.toolboxAPI`) - Core platform features (connections, utilities, terminals, events)
16
+ 2. **Dataverse API** (`window.dataverseAPI`) - Microsoft Dataverse Web API operations
17
+
11
18
  ## Usage
12
19
 
13
- ### In your TypeScript tool
20
+ ### Include all type definitions
14
21
 
15
22
  ```typescript
16
23
  /// <reference types="@pptb/types" />
17
24
 
18
- // Access the ToolBox API
25
+ // Both APIs are now available
19
26
  const toolbox = window.toolboxAPI;
20
-
21
- // Get connection context
22
- const context = await toolbox.getToolContext();
23
- console.log("Connection URL:", context.connectionUrl);
24
- console.log("Access Token:", context.accessToken);
25
-
26
- // Subscribe to events
27
- toolbox.onToolboxEvent((event, payload) => {
28
- console.log("Event:", payload.event, "Data:", payload.data);
29
- });
30
-
31
- // Show notifications
32
- await toolbox.showNotification({
33
- title: "Success",
34
- body: "Operation completed successfully",
35
- type: "success",
36
- });
27
+ const dataverse = window.dataverseAPI;
37
28
  ```
38
29
 
39
- ### Type-safe event handling
30
+ ### Include specific API types
40
31
 
41
32
  ```typescript
42
- toolbox.onToolboxEvent((event, payload) => {
43
- switch (payload.event) {
44
- case "connection:updated":
45
- console.log("Connection updated:", payload.data);
46
- break;
47
- case "tool:loaded":
48
- console.log("Tool loaded:", payload.data);
49
- break;
50
- }
51
- });
52
- ```
53
-
54
- ## API Reference
55
-
56
- Below are the APIs exposed to tools via `window.toolboxAPI`. All methods return Promises and are safe to `await` in modern browsers/Electron webviews.
57
-
58
- ### Settings
33
+ // Only ToolBox API types
34
+ /// <reference types="@pptb/types/toolboxAPI" />
59
35
 
60
- - getUserSettings(): Promise<any>
36
+ // Only Dataverse API types
37
+ /// <reference types="@pptb/types/dataverseAPI" />
38
+ ```
61
39
 
62
- - Returns the entire user settings object stored by the ToolBox.
40
+ ## ToolBox API Examples
63
41
 
64
- - updateUserSettings(settings: any): Promise<void>
42
+ The ToolBox API provides organized namespaces for different functionality:
65
43
 
66
- - Merges and persists the provided settings object into the user settings store.
44
+ ### Connections
67
45
 
68
- - getSetting(key: string): Promise<any>
46
+ ```typescript
47
+ // Get the active Dataverse connection
48
+ const connection = await toolboxAPI.connections.getActiveConnection();
49
+ if (connection) {
50
+ console.log("Connected to:", connection.url);
51
+ console.log("Environment:", connection.environment);
52
+ }
53
+ ```
69
54
 
70
- - Retrieves a single setting value by key from user settings.
55
+ ### Utilities
71
56
 
72
- - setSetting(key: string, value: any): Promise<void>
73
- - Sets or updates a single setting key/value in user settings.
57
+ ```typescript
58
+ // Show a notification
59
+ await toolboxAPI.utils.showNotification({
60
+ title: "Success",
61
+ body: "Operation completed successfully",
62
+ type: "success",
63
+ duration: 3000,
64
+ });
74
65
 
75
- ### Connections
66
+ // Copy to clipboard
67
+ await toolboxAPI.utils.copyToClipboard("Text to copy");
76
68
 
77
- - addConnection(connection: any): Promise<void>
69
+ // Save a file
70
+ const filePath = await toolboxAPI.utils.saveFile("output.json", JSON.stringify(data, null, 2));
71
+ if (filePath) {
72
+ console.log("File saved to:", filePath);
73
+ }
78
74
 
79
- - Adds a new Dataverse connection definition to the ToolBox.
75
+ // Get current theme
76
+ const theme = await toolboxAPI.utils.getCurrentTheme();
77
+ console.log("Current theme:", theme); // "light" or "dark"
78
+ ```
80
79
 
81
- - updateConnection(id: string, updates: any): Promise<void>
80
+ ### Terminal Operations
82
81
 
83
- - Applies partial updates to an existing connection by its id.
82
+ ```typescript
83
+ // Create a terminal (tool ID is automatically determined)
84
+ const terminal = await toolboxAPI.terminal.create({
85
+ name: "My Terminal",
86
+ cwd: "/path/to/directory",
87
+ });
84
88
 
85
- - deleteConnection(id: string): Promise<void>
89
+ // Execute a command
90
+ const result = await toolboxAPI.terminal.execute(terminal.id, "npm install");
91
+ console.log("Exit code:", result.exitCode);
92
+ console.log("Output:", result.output);
86
93
 
87
- - Removes an existing connection by its id.
94
+ // List all terminals for this tool
95
+ const terminals = await toolboxAPI.terminal.list();
88
96
 
89
- - getConnections(): Promise<ToolBox.DataverseConnection[]>
97
+ // Close a terminal
98
+ await toolboxAPI.terminal.close(terminal.id);
99
+ ```
90
100
 
91
- - Returns all saved Dataverse connections.
101
+ ### Events
92
102
 
93
- - setActiveConnection(id: string): Promise<void>
103
+ ```typescript
104
+ // Subscribe to events
105
+ toolboxAPI.events.on((event, payload) => {
106
+ console.log("Event:", payload.event, "Data:", payload.data);
94
107
 
95
- - Marks the specified connection as the active connection for the current session.
108
+ switch (payload.event) {
109
+ case "connection:updated":
110
+ console.log("Connection updated:", payload.data);
111
+ break;
112
+ case "terminal:output":
113
+ console.log("Terminal output:", payload.data);
114
+ break;
115
+ }
116
+ });
96
117
 
97
- - getActiveConnection(): Promise<ToolBox.DataverseConnection | null>
118
+ // Get event history
119
+ const history = await toolboxAPI.events.getHistory(10); // Last 10 events
120
+ ```
98
121
 
99
- - Returns the currently active connection or null if none is active.
122
+ ## Dataverse API Examples
100
123
 
101
- - disconnectConnection(): Promise<void>
102
- - Clears the active connection for the current session.
124
+ The Dataverse API provides direct access to Microsoft Dataverse operations:
103
125
 
104
- ### Tools
126
+ ### CRUD Operations
105
127
 
106
- - getAllTools(): Promise<ToolBox.Tool[]>
128
+ ```typescript
129
+ // Create a record
130
+ const result = await dataverseAPI.create("account", {
131
+ name: "Contoso Ltd",
132
+ emailaddress1: "info@contoso.com",
133
+ telephone1: "555-0100",
134
+ });
135
+ console.log("Created account ID:", result.id);
107
136
 
108
- - Returns all tools known to the ToolBox (installed/managed).
137
+ // Retrieve a record
138
+ const account = await dataverseAPI.retrieve("account", result.id, ["name", "emailaddress1", "telephone1"]);
139
+ console.log("Account name:", account.name);
109
140
 
110
- - getTool(toolId: string): Promise<ToolBox.Tool>
141
+ // Update a record
142
+ await dataverseAPI.update("account", result.id, {
143
+ name: "Updated Account Name",
144
+ description: "Updated description",
145
+ });
111
146
 
112
- - Returns metadata about a specific tool by its id.
147
+ // Delete a record
148
+ await dataverseAPI.delete("account", result.id);
149
+ ```
113
150
 
114
- - loadTool(packageName: string): Promise<ToolBox.Tool>
151
+ ### FetchXML Queries
115
152
 
116
- - Loads a tool (initializes/activates) by npm package name.
153
+ ```typescript
154
+ const fetchXml = `
155
+ <fetch top="10">
156
+ <entity name="account">
157
+ <attribute name="name" />
158
+ <attribute name="emailaddress1" />
159
+ <filter>
160
+ <condition attribute="statecode" operator="eq" value="0" />
161
+ </filter>
162
+ <order attribute="name" />
163
+ </entity>
164
+ </fetch>
165
+ `;
166
+
167
+ const result = await dataverseAPI.fetchXmlQuery(fetchXml);
168
+ console.log(`Found ${result.value.length} records`);
169
+ result.value.forEach((record) => {
170
+ console.log(record.name);
171
+ });
172
+ ```
117
173
 
118
- - unloadTool(toolId: string): Promise<void>
174
+ ### Metadata Operations
119
175
 
120
- - Unloads a tool instance by its id.
176
+ ```typescript
177
+ // Get entity metadata
178
+ const metadata = await dataverseAPI.getEntityMetadata("account");
179
+ console.log("Display Name:", metadata.DisplayName?.LocalizedLabels[0]?.Label);
180
+ console.log("Attributes:", metadata.Attributes?.length);
181
+
182
+ // Get all entities
183
+ const allEntities = await dataverseAPI.getAllEntitiesMetadata();
184
+ console.log(`Total entities: ${allEntities.value.length}`);
185
+ ```
121
186
 
122
- - installTool(packageName: string): Promise<ToolBox.Tool>
187
+ ### Execute Actions/Functions
123
188
 
124
- - Installs a tool from npm (and registers it with the ToolBox).
189
+ ```typescript
190
+ // Execute WhoAmI function
191
+ const whoAmI = await dataverseAPI.execute({
192
+ operationName: "WhoAmI",
193
+ operationType: "function",
194
+ });
195
+ console.log("User ID:", whoAmI.UserId);
196
+
197
+ // Execute bound action
198
+ const result = await dataverseAPI.execute({
199
+ entityName: "account",
200
+ entityId: accountId,
201
+ operationName: "CalculateRollupField",
202
+ operationType: "action",
203
+ parameters: {
204
+ FieldName: "total_revenue",
205
+ },
206
+ });
207
+ ```
125
208
 
126
- - uninstallTool(packageName: string, toolId: string): Promise<void>
209
+ ## API Reference
127
210
 
128
- - Uninstalls a previously installed tool and removes it from the ToolBox.
211
+ The Power Platform Tool Box exposes two main APIs to tools:
129
212
 
130
- - getToolWebviewHtml(packageName: string, connectionUrl?: string, accessToken?: string): Promise<string | null>
213
+ ### ToolBox API (`window.toolboxAPI`)
131
214
 
132
- - Returns an HTML string suitable for a tool's webview. Optional connection credentials can be passed for bootstrapping.
215
+ Core platform features organized into namespaces:
133
216
 
134
- - getToolContext(): Promise<ToolBox.ToolContext>
135
- - Returns the current tool context including `toolId`, `connectionUrl`, and `accessToken` when available.
217
+ #### Connections
136
218
 
137
- ### Tool Settings
219
+ - **getActiveConnection()**: Promise<DataverseConnection | null>
220
+ - Returns the currently active Dataverse connection or null if none is active
138
221
 
139
- - getToolSettings(toolId: string): Promise<any>
222
+ #### Utils
140
223
 
141
- - Returns tool-scoped settings for the specified tool id.
224
+ - **showNotification(options: NotificationOptions)**: Promise<void>
142
225
 
143
- - updateToolSettings(toolId: string, settings: any): Promise<void>
144
- - Merges and persists tool-scoped settings for the specified tool id.
226
+ - Displays a ToolBox notification. `options.type` supports `info | success | warning | error` and `duration` in ms (0 = persistent)
145
227
 
146
- ### Notifications
228
+ - **copyToClipboard(text: string)**: Promise<void>
147
229
 
148
- - showNotification(options: ToolBox.NotificationOptions): Promise<void>
149
- - Displays a ToolBox notification. `options.type` supports `info | success | warning | error` and `duration` in ms (0 = persistent).
230
+ - Copies the provided text into the system clipboard
150
231
 
151
- ### Clipboard
232
+ - **saveFile(defaultPath: string, content: any)**: Promise<string | null>
152
233
 
153
- - copyToClipboard(text: string): Promise<void>
154
- - Copies the provided text into the system clipboard.
234
+ - Opens a save dialog and writes the content. Returns the saved file path or null if canceled
155
235
 
156
- ### File operations
236
+ - **getCurrentTheme()**: Promise<"light" | "dark">
237
+ - Returns the current UI theme setting
157
238
 
158
- - saveFile(defaultPath: string, content: any): Promise<string | null>
159
- - Opens a save dialog and writes the content. Returns the saved file path or null if canceled.
239
+ #### Terminal
160
240
 
161
- ### Terminal operations
241
+ - **create(options: TerminalOptions)**: Promise<Terminal>
162
242
 
163
- - createTerminal(toolId: string, options: ToolBox.TerminalOptions): Promise<ToolBox.Terminal>
243
+ - Creates a new terminal attached to the tool (tool ID is auto-determined)
164
244
 
165
- - Creates a new terminal attached to the tool with the given options (name, shell, cwd, env).
245
+ - **execute(terminalId: string, command: string)**: Promise<TerminalCommandResult>
166
246
 
167
- - executeTerminalCommand(terminalId: string, command: string): Promise<ToolBox.TerminalCommandResult>
247
+ - Executes a command in the specified terminal and returns its result
168
248
 
169
- - Executes a command in the specified terminal and returns its result.
249
+ - **close(terminalId: string)**: Promise<void>
170
250
 
171
- - closeTerminal(terminalId: string): Promise<void>
251
+ - Closes the specified terminal
172
252
 
173
- - Closes the specified terminal.
253
+ - **get(terminalId: string)**: Promise<Terminal | undefined>
174
254
 
175
- - getTerminal(terminalId: string): Promise<ToolBox.Terminal | undefined>
255
+ - Gets a single terminal by id, if it exists
176
256
 
177
- - Gets a single terminal by id, if it exists.
257
+ - **list()**: Promise<Terminal[]>
178
258
 
179
- - getToolTerminals(toolId: string): Promise<ToolBox.Terminal[]>
259
+ - Lists all terminals created by this tool
180
260
 
181
- - Lists all terminals created by a specific tool.
261
+ - **setVisibility(terminalId: string, visible: boolean)**: Promise<void>
262
+ - Shows or hides the terminal UI for the specified terminal id
182
263
 
183
- - getAllTerminals(): Promise<ToolBox.Terminal[]>
264
+ #### Events
184
265
 
185
- - Lists all existing terminals managed by the ToolBox.
266
+ - **getHistory(limit?: number)**: Promise<ToolBoxEventPayload[]>
186
267
 
187
- - setTerminalVisibility(terminalId: string, visible: boolean): Promise<void>
188
- - Shows or hides the terminal UI for the specified terminal id.
268
+ - Returns recent ToolBox events for this tool, newest first. Use `limit` to cap the number of entries
189
269
 
190
- ### Events
270
+ - **on(callback: (event: any, payload: ToolBoxEventPayload) => void)**: void
191
271
 
192
- - getEventHistory(limit?: number): Promise<ToolBox.ToolBoxEventPayload[]>
272
+ - Subscribes to ToolBox events
273
+ - Events available:
274
+ - `tool:loaded` - A tool has been loaded
275
+ - `tool:unloaded` - A tool has been unloaded
276
+ - `connection:created` - A new connection was created
277
+ - `connection:updated` - An existing connection was updated
278
+ - `connection:deleted` - A connection was deleted
279
+ - `notification:shown` - A notification was displayed
280
+ - `terminal:created` - A new terminal was created
281
+ - `terminal:closed` - A terminal was closed
282
+ - `terminal:output` - Terminal produced output
283
+ - `terminal:command:completed` - A terminal command finished executing
284
+ - `terminal:error` - A terminal error occurred
193
285
 
194
- - Returns recent ToolBox events, newest first. Use `limit` to cap the number of entries.
286
+ - **off(callback: (event: any, payload: ToolBoxEventPayload) => void)**: void
287
+ - Removes a previously registered event listener
195
288
 
196
- - onToolboxEvent(callback: (event: any, payload: ToolBox.ToolBoxEventPayload) => void): void
289
+ ### Dataverse API (`window.dataverseAPI`)
197
290
 
198
- - Subscribes to ToolBox events (e.g., `tool:loaded`, `connection:updated`, `terminal:output`).
291
+ Complete HTTP client for interacting with Microsoft Dataverse:
199
292
 
200
- - removeToolboxEventListener(callback: (event: any, payload: ToolBox.ToolBoxEventPayload) => void): void
201
- - Removes a previously registered event listener.
293
+ #### CRUD Operations
202
294
 
203
- ### Auto-update
295
+ - **create(entityLogicalName: string, record: Record<string, unknown>)**: Promise<{id: string, ...}>
204
296
 
205
- - checkForUpdates(): Promise<void>
297
+ - Creates a new record in Dataverse
298
+ - Returns the created record ID and any returned fields
206
299
 
207
- - Triggers an update check.
300
+ - **retrieve(entityLogicalName: string, id: string, columns?: string[])**: Promise<Record<string, unknown>>
208
301
 
209
- - downloadUpdate(): Promise<void>
302
+ - Retrieves a single record by ID
303
+ - Optional columns array to select specific fields
210
304
 
211
- - Starts downloading an available update.
305
+ - **update(entityLogicalName: string, id: string, record: Record<string, unknown>)**: Promise<void>
212
306
 
213
- - quitAndInstall(): Promise<void>
307
+ - Updates an existing record
214
308
 
215
- - Quits the app and installs a downloaded update.
309
+ - **delete(entityLogicalName: string, id: string)**: Promise<void>
310
+ - Deletes a record
216
311
 
217
- - getAppVersion(): Promise<string>
312
+ #### Query Operations
218
313
 
219
- - Returns the current application version.
314
+ - **fetchXmlQuery(fetchXml: string)**: Promise<{value: Record<string, unknown>[], ...}>
220
315
 
221
- - onUpdateChecking(callback: () => void): void
316
+ - Executes a FetchXML query
317
+ - Returns object with value array containing matching records
222
318
 
223
- - Called when an update check has started.
319
+ - **retrieveMultiple(fetchXml: string)**: Promise<{value: Record<string, unknown>[], ...}>
320
+ - Alias for fetchXmlQuery for backward compatibility
224
321
 
225
- - onUpdateAvailable(callback: (info: any) => void): void
322
+ #### Metadata Operations
226
323
 
227
- - Called when an update is available; `info` provides update metadata.
324
+ - **getEntityMetadata(entityLogicalName: string)**: Promise<EntityMetadata>
228
325
 
229
- - onUpdateNotAvailable(callback: () => void): void
326
+ - Retrieves metadata for a specific entity
230
327
 
231
- - Called when no updates are available.
328
+ - **getAllEntitiesMetadata()**: Promise<{value: EntityMetadata[]}>
329
+ - Retrieves metadata for all entities
232
330
 
233
- - onUpdateDownloadProgress(callback: (progress: any) => void): void
331
+ #### Advanced Operations
234
332
 
235
- - Called periodically with download progress information.
333
+ - **execute(request: ExecuteRequest)**: Promise<Record<string, unknown>>
334
+ - Executes a Dataverse Web API action or function
335
+ - Supports both bound and unbound operations
236
336
 
237
- - onUpdateDownloaded(callback: (info: any) => void): void
337
+ ### Security Notes
238
338
 
239
- - Called once an update has been downloaded and is ready to install.
339
+ - **Access Tokens**: Tools do NOT have direct access to access tokens. All Dataverse operations are authenticated automatically by the platform.
340
+ - **Connection Context**: Tools only receive the connection URL, not sensitive credentials.
341
+ - **Secure Storage**: All tokens and secrets are encrypted and managed by the platform.
240
342
 
241
- - onUpdateError(callback: (error: string) => void): void
242
- - Called when an update-related error occurs.
343
+ For detailed examples and best practices, see the [Dataverse API Documentation](../docs/DATAVERSE_API.md).
243
344
 
244
345
  ## Publishing the package to npm
245
346
 
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Power Platform Tool Box - Dataverse API Type Definitions
3
+ *
4
+ * Dataverse Web API exposed to tools via window.dataverseAPI
5
+ */
6
+
7
+ declare namespace DataverseAPI {
8
+ /**
9
+ * FetchXML query result
10
+ */
11
+ export interface FetchXmlResult {
12
+ value: Record<string, unknown>[];
13
+ "@odata.context"?: string;
14
+ "@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"?: string;
15
+ }
16
+
17
+ /**
18
+ * Entity metadata response
19
+ */
20
+ export interface EntityMetadata {
21
+ MetadataId: string;
22
+ LogicalName: string;
23
+ DisplayName?: {
24
+ LocalizedLabels: Array<{ Label: string; LanguageCode: number }>;
25
+ };
26
+ Attributes?: unknown[];
27
+ [key: string]: unknown;
28
+ }
29
+
30
+ /**
31
+ * Entity metadata collection response
32
+ */
33
+ export interface EntityMetadataCollection {
34
+ value: EntityMetadata[];
35
+ }
36
+
37
+ /**
38
+ * Record creation result
39
+ */
40
+ export interface CreateResult {
41
+ id: string;
42
+ [key: string]: unknown;
43
+ }
44
+
45
+ /**
46
+ * Execute operation request
47
+ */
48
+ export interface ExecuteRequest {
49
+ /**
50
+ * Name of the action or function to execute
51
+ */
52
+ operationName: string;
53
+
54
+ /**
55
+ * Type of operation - action or function
56
+ */
57
+ operationType: "action" | "function";
58
+
59
+ /**
60
+ * Entity logical name for bound operations
61
+ */
62
+ entityName?: string;
63
+
64
+ /**
65
+ * Record ID for bound operations
66
+ */
67
+ entityId?: string;
68
+
69
+ /**
70
+ * Parameters to pass to the operation
71
+ */
72
+ parameters?: Record<string, unknown>;
73
+ }
74
+
75
+ /**
76
+ * Dataverse Web API for CRUD operations, queries, and metadata
77
+ */
78
+ export interface API {
79
+ /**
80
+ * Create a new record in Dataverse
81
+ *
82
+ * @param entityLogicalName - Logical name of the entity (e.g., 'account', 'contact')
83
+ * @param record - Record data to create
84
+ * @returns Object containing the created record ID and any returned fields
85
+ *
86
+ * @example
87
+ * const result = await dataverseAPI.create('account', {
88
+ * name: 'Contoso Ltd',
89
+ * emailaddress1: 'info@contoso.com',
90
+ * telephone1: '555-0100'
91
+ * });
92
+ * console.log('Created account ID:', result.id);
93
+ */
94
+ create: (entityLogicalName: string, record: Record<string, unknown>) => Promise<CreateResult>;
95
+
96
+ /**
97
+ * Retrieve a single record by ID
98
+ *
99
+ * @param entityLogicalName - Logical name of the entity
100
+ * @param id - GUID of the record
101
+ * @param columns - Optional array of column names to retrieve (retrieves all if not specified)
102
+ * @returns Object containing the requested record
103
+ *
104
+ * @example
105
+ * const account = await dataverseAPI.retrieve(
106
+ * 'account',
107
+ * 'guid-here',
108
+ * ['name', 'emailaddress1', 'telephone1']
109
+ * );
110
+ * console.log('Account name:', account.name);
111
+ */
112
+ retrieve: (entityLogicalName: string, id: string, columns?: string[]) => Promise<Record<string, unknown>>;
113
+
114
+ /**
115
+ * Update an existing record
116
+ *
117
+ * @param entityLogicalName - Logical name of the entity
118
+ * @param id - GUID of the record
119
+ * @param record - Fields to update
120
+ *
121
+ * @example
122
+ * await dataverseAPI.update('account', 'guid-here', {
123
+ * name: 'Updated Account Name',
124
+ * description: 'Updated description'
125
+ * });
126
+ */
127
+ update: (entityLogicalName: string, id: string, record: Record<string, unknown>) => Promise<void>;
128
+
129
+ /**
130
+ * Delete a record
131
+ *
132
+ * @param entityLogicalName - Logical name of the entity
133
+ * @param id - GUID of the record
134
+ *
135
+ * @example
136
+ * await dataverseAPI.delete('account', 'guid-here');
137
+ */
138
+ delete: (entityLogicalName: string, id: string) => Promise<void>;
139
+
140
+ /**
141
+ * Execute a FetchXML query
142
+ *
143
+ * @param fetchXml - FetchXML query string
144
+ * @returns Object with value array containing matching records
145
+ *
146
+ * @example
147
+ * const fetchXml = `
148
+ * <fetch top="10">
149
+ * <entity name="account">
150
+ * <attribute name="name" />
151
+ * <attribute name="emailaddress1" />
152
+ * <filter>
153
+ * <condition attribute="statecode" operator="eq" value="0" />
154
+ * </filter>
155
+ * <order attribute="name" />
156
+ * </entity>
157
+ * </fetch>
158
+ * `;
159
+ *
160
+ * const result = await dataverseAPI.fetchXmlQuery(fetchXml);
161
+ * console.log(`Found ${result.value.length} records`);
162
+ * result.value.forEach(record => {
163
+ * console.log(record.name);
164
+ * });
165
+ */
166
+ fetchXmlQuery: (fetchXml: string) => Promise<FetchXmlResult>;
167
+
168
+ /**
169
+ * Retrieve multiple records (alias for fetchXmlQuery for backward compatibility)
170
+ *
171
+ * @param fetchXml - FetchXML query string
172
+ * @returns Object with value array containing matching records
173
+ */
174
+ retrieveMultiple: (fetchXml: string) => Promise<FetchXmlResult>;
175
+
176
+ /**
177
+ * Execute a Dataverse Web API action or function
178
+ *
179
+ * @param request - Execute request configuration
180
+ * @returns Object containing the operation result
181
+ *
182
+ * @example
183
+ * // Execute WhoAmI function
184
+ * const result = await dataverseAPI.execute({
185
+ * operationName: 'WhoAmI',
186
+ * operationType: 'function'
187
+ * });
188
+ * console.log('User ID:', result.UserId);
189
+ *
190
+ * @example
191
+ * // Execute bound action
192
+ * const result = await dataverseAPI.execute({
193
+ * entityName: 'account',
194
+ * entityId: 'guid-here',
195
+ * operationName: 'CalculateRollupField',
196
+ * operationType: 'action',
197
+ * parameters: {
198
+ * FieldName: 'total_revenue'
199
+ * }
200
+ * });
201
+ */
202
+ execute: (request: ExecuteRequest) => Promise<Record<string, unknown>>;
203
+
204
+ /**
205
+ * Get metadata for a specific entity
206
+ *
207
+ * @param entityLogicalName - Logical name of the entity
208
+ * @returns Object containing entity metadata
209
+ *
210
+ * @example
211
+ * const metadata = await dataverseAPI.getEntityMetadata('account');
212
+ * console.log('Display Name:', metadata.DisplayName?.LocalizedLabels[0]?.Label);
213
+ * console.log('Attributes:', metadata.Attributes?.length);
214
+ */
215
+ getEntityMetadata: (entityLogicalName: string) => Promise<EntityMetadata>;
216
+
217
+ /**
218
+ * Get metadata for all entities
219
+ *
220
+ * @returns Object with value array containing all entity metadata
221
+ *
222
+ * @example
223
+ * const allEntities = await dataverseAPI.getAllEntitiesMetadata();
224
+ * console.log(`Total entities: ${allEntities.value.length}`);
225
+ * allEntities.value.forEach(entity => {
226
+ * console.log(`${entity.LogicalName} - ${entity.DisplayName?.LocalizedLabels[0]?.Label}`);
227
+ * });
228
+ */
229
+ getAllEntitiesMetadata: () => Promise<EntityMetadataCollection>;
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Global window interface extension for Dataverse API
235
+ */
236
+ declare global {
237
+ interface Window {
238
+ /**
239
+ * Dataverse Web API for interacting with Microsoft Dataverse
240
+ */
241
+ dataverseAPI: DataverseAPI.API;
242
+ }
243
+ }
244
+
245
+ export = DataverseAPI;
246
+ export as namespace DataverseAPI;
package/index.d.ts CHANGED
@@ -1,183 +1,22 @@
1
1
  /**
2
2
  * Power Platform Tool Box API Type Definitions
3
3
  *
4
- * Tools running in ToolBox webviews can access the ToolBox API via window.toolboxAPI
4
+ * This is the main entry point for TypeScript type definitions.
5
+ * Tools can reference specific APIs they need:
6
+ *
7
+ * For ToolBox API:
8
+ * /// <reference types="@pptb/types/toolboxAPI" />
9
+ *
10
+ * For Dataverse API:
11
+ * /// <reference types="@pptb/types/dataverseAPI" />
12
+ *
13
+ * Or reference all:
14
+ * /// <reference types="@pptb/types" />
5
15
  */
6
16
 
7
- declare namespace ToolBox {
8
- /**
9
- * Tool context containing connection information
10
- */
11
- export interface ToolContext {
12
- toolId: string | null;
13
- connectionUrl: string | null;
14
- accessToken: string | null;
15
- }
16
-
17
- /**
18
- * Notification options
19
- */
20
- export interface NotificationOptions {
21
- title: string;
22
- body: string;
23
- type?: "info" | "success" | "warning" | "error";
24
- duration?: number; // Duration in milliseconds, 0 for persistent
25
- }
26
-
27
- /**
28
- * Event types that can be emitted by the ToolBox
29
- */
30
- export type ToolBoxEvent = "tool:loaded" | "tool:unloaded" | "connection:created" | "connection:updated" | "connection:deleted" | "settings:updated" | "notification:shown" | "terminal:created" | "terminal:closed" | "terminal:output" | "terminal:command:completed" | "terminal:error";
31
-
32
- /**
33
- * Event payload for ToolBox events
34
- */
35
- export interface ToolBoxEventPayload {
36
- event: ToolBoxEvent;
37
- data: unknown;
38
- timestamp: string;
39
- }
40
-
41
- /**
42
- * Dataverse connection configuration
43
- */
44
- export interface DataverseConnection {
45
- id: string;
46
- name: string;
47
- url: string;
48
- environment: "Dev" | "Test" | "UAT" | "Production";
49
- clientId?: string;
50
- tenantId?: string;
51
- createdAt: string;
52
- lastUsedAt?: string;
53
- isActive?: boolean;
54
- }
55
-
56
- /**
57
- * Tool information
58
- */
59
- export interface Tool {
60
- id: string;
61
- name: string;
62
- version: string;
63
- description: string;
64
- author: string;
65
- icon?: string;
66
- }
67
-
68
- /**
69
- * Terminal configuration options
70
- */
71
- export interface TerminalOptions {
72
- name: string;
73
- shell?: string;
74
- cwd?: string;
75
- env?: Record<string, string>;
76
- }
77
-
78
- /**
79
- * Terminal instance
80
- */
81
- export interface Terminal {
82
- id: string;
83
- name: string;
84
- toolId: string;
85
- shell: string;
86
- cwd: string;
87
- isVisible: boolean;
88
- createdAt: string;
89
- }
90
-
91
- /**
92
- * Terminal command execution result
93
- */
94
- export interface TerminalCommandResult {
95
- terminalId: string;
96
- commandId: string;
97
- output?: string;
98
- exitCode?: number;
99
- error?: string;
100
- }
101
-
102
- /**
103
- * ToolBox API exposed to tools via window.toolboxAPI
104
- */
105
- export interface ToolBoxAPI {
106
- // Settings
107
- getUserSettings: () => Promise<any>;
108
- updateUserSettings: (settings: any) => Promise<void>;
109
- getSetting: (key: string) => Promise<any>;
110
- setSetting: (key: string, value: any) => Promise<void>;
111
-
112
- // Connections
113
- addConnection: (connection: any) => Promise<void>;
114
- updateConnection: (id: string, updates: any) => Promise<void>;
115
- deleteConnection: (id: string) => Promise<void>;
116
- getConnections: () => Promise<DataverseConnection[]>;
117
- setActiveConnection: (id: string) => Promise<void>;
118
- getActiveConnection: () => Promise<DataverseConnection | null>;
119
- disconnectConnection: () => Promise<void>;
120
-
121
- // Tools
122
- getAllTools: () => Promise<Tool[]>;
123
- getTool: (toolId: string) => Promise<Tool>;
124
- loadTool: (packageName: string) => Promise<Tool>;
125
- unloadTool: (toolId: string) => Promise<void>;
126
- installTool: (packageName: string) => Promise<Tool>;
127
- uninstallTool: (packageName: string, toolId: string) => Promise<void>;
128
- getToolWebviewHtml: (packageName: string, connectionUrl?: string, accessToken?: string) => Promise<string | null>;
129
- getToolContext: () => Promise<ToolContext>;
130
-
131
- // Tool Settings
132
- getToolSettings: (toolId: string) => Promise<any>;
133
- updateToolSettings: (toolId: string, settings: any) => Promise<void>;
134
-
135
- // Notifications
136
- showNotification: (options: NotificationOptions) => Promise<void>;
137
-
138
- // Clipboard
139
- copyToClipboard: (text: string) => Promise<void>;
140
-
141
- // File operations
142
- saveFile: (defaultPath: string, content: any) => Promise<string | null>;
143
-
144
- // Terminal operations
145
- createTerminal: (toolId: string, options: TerminalOptions) => Promise<Terminal>;
146
- executeTerminalCommand: (terminalId: string, command: string) => Promise<TerminalCommandResult>;
147
- closeTerminal: (terminalId: string) => Promise<void>;
148
- getTerminal: (terminalId: string) => Promise<Terminal | undefined>;
149
- getToolTerminals: (toolId: string) => Promise<Terminal[]>;
150
- getAllTerminals: () => Promise<Terminal[]>;
151
- setTerminalVisibility: (terminalId: string, visible: boolean) => Promise<void>;
152
-
153
- // Events
154
- getEventHistory: (limit?: number) => Promise<ToolBoxEventPayload[]>;
155
- onToolboxEvent: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
156
- removeToolboxEventListener: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
157
-
158
- // Auto-update
159
- checkForUpdates: () => Promise<void>;
160
- downloadUpdate: () => Promise<void>;
161
- quitAndInstall: () => Promise<void>;
162
- getAppVersion: () => Promise<string>;
163
- onUpdateChecking: (callback: () => void) => void;
164
- onUpdateAvailable: (callback: (info: any) => void) => void;
165
- onUpdateNotAvailable: (callback: () => void) => void;
166
- onUpdateDownloadProgress: (callback: (progress: any) => void) => void;
167
- onUpdateDownloaded: (callback: (info: any) => void) => void;
168
- onUpdateError: (callback: (error: string) => void) => void;
169
- }
170
- }
171
-
172
- /**
173
- * Global window interface extension for ToolBox tools
174
- */
175
- declare global {
176
- interface Window {
177
- toolboxAPI: ToolBox.ToolBoxAPI;
178
- TOOLBOX_CONTEXT?: ToolBox.ToolContext;
179
- }
180
- }
17
+ /// <reference path="./toolboxAPI.d.ts" />
18
+ /// <reference path="./dataverseAPI.d.ts" />
181
19
 
182
- export = ToolBox;
183
- export as namespace ToolBox;
20
+ // Re-export all namespaces for convenience
21
+ export * from "./toolboxAPI";
22
+ export * from "./dataverseAPI";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pptb/types",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "TypeScript type definitions for Power Platform Tool Box API",
5
5
  "main": "index.d.ts",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Power Platform Tool Box - ToolBox API Type Definitions
3
+ *
4
+ * Core ToolBox API exposed to tools via window.toolboxAPI
5
+ */
6
+
7
+ declare namespace ToolBoxAPI {
8
+ /**
9
+ * Tool context containing connection information
10
+ * NOTE: accessToken is NOT included for security - tools must use dataverseAPI
11
+ */
12
+ export interface ToolContext {
13
+ toolId: string | null;
14
+ connectionUrl: string | null;
15
+ }
16
+
17
+ /**
18
+ * Notification options
19
+ */
20
+ export interface NotificationOptions {
21
+ title: string;
22
+ body: string;
23
+ type?: "info" | "success" | "warning" | "error";
24
+ duration?: number; // Duration in milliseconds, 0 for persistent
25
+ }
26
+
27
+ /**
28
+ * Event types that can be emitted by the ToolBox
29
+ */
30
+ export type ToolBoxEvent =
31
+ | "tool:loaded"
32
+ | "tool:unloaded"
33
+ | "connection:created"
34
+ | "connection:updated"
35
+ | "connection:deleted"
36
+ | "settings:updated"
37
+ | "notification:shown"
38
+ | "terminal:created"
39
+ | "terminal:closed"
40
+ | "terminal:output"
41
+ | "terminal:command:completed"
42
+ | "terminal:error";
43
+
44
+ /**
45
+ * Event payload for ToolBox events
46
+ */
47
+ export interface ToolBoxEventPayload {
48
+ event: ToolBoxEvent;
49
+ data: unknown;
50
+ timestamp: string;
51
+ }
52
+
53
+ /**
54
+ * Dataverse connection configuration
55
+ */
56
+ export interface DataverseConnection {
57
+ id: string;
58
+ name: string;
59
+ url: string;
60
+ environment: "Dev" | "Test" | "UAT" | "Production";
61
+ clientId?: string;
62
+ tenantId?: string;
63
+ createdAt: string;
64
+ lastUsedAt?: string;
65
+ isActive?: boolean;
66
+ }
67
+
68
+ /**
69
+ * Tool information
70
+ */
71
+ export interface Tool {
72
+ id: string;
73
+ name: string;
74
+ version: string;
75
+ description: string;
76
+ author: string;
77
+ icon?: string;
78
+ }
79
+
80
+ /**
81
+ * Terminal configuration options
82
+ */
83
+ export interface TerminalOptions {
84
+ name: string;
85
+ shell?: string;
86
+ cwd?: string;
87
+ env?: Record<string, string>;
88
+ visible?: boolean; // Whether terminal should be visible initially (default: true)
89
+ }
90
+
91
+ /**
92
+ * Terminal instance
93
+ */
94
+ export interface Terminal {
95
+ id: string;
96
+ name: string;
97
+ toolId: string;
98
+ shell: string;
99
+ cwd: string;
100
+ isVisible: boolean;
101
+ createdAt: string;
102
+ }
103
+
104
+ /**
105
+ * Terminal command execution result
106
+ */
107
+ export interface TerminalCommandResult {
108
+ terminalId: string;
109
+ commandId: string;
110
+ output?: string;
111
+ exitCode?: number;
112
+ error?: string;
113
+ }
114
+
115
+ /**
116
+ * Connections namespace - restricted access for tools
117
+ */
118
+ export interface ConnectionsAPI {
119
+ /**
120
+ * Get the currently active Dataverse connection
121
+ */
122
+ getActiveConnection: () => Promise<DataverseConnection | null>;
123
+ }
124
+
125
+ /**
126
+ * Utils namespace - utility functions for tools
127
+ */
128
+ export interface UtilsAPI {
129
+ /**
130
+ * Display a notification to the user
131
+ */
132
+ showNotification: (options: NotificationOptions) => Promise<void>;
133
+
134
+ /**
135
+ * Copy text to the system clipboard
136
+ */
137
+ copyToClipboard: (text: string) => Promise<void>;
138
+
139
+ /**
140
+ * Open a save file dialog and write content
141
+ */
142
+ saveFile: (defaultPath: string, content: any) => Promise<string | null>;
143
+
144
+ /**
145
+ * Get the current UI theme (light or dark)
146
+ */
147
+ getCurrentTheme: () => Promise<"light" | "dark">;
148
+ }
149
+
150
+ /**
151
+ * Terminal namespace - context-aware terminal operations
152
+ */
153
+ export interface TerminalAPI {
154
+ /**
155
+ * Create a new terminal (tool ID is auto-determined)
156
+ */
157
+ create: (options: TerminalOptions) => Promise<Terminal>;
158
+
159
+ /**
160
+ * Execute a command in a terminal
161
+ */
162
+ execute: (terminalId: string, command: string) => Promise<TerminalCommandResult>;
163
+
164
+ /**
165
+ * Close a terminal
166
+ */
167
+ close: (terminalId: string) => Promise<void>;
168
+
169
+ /**
170
+ * Get a terminal by ID
171
+ */
172
+ get: (terminalId: string) => Promise<Terminal | undefined>;
173
+
174
+ /**
175
+ * List all terminals for this tool
176
+ */
177
+ list: () => Promise<Terminal[]>;
178
+
179
+ /**
180
+ * Set terminal visibility
181
+ */
182
+ setVisibility: (terminalId: string, visible: boolean) => Promise<void>;
183
+ }
184
+
185
+ /**
186
+ * Events namespace - tool-specific event handling
187
+ */
188
+ export interface EventsAPI {
189
+ /**
190
+ * Get event history for this tool
191
+ */
192
+ getHistory: (limit?: number) => Promise<ToolBoxEventPayload[]>;
193
+
194
+ /**
195
+ * Subscribe to ToolBox events
196
+ */
197
+ on: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
198
+
199
+ /**
200
+ * Unsubscribe from ToolBox events
201
+ */
202
+ off: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
203
+ }
204
+
205
+ /**
206
+ * Settings namespace - context-aware tool settings
207
+ * All settings operations automatically use the current tool's ID
208
+ */
209
+ export interface SettingsAPI {
210
+ /**
211
+ * Get all settings for this tool
212
+ * @returns Promise resolving to an object with all settings (empty object if no settings exist)
213
+ */
214
+ getSettings: () => Promise<Record<string, any>>;
215
+
216
+ /**
217
+ * Get a specific setting by key
218
+ * @param key The setting key to retrieve
219
+ * @returns Promise resolving to the setting value, or undefined if not found
220
+ */
221
+ getSetting: (key: string) => Promise<any>;
222
+
223
+ /**
224
+ * Set a specific setting by key
225
+ * @param key The setting key to set
226
+ * @param value The value to store (can be any JSON-serializable value)
227
+ * @returns Promise that resolves when the setting is saved
228
+ */
229
+ setSetting: (key: string, value: any) => Promise<void>;
230
+
231
+ /**
232
+ * Set all settings (replaces entire settings object)
233
+ * @param settings The settings object to store
234
+ * @returns Promise that resolves when the settings are saved
235
+ */
236
+ setSettings: (settings: Record<string, any>) => Promise<void>;
237
+ }
238
+
239
+ /**
240
+ * Main ToolBox API exposed to tools via window.toolboxAPI
241
+ */
242
+ export interface API {
243
+ /**
244
+ * Connection-related operations (restricted)
245
+ */
246
+ connections: ConnectionsAPI;
247
+
248
+ /**
249
+ * Utility functions
250
+ */
251
+ utils: UtilsAPI;
252
+
253
+ /**
254
+ * Tool-specific settings (context-aware)
255
+ */
256
+ settings: SettingsAPI;
257
+
258
+ /**
259
+ * Terminal operations (context-aware)
260
+ */
261
+ terminal: TerminalAPI;
262
+
263
+ /**
264
+ * Event handling (tool-specific)
265
+ */
266
+ events: EventsAPI;
267
+
268
+ /**
269
+ * Get the current tool context
270
+ * @internal Used internally by the framework
271
+ */
272
+ getToolContext: () => Promise<ToolContext>;
273
+ }
274
+
275
+ /**
276
+ * Auto-update event handlers
277
+ */
278
+ export interface UpdateHandlers {
279
+ onUpdateChecking: (callback: () => void) => void;
280
+ onUpdateAvailable: (callback: (info: any) => void) => void;
281
+ onUpdateNotAvailable: (callback: () => void) => void;
282
+ onUpdateDownloadProgress: (callback: (progress: any) => void) => void;
283
+ onUpdateDownloaded: (callback: (info: any) => void) => void;
284
+ onUpdateError: (callback: (error: string) => void) => void;
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Global window interface extension for ToolBox tools
290
+ */
291
+ declare global {
292
+ interface Window {
293
+ /**
294
+ * The organized ToolBox API for tools
295
+ */
296
+ toolboxAPI: ToolBoxAPI.API;
297
+
298
+ /**
299
+ * Tool context available at startup
300
+ */
301
+ TOOLBOX_CONTEXT?: ToolBoxAPI.ToolContext;
302
+ }
303
+ }
304
+
305
+ export = ToolBoxAPI;
306
+ export as namespace ToolBoxAPI;