@pptb/types 1.0.0 → 1.0.1
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 +236 -135
- package/dataverseAPI.d.ts +246 -0
- package/index.d.ts +16 -177
- package/package.json +1 -1
- package/toolboxAPI.d.ts +266 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @pptb/types
|
|
2
2
|
|
|
3
|
-
TypeScript type definitions for Power Platform Tool Box
|
|
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
|
-
###
|
|
20
|
+
### Include all type definitions
|
|
14
21
|
|
|
15
22
|
```typescript
|
|
16
23
|
/// <reference types="@pptb/types" />
|
|
17
24
|
|
|
18
|
-
//
|
|
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
|
-
###
|
|
30
|
+
### Include specific API types
|
|
40
31
|
|
|
41
32
|
```typescript
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
36
|
+
// Only Dataverse API types
|
|
37
|
+
/// <reference types="@pptb/types/dataverseAPI" />
|
|
38
|
+
```
|
|
61
39
|
|
|
62
|
-
|
|
40
|
+
## ToolBox API Examples
|
|
63
41
|
|
|
64
|
-
|
|
42
|
+
The ToolBox API provides organized namespaces for different functionality:
|
|
65
43
|
|
|
66
|
-
|
|
44
|
+
### Connections
|
|
67
45
|
|
|
68
|
-
|
|
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
|
-
|
|
55
|
+
### Utilities
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
66
|
+
// Copy to clipboard
|
|
67
|
+
await toolboxAPI.utils.copyToClipboard("Text to copy");
|
|
76
68
|
|
|
77
|
-
|
|
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
|
-
|
|
75
|
+
// Get current theme
|
|
76
|
+
const theme = await toolboxAPI.utils.getCurrentTheme();
|
|
77
|
+
console.log("Current theme:", theme); // "light" or "dark"
|
|
78
|
+
```
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
### Terminal Operations
|
|
82
81
|
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
+
// List all terminals for this tool
|
|
95
|
+
const terminals = await toolboxAPI.terminal.list();
|
|
88
96
|
|
|
89
|
-
|
|
97
|
+
// Close a terminal
|
|
98
|
+
await toolboxAPI.terminal.close(terminal.id);
|
|
99
|
+
```
|
|
90
100
|
|
|
91
|
-
|
|
101
|
+
### Events
|
|
92
102
|
|
|
93
|
-
|
|
103
|
+
```typescript
|
|
104
|
+
// Subscribe to events
|
|
105
|
+
toolboxAPI.events.on((event, payload) => {
|
|
106
|
+
console.log("Event:", payload.event, "Data:", payload.data);
|
|
94
107
|
|
|
95
|
-
|
|
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
|
-
|
|
118
|
+
// Get event history
|
|
119
|
+
const history = await toolboxAPI.events.getHistory(10); // Last 10 events
|
|
120
|
+
```
|
|
98
121
|
|
|
99
|
-
|
|
122
|
+
## Dataverse API Examples
|
|
100
123
|
|
|
101
|
-
|
|
102
|
-
- Clears the active connection for the current session.
|
|
124
|
+
The Dataverse API provides direct access to Microsoft Dataverse operations:
|
|
103
125
|
|
|
104
|
-
###
|
|
126
|
+
### CRUD Operations
|
|
105
127
|
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
141
|
+
// Update a record
|
|
142
|
+
await dataverseAPI.update("account", result.id, {
|
|
143
|
+
name: "Updated Account Name",
|
|
144
|
+
description: "Updated description",
|
|
145
|
+
});
|
|
111
146
|
|
|
112
|
-
|
|
147
|
+
// Delete a record
|
|
148
|
+
await dataverseAPI.delete("account", result.id);
|
|
149
|
+
```
|
|
113
150
|
|
|
114
|
-
|
|
151
|
+
### FetchXML Queries
|
|
115
152
|
|
|
116
|
-
|
|
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
|
-
|
|
174
|
+
### Metadata Operations
|
|
119
175
|
|
|
120
|
-
|
|
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
|
-
|
|
187
|
+
### Execute Actions/Functions
|
|
123
188
|
|
|
124
|
-
|
|
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
|
-
|
|
209
|
+
## API Reference
|
|
127
210
|
|
|
128
|
-
|
|
211
|
+
The Power Platform Tool Box exposes two main APIs to tools:
|
|
129
212
|
|
|
130
|
-
|
|
213
|
+
### ToolBox API (`window.toolboxAPI`)
|
|
131
214
|
|
|
132
|
-
|
|
215
|
+
Core platform features organized into namespaces:
|
|
133
216
|
|
|
134
|
-
|
|
135
|
-
- Returns the current tool context including `toolId`, `connectionUrl`, and `accessToken` when available.
|
|
217
|
+
#### Connections
|
|
136
218
|
|
|
137
|
-
|
|
219
|
+
- **getActiveConnection()**: Promise<DataverseConnection | null>
|
|
220
|
+
- Returns the currently active Dataverse connection or null if none is active
|
|
138
221
|
|
|
139
|
-
|
|
222
|
+
#### Utils
|
|
140
223
|
|
|
141
|
-
|
|
224
|
+
- **showNotification(options: NotificationOptions)**: Promise<void>
|
|
142
225
|
|
|
143
|
-
-
|
|
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
|
-
|
|
228
|
+
- **copyToClipboard(text: string)**: Promise<void>
|
|
147
229
|
|
|
148
|
-
-
|
|
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
|
-
|
|
232
|
+
- **saveFile(defaultPath: string, content: any)**: Promise<string | null>
|
|
152
233
|
|
|
153
|
-
-
|
|
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
|
-
|
|
236
|
+
- **getCurrentTheme()**: Promise<"light" | "dark">
|
|
237
|
+
- Returns the current UI theme setting
|
|
157
238
|
|
|
158
|
-
|
|
159
|
-
- Opens a save dialog and writes the content. Returns the saved file path or null if canceled.
|
|
239
|
+
#### Terminal
|
|
160
240
|
|
|
161
|
-
|
|
241
|
+
- **create(options: TerminalOptions)**: Promise<Terminal>
|
|
162
242
|
|
|
163
|
-
-
|
|
243
|
+
- Creates a new terminal attached to the tool (tool ID is auto-determined)
|
|
164
244
|
|
|
165
|
-
|
|
245
|
+
- **execute(terminalId: string, command: string)**: Promise<TerminalCommandResult>
|
|
166
246
|
|
|
167
|
-
-
|
|
247
|
+
- Executes a command in the specified terminal and returns its result
|
|
168
248
|
|
|
169
|
-
|
|
249
|
+
- **close(terminalId: string)**: Promise<void>
|
|
170
250
|
|
|
171
|
-
-
|
|
251
|
+
- Closes the specified terminal
|
|
172
252
|
|
|
173
|
-
|
|
253
|
+
- **get(terminalId: string)**: Promise<Terminal | undefined>
|
|
174
254
|
|
|
175
|
-
-
|
|
255
|
+
- Gets a single terminal by id, if it exists
|
|
176
256
|
|
|
177
|
-
|
|
257
|
+
- **list()**: Promise<Terminal[]>
|
|
178
258
|
|
|
179
|
-
-
|
|
259
|
+
- Lists all terminals created by this tool
|
|
180
260
|
|
|
181
|
-
|
|
261
|
+
- **setVisibility(terminalId: string, visible: boolean)**: Promise<void>
|
|
262
|
+
- Shows or hides the terminal UI for the specified terminal id
|
|
182
263
|
|
|
183
|
-
|
|
264
|
+
#### Events
|
|
184
265
|
|
|
185
|
-
|
|
266
|
+
- **getHistory(limit?: number)**: Promise<ToolBoxEventPayload[]>
|
|
186
267
|
|
|
187
|
-
-
|
|
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
|
-
|
|
270
|
+
- **on(callback: (event: any, payload: ToolBoxEventPayload) => void)**: void
|
|
191
271
|
|
|
192
|
-
-
|
|
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
|
-
|
|
286
|
+
- **off(callback: (event: any, payload: ToolBoxEventPayload) => void)**: void
|
|
287
|
+
- Removes a previously registered event listener
|
|
195
288
|
|
|
196
|
-
|
|
289
|
+
### Dataverse API (`window.dataverseAPI`)
|
|
197
290
|
|
|
198
|
-
|
|
291
|
+
Complete HTTP client for interacting with Microsoft Dataverse:
|
|
199
292
|
|
|
200
|
-
|
|
201
|
-
- Removes a previously registered event listener.
|
|
293
|
+
#### CRUD Operations
|
|
202
294
|
|
|
203
|
-
|
|
295
|
+
- **create(entityLogicalName: string, record: Record<string, unknown>)**: Promise<{id: string, ...}>
|
|
204
296
|
|
|
205
|
-
-
|
|
297
|
+
- Creates a new record in Dataverse
|
|
298
|
+
- Returns the created record ID and any returned fields
|
|
206
299
|
|
|
207
|
-
|
|
300
|
+
- **retrieve(entityLogicalName: string, id: string, columns?: string[])**: Promise<Record<string, unknown>>
|
|
208
301
|
|
|
209
|
-
-
|
|
302
|
+
- Retrieves a single record by ID
|
|
303
|
+
- Optional columns array to select specific fields
|
|
210
304
|
|
|
211
|
-
|
|
305
|
+
- **update(entityLogicalName: string, id: string, record: Record<string, unknown>)**: Promise<void>
|
|
212
306
|
|
|
213
|
-
-
|
|
307
|
+
- Updates an existing record
|
|
214
308
|
|
|
215
|
-
|
|
309
|
+
- **delete(entityLogicalName: string, id: string)**: Promise<void>
|
|
310
|
+
- Deletes a record
|
|
216
311
|
|
|
217
|
-
|
|
312
|
+
#### Query Operations
|
|
218
313
|
|
|
219
|
-
|
|
314
|
+
- **fetchXmlQuery(fetchXml: string)**: Promise<{value: Record<string, unknown>[], ...}>
|
|
220
315
|
|
|
221
|
-
-
|
|
316
|
+
- Executes a FetchXML query
|
|
317
|
+
- Returns object with value array containing matching records
|
|
222
318
|
|
|
223
|
-
|
|
319
|
+
- **retrieveMultiple(fetchXml: string)**: Promise<{value: Record<string, unknown>[], ...}>
|
|
320
|
+
- Alias for fetchXmlQuery for backward compatibility
|
|
224
321
|
|
|
225
|
-
|
|
322
|
+
#### Metadata Operations
|
|
226
323
|
|
|
227
|
-
|
|
324
|
+
- **getEntityMetadata(entityLogicalName: string)**: Promise<EntityMetadata>
|
|
228
325
|
|
|
229
|
-
-
|
|
326
|
+
- Retrieves metadata for a specific entity
|
|
230
327
|
|
|
231
|
-
|
|
328
|
+
- **getAllEntitiesMetadata()**: Promise<{value: EntityMetadata[]}>
|
|
329
|
+
- Retrieves metadata for all entities
|
|
232
330
|
|
|
233
|
-
|
|
331
|
+
#### Advanced Operations
|
|
234
332
|
|
|
235
|
-
|
|
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
|
-
|
|
337
|
+
### Security Notes
|
|
238
338
|
|
|
239
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
|
183
|
-
export
|
|
20
|
+
// Re-export all namespaces for convenience
|
|
21
|
+
export * from "./toolboxAPI";
|
|
22
|
+
export * from "./dataverseAPI";
|
package/package.json
CHANGED
package/toolboxAPI.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Terminal instance
|
|
92
|
+
*/
|
|
93
|
+
export interface Terminal {
|
|
94
|
+
id: string;
|
|
95
|
+
name: string;
|
|
96
|
+
toolId: string;
|
|
97
|
+
shell: string;
|
|
98
|
+
cwd: string;
|
|
99
|
+
isVisible: boolean;
|
|
100
|
+
createdAt: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Terminal command execution result
|
|
105
|
+
*/
|
|
106
|
+
export interface TerminalCommandResult {
|
|
107
|
+
terminalId: string;
|
|
108
|
+
commandId: string;
|
|
109
|
+
output?: string;
|
|
110
|
+
exitCode?: number;
|
|
111
|
+
error?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Connections namespace - restricted access for tools
|
|
116
|
+
*/
|
|
117
|
+
export interface ConnectionsAPI {
|
|
118
|
+
/**
|
|
119
|
+
* Get the currently active Dataverse connection
|
|
120
|
+
*/
|
|
121
|
+
getActiveConnection: () => Promise<DataverseConnection | null>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Utils namespace - utility functions for tools
|
|
126
|
+
*/
|
|
127
|
+
export interface UtilsAPI {
|
|
128
|
+
/**
|
|
129
|
+
* Display a notification to the user
|
|
130
|
+
*/
|
|
131
|
+
showNotification: (options: NotificationOptions) => Promise<void>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Copy text to the system clipboard
|
|
135
|
+
*/
|
|
136
|
+
copyToClipboard: (text: string) => Promise<void>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Open a save file dialog and write content
|
|
140
|
+
*/
|
|
141
|
+
saveFile: (defaultPath: string, content: any) => Promise<string | null>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get the current UI theme (light or dark)
|
|
145
|
+
*/
|
|
146
|
+
getCurrentTheme: () => Promise<"light" | "dark">;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Terminal namespace - context-aware terminal operations
|
|
151
|
+
*/
|
|
152
|
+
export interface TerminalAPI {
|
|
153
|
+
/**
|
|
154
|
+
* Create a new terminal (tool ID is auto-determined)
|
|
155
|
+
*/
|
|
156
|
+
create: (options: TerminalOptions) => Promise<Terminal>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Execute a command in a terminal
|
|
160
|
+
*/
|
|
161
|
+
execute: (terminalId: string, command: string) => Promise<TerminalCommandResult>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Close a terminal
|
|
165
|
+
*/
|
|
166
|
+
close: (terminalId: string) => Promise<void>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get a terminal by ID
|
|
170
|
+
*/
|
|
171
|
+
get: (terminalId: string) => Promise<Terminal | undefined>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* List all terminals for this tool
|
|
175
|
+
*/
|
|
176
|
+
list: () => Promise<Terminal[]>;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Set terminal visibility
|
|
180
|
+
*/
|
|
181
|
+
setVisibility: (terminalId: string, visible: boolean) => Promise<void>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Events namespace - tool-specific event handling
|
|
186
|
+
*/
|
|
187
|
+
export interface EventsAPI {
|
|
188
|
+
/**
|
|
189
|
+
* Get event history for this tool
|
|
190
|
+
*/
|
|
191
|
+
getHistory: (limit?: number) => Promise<ToolBoxEventPayload[]>;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Subscribe to ToolBox events
|
|
195
|
+
*/
|
|
196
|
+
on: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Unsubscribe from ToolBox events
|
|
200
|
+
*/
|
|
201
|
+
off: (callback: (event: any, payload: ToolBoxEventPayload) => void) => void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Main ToolBox API exposed to tools via window.toolboxAPI
|
|
206
|
+
*/
|
|
207
|
+
export interface API {
|
|
208
|
+
/**
|
|
209
|
+
* Connection-related operations (restricted)
|
|
210
|
+
*/
|
|
211
|
+
connections: ConnectionsAPI;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Utility functions
|
|
215
|
+
*/
|
|
216
|
+
utils: UtilsAPI;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Terminal operations (context-aware)
|
|
220
|
+
*/
|
|
221
|
+
terminal: TerminalAPI;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Event handling (tool-specific)
|
|
225
|
+
*/
|
|
226
|
+
events: EventsAPI;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Get the current tool context
|
|
230
|
+
* @internal Used internally by the framework
|
|
231
|
+
*/
|
|
232
|
+
getToolContext: () => Promise<ToolContext>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Auto-update event handlers
|
|
237
|
+
*/
|
|
238
|
+
export interface UpdateHandlers {
|
|
239
|
+
onUpdateChecking: (callback: () => void) => void;
|
|
240
|
+
onUpdateAvailable: (callback: (info: any) => void) => void;
|
|
241
|
+
onUpdateNotAvailable: (callback: () => void) => void;
|
|
242
|
+
onUpdateDownloadProgress: (callback: (progress: any) => void) => void;
|
|
243
|
+
onUpdateDownloaded: (callback: (info: any) => void) => void;
|
|
244
|
+
onUpdateError: (callback: (error: string) => void) => void;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Global window interface extension for ToolBox tools
|
|
250
|
+
*/
|
|
251
|
+
declare global {
|
|
252
|
+
interface Window {
|
|
253
|
+
/**
|
|
254
|
+
* The organized ToolBox API for tools
|
|
255
|
+
*/
|
|
256
|
+
toolboxAPI: ToolBoxAPI.API;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Tool context available at startup
|
|
260
|
+
*/
|
|
261
|
+
TOOLBOX_CONTEXT?: ToolBoxAPI.ToolContext;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export = ToolBoxAPI;
|
|
266
|
+
export as namespace ToolBoxAPI;
|