@pptb/types 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -0
- package/index.d.ts +183 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# @pptb/types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for Power Platform Tool Box API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @pptb/types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### In your TypeScript tool
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
/// <reference types="@pptb/types" />
|
|
17
|
+
|
|
18
|
+
// Access the ToolBox API
|
|
19
|
+
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
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Type-safe event handling
|
|
40
|
+
|
|
41
|
+
```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
|
|
59
|
+
|
|
60
|
+
- getUserSettings(): Promise<any>
|
|
61
|
+
|
|
62
|
+
- Returns the entire user settings object stored by the ToolBox.
|
|
63
|
+
|
|
64
|
+
- updateUserSettings(settings: any): Promise<void>
|
|
65
|
+
|
|
66
|
+
- Merges and persists the provided settings object into the user settings store.
|
|
67
|
+
|
|
68
|
+
- getSetting(key: string): Promise<any>
|
|
69
|
+
|
|
70
|
+
- Retrieves a single setting value by key from user settings.
|
|
71
|
+
|
|
72
|
+
- setSetting(key: string, value: any): Promise<void>
|
|
73
|
+
- Sets or updates a single setting key/value in user settings.
|
|
74
|
+
|
|
75
|
+
### Connections
|
|
76
|
+
|
|
77
|
+
- addConnection(connection: any): Promise<void>
|
|
78
|
+
|
|
79
|
+
- Adds a new Dataverse connection definition to the ToolBox.
|
|
80
|
+
|
|
81
|
+
- updateConnection(id: string, updates: any): Promise<void>
|
|
82
|
+
|
|
83
|
+
- Applies partial updates to an existing connection by its id.
|
|
84
|
+
|
|
85
|
+
- deleteConnection(id: string): Promise<void>
|
|
86
|
+
|
|
87
|
+
- Removes an existing connection by its id.
|
|
88
|
+
|
|
89
|
+
- getConnections(): Promise<ToolBox.DataverseConnection[]>
|
|
90
|
+
|
|
91
|
+
- Returns all saved Dataverse connections.
|
|
92
|
+
|
|
93
|
+
- setActiveConnection(id: string): Promise<void>
|
|
94
|
+
|
|
95
|
+
- Marks the specified connection as the active connection for the current session.
|
|
96
|
+
|
|
97
|
+
- getActiveConnection(): Promise<ToolBox.DataverseConnection | null>
|
|
98
|
+
|
|
99
|
+
- Returns the currently active connection or null if none is active.
|
|
100
|
+
|
|
101
|
+
- disconnectConnection(): Promise<void>
|
|
102
|
+
- Clears the active connection for the current session.
|
|
103
|
+
|
|
104
|
+
### Tools
|
|
105
|
+
|
|
106
|
+
- getAllTools(): Promise<ToolBox.Tool[]>
|
|
107
|
+
|
|
108
|
+
- Returns all tools known to the ToolBox (installed/managed).
|
|
109
|
+
|
|
110
|
+
- getTool(toolId: string): Promise<ToolBox.Tool>
|
|
111
|
+
|
|
112
|
+
- Returns metadata about a specific tool by its id.
|
|
113
|
+
|
|
114
|
+
- loadTool(packageName: string): Promise<ToolBox.Tool>
|
|
115
|
+
|
|
116
|
+
- Loads a tool (initializes/activates) by npm package name.
|
|
117
|
+
|
|
118
|
+
- unloadTool(toolId: string): Promise<void>
|
|
119
|
+
|
|
120
|
+
- Unloads a tool instance by its id.
|
|
121
|
+
|
|
122
|
+
- installTool(packageName: string): Promise<ToolBox.Tool>
|
|
123
|
+
|
|
124
|
+
- Installs a tool from npm (and registers it with the ToolBox).
|
|
125
|
+
|
|
126
|
+
- uninstallTool(packageName: string, toolId: string): Promise<void>
|
|
127
|
+
|
|
128
|
+
- Uninstalls a previously installed tool and removes it from the ToolBox.
|
|
129
|
+
|
|
130
|
+
- getToolWebviewHtml(packageName: string, connectionUrl?: string, accessToken?: string): Promise<string | null>
|
|
131
|
+
|
|
132
|
+
- Returns an HTML string suitable for a tool's webview. Optional connection credentials can be passed for bootstrapping.
|
|
133
|
+
|
|
134
|
+
- getToolContext(): Promise<ToolBox.ToolContext>
|
|
135
|
+
- Returns the current tool context including `toolId`, `connectionUrl`, and `accessToken` when available.
|
|
136
|
+
|
|
137
|
+
### Tool Settings
|
|
138
|
+
|
|
139
|
+
- getToolSettings(toolId: string): Promise<any>
|
|
140
|
+
|
|
141
|
+
- Returns tool-scoped settings for the specified tool id.
|
|
142
|
+
|
|
143
|
+
- updateToolSettings(toolId: string, settings: any): Promise<void>
|
|
144
|
+
- Merges and persists tool-scoped settings for the specified tool id.
|
|
145
|
+
|
|
146
|
+
### Notifications
|
|
147
|
+
|
|
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).
|
|
150
|
+
|
|
151
|
+
### Clipboard
|
|
152
|
+
|
|
153
|
+
- copyToClipboard(text: string): Promise<void>
|
|
154
|
+
- Copies the provided text into the system clipboard.
|
|
155
|
+
|
|
156
|
+
### File operations
|
|
157
|
+
|
|
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.
|
|
160
|
+
|
|
161
|
+
### Terminal operations
|
|
162
|
+
|
|
163
|
+
- createTerminal(toolId: string, options: ToolBox.TerminalOptions): Promise<ToolBox.Terminal>
|
|
164
|
+
|
|
165
|
+
- Creates a new terminal attached to the tool with the given options (name, shell, cwd, env).
|
|
166
|
+
|
|
167
|
+
- executeTerminalCommand(terminalId: string, command: string): Promise<ToolBox.TerminalCommandResult>
|
|
168
|
+
|
|
169
|
+
- Executes a command in the specified terminal and returns its result.
|
|
170
|
+
|
|
171
|
+
- closeTerminal(terminalId: string): Promise<void>
|
|
172
|
+
|
|
173
|
+
- Closes the specified terminal.
|
|
174
|
+
|
|
175
|
+
- getTerminal(terminalId: string): Promise<ToolBox.Terminal | undefined>
|
|
176
|
+
|
|
177
|
+
- Gets a single terminal by id, if it exists.
|
|
178
|
+
|
|
179
|
+
- getToolTerminals(toolId: string): Promise<ToolBox.Terminal[]>
|
|
180
|
+
|
|
181
|
+
- Lists all terminals created by a specific tool.
|
|
182
|
+
|
|
183
|
+
- getAllTerminals(): Promise<ToolBox.Terminal[]>
|
|
184
|
+
|
|
185
|
+
- Lists all existing terminals managed by the ToolBox.
|
|
186
|
+
|
|
187
|
+
- setTerminalVisibility(terminalId: string, visible: boolean): Promise<void>
|
|
188
|
+
- Shows or hides the terminal UI for the specified terminal id.
|
|
189
|
+
|
|
190
|
+
### Events
|
|
191
|
+
|
|
192
|
+
- getEventHistory(limit?: number): Promise<ToolBox.ToolBoxEventPayload[]>
|
|
193
|
+
|
|
194
|
+
- Returns recent ToolBox events, newest first. Use `limit` to cap the number of entries.
|
|
195
|
+
|
|
196
|
+
- onToolboxEvent(callback: (event: any, payload: ToolBox.ToolBoxEventPayload) => void): void
|
|
197
|
+
|
|
198
|
+
- Subscribes to ToolBox events (e.g., `tool:loaded`, `connection:updated`, `terminal:output`).
|
|
199
|
+
|
|
200
|
+
- removeToolboxEventListener(callback: (event: any, payload: ToolBox.ToolBoxEventPayload) => void): void
|
|
201
|
+
- Removes a previously registered event listener.
|
|
202
|
+
|
|
203
|
+
### Auto-update
|
|
204
|
+
|
|
205
|
+
- checkForUpdates(): Promise<void>
|
|
206
|
+
|
|
207
|
+
- Triggers an update check.
|
|
208
|
+
|
|
209
|
+
- downloadUpdate(): Promise<void>
|
|
210
|
+
|
|
211
|
+
- Starts downloading an available update.
|
|
212
|
+
|
|
213
|
+
- quitAndInstall(): Promise<void>
|
|
214
|
+
|
|
215
|
+
- Quits the app and installs a downloaded update.
|
|
216
|
+
|
|
217
|
+
- getAppVersion(): Promise<string>
|
|
218
|
+
|
|
219
|
+
- Returns the current application version.
|
|
220
|
+
|
|
221
|
+
- onUpdateChecking(callback: () => void): void
|
|
222
|
+
|
|
223
|
+
- Called when an update check has started.
|
|
224
|
+
|
|
225
|
+
- onUpdateAvailable(callback: (info: any) => void): void
|
|
226
|
+
|
|
227
|
+
- Called when an update is available; `info` provides update metadata.
|
|
228
|
+
|
|
229
|
+
- onUpdateNotAvailable(callback: () => void): void
|
|
230
|
+
|
|
231
|
+
- Called when no updates are available.
|
|
232
|
+
|
|
233
|
+
- onUpdateDownloadProgress(callback: (progress: any) => void): void
|
|
234
|
+
|
|
235
|
+
- Called periodically with download progress information.
|
|
236
|
+
|
|
237
|
+
- onUpdateDownloaded(callback: (info: any) => void): void
|
|
238
|
+
|
|
239
|
+
- Called once an update has been downloaded and is ready to install.
|
|
240
|
+
|
|
241
|
+
- onUpdateError(callback: (error: string) => void): void
|
|
242
|
+
- Called when an update-related error occurs.
|
|
243
|
+
|
|
244
|
+
## Publishing the package to npm
|
|
245
|
+
|
|
246
|
+
This is an organization scoped package so use the following command to deploy to npm
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
npm publish --access public
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
GPL-3.0
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Power Platform Tool Box API Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Tools running in ToolBox webviews can access the ToolBox API via window.toolboxAPI
|
|
5
|
+
*/
|
|
6
|
+
|
|
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
|
+
}
|
|
181
|
+
|
|
182
|
+
export = ToolBox;
|
|
183
|
+
export as namespace ToolBox;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pptb/types",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript type definitions for Power Platform Tool Box API",
|
|
5
|
+
"main": "index.d.ts",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"powerplatform",
|
|
9
|
+
"pptb",
|
|
10
|
+
"toolbox",
|
|
11
|
+
"types",
|
|
12
|
+
"typescript",
|
|
13
|
+
"dataverse"
|
|
14
|
+
],
|
|
15
|
+
"author": "Power Platform Tool Box",
|
|
16
|
+
"license": "GPL-3.0",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/PowerPlatform-ToolBox/desktop-app.git",
|
|
20
|
+
"directory": "packages"
|
|
21
|
+
}
|
|
22
|
+
}
|