@pptb/types 1.2.7-beta.4 → 1.2.7-beta.6
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 +77 -3
- package/package.json +1 -1
- package/pptbConfig.d.ts +30 -5
- package/toolboxAPI.d.ts +53 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ TypeScript type definitions for Power Platform ToolBox APIs, plus a built-in CLI
|
|
|
18
18
|
- [Connections](#connections)
|
|
19
19
|
- [Utilities](#utilities)
|
|
20
20
|
- [Terminal Operations](#terminal-operations)
|
|
21
|
+
- [Native Workers](#native-workers)
|
|
21
22
|
- [Events](#events)
|
|
22
23
|
- [Inter-Tool Invocation](#inter-tool-invocation)
|
|
23
24
|
- [Caller: launching another tool with prefill data](#caller-launching-another-tool-with-prefill-data)
|
|
@@ -42,6 +43,7 @@ TypeScript type definitions for Power Platform ToolBox APIs, plus a built-in CLI
|
|
|
42
43
|
- [Connections](#connections-1)
|
|
43
44
|
- [Utils](#utils)
|
|
44
45
|
- [Terminal](#terminal)
|
|
46
|
+
- [Workers](#workers)
|
|
45
47
|
- [Events](#events-1)
|
|
46
48
|
- [Invocation](#invocation)
|
|
47
49
|
- [Dataverse API (`window.dataverseAPI`)](#dataverse-api-windowdataverseapi)
|
|
@@ -256,6 +258,18 @@ The ToolBox API provides organized namespaces for different functionality:
|
|
|
256
258
|
|
|
257
259
|
### Connections
|
|
258
260
|
|
|
261
|
+
Declare an exact count or range with `features.connections`, for example `3`, `{ "min": 0, "max": 3 }`, or `{ "min": 1, "max": 4 }`. Exact `0` means no connections. Counts are bounded to 0–10; object defaults are min 1 and max equal to the resolved min. Remove the deprecated `multiConnection` and `connectionRequirement` fields when migrating; existing legacy-only tools remain supported.
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
const slots = await toolboxAPI.connections.getConnections();
|
|
265
|
+
const third = await toolboxAPI.connections.getConnection(2);
|
|
266
|
+
if (third) {
|
|
267
|
+
const records = await dataverseAPI.queryData("accounts?$select=name&$top=5", 2);
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Targets are zero-based; `"primary"` and `"secondary"` alias 0 and 1. Null slots retain their positions, so never filter the array before routing requests. `getSecondaryConnection()` is deprecated but supported; use `getConnection(1)` or `(await getConnections())[1]`. See the [connection-slot author guide](https://github.com/PowerPlatformToolBox/desktop-app/blob/main/docs/N_CONNECTION_TOOL_AUTHOR_GUIDE.md) for migration and lifecycle examples.
|
|
272
|
+
|
|
259
273
|
```typescript
|
|
260
274
|
// Get the active Dataverse connection
|
|
261
275
|
const connection = await toolboxAPI.connections.getActiveConnection();
|
|
@@ -339,6 +353,42 @@ const terminals = await toolboxAPI.terminal.list();
|
|
|
339
353
|
await toolboxAPI.terminal.close(terminal.id);
|
|
340
354
|
```
|
|
341
355
|
|
|
356
|
+
### Native Workers
|
|
357
|
+
|
|
358
|
+
If a tool declares a .NET worker in `pptb.config.json`, connect to it through
|
|
359
|
+
`toolboxAPI.workers.connect()`. PPTB owns process startup, consent, JSON-RPC
|
|
360
|
+
framing, readiness, request correlation, cancellation and cleanup. Tool code only
|
|
361
|
+
registers any worker-to-tool callbacks it needs, then calls worker methods by
|
|
362
|
+
name:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
const worker = await toolboxAPI.workers.connect("sample", {
|
|
366
|
+
requests: {
|
|
367
|
+
"dataverse/fetchXml": async (params, context) => {
|
|
368
|
+
if (context.isCancellationRequested) throw new Error("Request cancelled");
|
|
369
|
+
const fetchXml = String(params);
|
|
370
|
+
const result = await dataverseAPI.fetchXmlQuery(fetchXml);
|
|
371
|
+
if (context.isCancellationRequested) throw new Error("Request cancelled");
|
|
372
|
+
return { value: result.value };
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
notifications: {
|
|
376
|
+
progress: (message) => setStatus(String(message)),
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
await worker.ready;
|
|
381
|
+
const result = await worker.request("query", fetchXml);
|
|
382
|
+
await worker.stop();
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Use `worker.cancel()` to cancel outstanding requests. `worker.stop()` waits for
|
|
386
|
+
PPTB's verified process cleanup; if it rejects, keep the session and let the user
|
|
387
|
+
retry stop rather than claiming the worker was stopped. Workers are trusted
|
|
388
|
+
native code running as the current OS user, not sandboxed. Do not send tokens or
|
|
389
|
+
credential material to them; implement narrowly scoped reverse requests through
|
|
390
|
+
PPTB APIs instead.
|
|
391
|
+
|
|
342
392
|
### Events
|
|
343
393
|
|
|
344
394
|
```typescript
|
|
@@ -690,6 +740,13 @@ Core platform features organized into namespaces:
|
|
|
690
740
|
|
|
691
741
|
#### Connections
|
|
692
742
|
|
|
743
|
+
- **getConnections()**: Promise<Array<Connection | null>>
|
|
744
|
+
- Returns configured slots, preserving null gaps; not necessarily padded to the declared maximum.
|
|
745
|
+
- **getConnection(target: "primary" | "secondary" | number)**: Promise<Connection | null>
|
|
746
|
+
- Gets one slot by zero-based index or legacy alias. Unassigned slots return null; negative/fractional targets reject.
|
|
747
|
+
- **getSecondaryConnection()**: Promise<Connection | null>
|
|
748
|
+
- Deprecated compatibility adapter; prefer `getConnection("secondary")`.
|
|
749
|
+
|
|
693
750
|
- **getActiveConnection()**: Promise<Connection | null>
|
|
694
751
|
- Returns the currently active connection or null if none is active
|
|
695
752
|
- Includes `enabledForPowerPlatformAPI` so tools can decide whether to use Power Platform API
|
|
@@ -750,6 +807,21 @@ Core platform features organized into namespaces:
|
|
|
750
807
|
- **setVisibility(terminalId: string, visible: boolean)**: Promise<void>
|
|
751
808
|
- Shows or hides the terminal UI for the specified terminal id
|
|
752
809
|
|
|
810
|
+
#### Workers
|
|
811
|
+
|
|
812
|
+
- **connect(workerId: string, options?: WorkerSessionOptions)**: Promise<WorkerSession>
|
|
813
|
+
- Starts the declared worker and returns a JSON-RPC session. `ready` resolves after the protocol initialize handshake.
|
|
814
|
+
- `options.requests` registers worker-initiated requests handled by the tool; `options.notifications` handles worker notifications; `options.onExit` observes process termination.
|
|
815
|
+
- **WorkerSession.request<Result>(method: string, params?: unknown)**: Promise<Result>
|
|
816
|
+
- Sends a named request to the worker and resolves with its result.
|
|
817
|
+
- **WorkerSession.notify(method: string, params?: unknown)**: Promise<void>
|
|
818
|
+
- Sends a notification to the worker.
|
|
819
|
+
- **WorkerSession.cancel()**: void
|
|
820
|
+
- Requests cancellation of outstanding requests. Worker and callback cancellation is cooperative.
|
|
821
|
+
- **WorkerSession.stop() / dispose()**: Promise<void>
|
|
822
|
+
- Stops the worker and waits for verified cleanup. A failed stop must remain visible and retryable.
|
|
823
|
+
- **WorkerSessionOptions.requests** handlers receive `(params, context)`, where `context.isCancellationRequested` and `context.onCancellationRequested()` expose cancellation without exposing transport details.
|
|
824
|
+
|
|
753
825
|
#### Events
|
|
754
826
|
|
|
755
827
|
- **getHistory(limit?: number)**: Promise<ToolBoxEventPayload[]>
|
|
@@ -784,7 +856,7 @@ Core platform features organized into namespaces:
|
|
|
784
856
|
- **launchTool(targetToolId, prefillData?, options?)**: Promise\<unknown\>
|
|
785
857
|
- Launches the specified tool, optionally with prefill data
|
|
786
858
|
- Returns a Promise that resolves with the data returned by the callee, or `null` if it closes without returning or the user clicks the "Return to Caller" banner
|
|
787
|
-
- The callee
|
|
859
|
+
- The callee inherits the caller's full positional connection array, bounded by its declared maximum; `options.connectionIds` replaces the array and legacy overrides affect only slots 0/1
|
|
788
860
|
- Only one active callee per caller is allowed; throws `"A callee invocation is already in progress"` if a callee is already open
|
|
789
861
|
- Pass `options.noReturn: true` for one-way "Send To" flows; the banner is suppressed entirely for the callee
|
|
790
862
|
|
|
@@ -835,13 +907,13 @@ Complete HTTP client for interacting with Microsoft Dataverse:
|
|
|
835
907
|
- Supports both bound and unbound operations
|
|
836
908
|
- **publishCustomizations(tableLogicalName?: string)**: Promise<void>
|
|
837
909
|
- Publishes pending customizations. When `tableLogicalName` is omitted it runs PublishAllXml; otherwise it publishes only the specified table.
|
|
838
|
-
- **deploySolution(base64SolutionContent: string | ArrayBuffer | ArrayBufferView, options?: DeploySolutionOptions, connectionTarget?: "primary" | "secondary")**: Promise<{ImportJobId: string}>
|
|
910
|
+
- **deploySolution(base64SolutionContent: string | ArrayBuffer | ArrayBufferView, options?: DeploySolutionOptions, connectionTarget?: "primary" | "secondary" | number)**: Promise<{ImportJobId: string}>
|
|
839
911
|
- Deploys (imports) a solution to the Dataverse environment
|
|
840
912
|
- Accepts either a base64-encoded solution zip string or raw binary data (Buffer, ArrayBuffer, Uint8Array)
|
|
841
913
|
- Always supplies `PublishWorkflows` and `OverwriteUnmanagedCustomizations` booleans to Dataverse, defaulting to `false` when you omit them
|
|
842
914
|
- Supports optional parameters for customizing the import (publishWorkflows, overwriteUnmanagedCustomizations, skipProductUpdateDependencies, convertToManaged)
|
|
843
915
|
- Returns an ImportJobId for tracking the import progress
|
|
844
|
-
- **getImportJobStatus(importJobId: string, connectionTarget?: "primary" | "secondary")**: Promise<Record<string, unknown>>
|
|
916
|
+
- **getImportJobStatus(importJobId: string, connectionTarget?: "primary" | "secondary" | number)**: Promise<Record<string, unknown>>
|
|
845
917
|
- Gets the status of a solution import job
|
|
846
918
|
- Returns import job details including progress, completion status, and error information
|
|
847
919
|
- Use to track the progress of a solution deployment initiated with deploySolution
|
|
@@ -852,6 +924,8 @@ Generic HTTP client for Power Platform Admin APIs covering all categories:
|
|
|
852
924
|
|
|
853
925
|
#### Category Methods
|
|
854
926
|
|
|
927
|
+
`connectionTarget` accepts zero-based numeric slots plus `"primary"` / `"secondary"`. For example, `powerplatformAPI.PowerApps.Get("apps", 2)` routes to slot 3. Calling an API with an unassigned slot returns a missing-connection error.
|
|
928
|
+
|
|
855
929
|
Each category (Analytics, AppManagement, Authorization, Connectivity, CopilotStudio, Dynamics, EnvironmentManagement, Governance, Licensing, PowerApps, PowerAutomate, PowerPages, ResourceQuery, UserManagement, WorkflowAgents) exposes:
|
|
856
930
|
|
|
857
931
|
- **Get(path?, connectionTarget?, headers?)**: Promise<PowerPlatformResponse>
|
package/package.json
CHANGED
package/pptbConfig.d.ts
CHANGED
|
@@ -174,15 +174,40 @@ export interface InvocationConfig {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* This file lives alongside `package.json` in the tool's package root.
|
|
180
|
-
* All sections are optional; the file itself is optional. When present it
|
|
181
|
-
* is validated by `pptb-validate` in addition to `package.json`.
|
|
177
|
+
* Author-facing runtime policy. Latest maps to native LatestMajor in later runtime work.
|
|
182
178
|
*/
|
|
179
|
+
export type WorkerRollForward = "Disable" | "Latest" | "Minor" | "Major";
|
|
180
|
+
export type WorkerTargetFramework = "net8.0" | "net9.0" | "net10.0";
|
|
181
|
+
export type WorkerPlatform = "all" | "windows-x64" | "windows-arm64" | "macos-x64" | "macos-arm64" | "linux-x64" | "linux-arm64";
|
|
182
|
+
|
|
183
|
+
/** Declarative metadata only; no worker execution API is available yet. */
|
|
184
|
+
export interface WorkerDeclaration {
|
|
185
|
+
kind: "dotnet-tool";
|
|
186
|
+
packageId: string;
|
|
187
|
+
/** Exact NuGet version; ranges, floating versions and tags are forbidden. */
|
|
188
|
+
packageVersion: string;
|
|
189
|
+
command: string;
|
|
190
|
+
dotnet: {
|
|
191
|
+
targetFramework: WorkerTargetFramework;
|
|
192
|
+
/** Stable major.minor.patch matching the executable target framework. */
|
|
193
|
+
minimumRuntimeVersion: string;
|
|
194
|
+
/** Defaults to Major when omitted. Explicit null/empty/unknown values are invalid. */
|
|
195
|
+
rollForward?: WorkerRollForward;
|
|
196
|
+
};
|
|
197
|
+
/** Required unique aliases; all must appear alone and names the versioned officially supported PPTB platform matrix. */
|
|
198
|
+
platforms: WorkerPlatform[];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface NormalizedWorkerDeclaration extends WorkerDeclaration {
|
|
202
|
+
dotnet: WorkerDeclaration["dotnet"] & { rollForward: WorkerRollForward };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Optional package-root config, validated alongside package.json by pptb-validate. */
|
|
183
206
|
export interface PPTBConfig {
|
|
184
207
|
/** Invocation contract – how this tool can be called by other tools. */
|
|
185
208
|
invocation?: InvocationConfig;
|
|
186
209
|
/** Agent contract – how this tool can be called by external automation. */
|
|
187
210
|
agents?: AgentsConfig;
|
|
211
|
+
/** Native worker declarations keyed by stable ID. Requires package.json features.minAPI. */
|
|
212
|
+
workers?: Record<string, WorkerDeclaration>;
|
|
188
213
|
}
|
package/toolboxAPI.d.ts
CHANGED
|
@@ -169,6 +169,55 @@ declare namespace ToolBoxAPI {
|
|
|
169
169
|
error?: string;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
const workerHandleBrand: unique symbol;
|
|
173
|
+
export type WorkerHandle = string & { readonly [workerHandleBrand]: true };
|
|
174
|
+
|
|
175
|
+
export type WorkerRpcMessage =
|
|
176
|
+
| { jsonrpc: "2.0"; method: string; id?: string | number; params?: unknown[] | Record<string, unknown> }
|
|
177
|
+
| { jsonrpc: "2.0"; id: string | number | null; result: unknown }
|
|
178
|
+
| { jsonrpc: "2.0"; id: string | number | null; error: { code: number; message: string; data?: unknown } };
|
|
179
|
+
|
|
180
|
+
export interface WorkerSnapshot {
|
|
181
|
+
state: "starting" | "running" | "stopping" | "exited" | "failed";
|
|
182
|
+
failure?: string;
|
|
183
|
+
stderr: { bytes: number; truncated: boolean; summary: "Worker stderr redacted" };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface WorkerStart {
|
|
187
|
+
handle: WorkerHandle;
|
|
188
|
+
ready: Promise<void>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface WorkerRequestContext {
|
|
192
|
+
readonly isCancellationRequested: boolean;
|
|
193
|
+
onCancellationRequested(callback: () => void): { dispose(): void };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface WorkerSessionOptions {
|
|
197
|
+
requests?: Record<string, (params: unknown, context: WorkerRequestContext) => unknown | Promise<unknown>>;
|
|
198
|
+
notifications?: Record<string, (params: unknown) => void>;
|
|
199
|
+
onExit?: (snapshot: WorkerSnapshot) => void;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface WorkerSession {
|
|
203
|
+
readonly ready: Promise<void>;
|
|
204
|
+
request<Result = unknown>(method: string, params?: unknown): Promise<Result>;
|
|
205
|
+
notify(method: string, params?: unknown): Promise<void>;
|
|
206
|
+
cancel(): void;
|
|
207
|
+
stop(): Promise<void>;
|
|
208
|
+
dispose(): Promise<void>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface WorkersAPI {
|
|
212
|
+
connect(workerId: string, options?: WorkerSessionOptions): Promise<WorkerSession>;
|
|
213
|
+
start(workerId: string): Promise<WorkerStart>;
|
|
214
|
+
send(handle: WorkerHandle, message: WorkerRpcMessage): Promise<void>;
|
|
215
|
+
onMessage(handle: WorkerHandle, callback: (message: WorkerRpcMessage) => void): () => void;
|
|
216
|
+
onExit(handle: WorkerHandle, callback: (snapshot: WorkerSnapshot) => void): () => void;
|
|
217
|
+
stop(handle: WorkerHandle): Promise<void>;
|
|
218
|
+
dispose(handle: WorkerHandle): Promise<void>;
|
|
219
|
+
}
|
|
220
|
+
|
|
172
221
|
/**
|
|
173
222
|
* Connections namespace - restricted access for tools
|
|
174
223
|
*/
|
|
@@ -179,7 +228,7 @@ declare namespace ToolBoxAPI {
|
|
|
179
228
|
getActiveConnection: () => Promise<Connection | null>;
|
|
180
229
|
|
|
181
230
|
/**
|
|
182
|
-
* @deprecated Use `getConnection("secondary")` or `getConnections()[1]` for slot-aware connection access.
|
|
231
|
+
* @deprecated Use `getConnection("secondary")` or `(await getConnections())[1]` for slot-aware connection access.
|
|
183
232
|
*/
|
|
184
233
|
getSecondaryConnection: () => Promise<Connection | null>;
|
|
185
234
|
|
|
@@ -406,6 +455,9 @@ declare namespace ToolBoxAPI {
|
|
|
406
455
|
* Main ToolBox API exposed to tools via window.toolboxAPI
|
|
407
456
|
*/
|
|
408
457
|
export interface API {
|
|
458
|
+
/** Start and communicate with a worker declared by this tool's manifest. */
|
|
459
|
+
workers: WorkersAPI;
|
|
460
|
+
|
|
409
461
|
/**
|
|
410
462
|
* Connection-related operations (restricted)
|
|
411
463
|
*/
|