@peers-app/peers-sdk 0.25.17 → 0.25.19
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 +9 -1
- package/dist/contracts/__tests__/action-dispatch.test.d.ts +1 -0
- package/dist/contracts/__tests__/action-dispatch.test.js +339 -0
- package/dist/contracts/__tests__/contract-proxy.test.js +24 -1
- package/dist/contracts/__tests__/contract-resolvers.test.js +3 -0
- package/dist/contracts/__tests__/generic-tool-dispatch.test.d.ts +1 -0
- package/dist/contracts/__tests__/generic-tool-dispatch.test.js +173 -0
- package/dist/contracts/action-dispatch.d.ts +12 -0
- package/dist/contracts/action-dispatch.js +73 -0
- package/dist/contracts/contract-provider-router.d.ts +16 -2
- package/dist/contracts/contract-provider-router.js +11 -1
- package/dist/contracts/contract-providers.table.d.ts +2 -2
- package/dist/contracts/contract-proxy.d.ts +58 -0
- package/dist/contracts/contract-proxy.js +163 -19
- package/dist/contracts/contract-resolvers.js +12 -1
- package/dist/contracts/index.d.ts +5 -1
- package/dist/contracts/index.js +21 -2
- package/dist/contracts/system/contract-catalog-contract.d.ts +40 -0
- package/dist/contracts/system/contract-catalog-contract.js +51 -0
- package/dist/contracts/system/http-contract.d.ts +80 -0
- package/dist/contracts/system/http-contract.js +93 -0
- package/dist/contracts/system/index.d.ts +3 -0
- package/dist/contracts/system/index.js +3 -0
- package/dist/contracts/system/scheduler-contract.d.ts +54 -0
- package/dist/contracts/system/scheduler-contract.js +70 -0
- package/dist/data/messages.d.ts +3 -3
- package/dist/data/package-versions.d.ts +10 -10
- package/dist/data/tool-access-approvals.d.ts +3 -3
- package/dist/data/tool-access.d.ts +3 -1
- package/dist/data/tool-access.js +5 -2
- package/dist/data/tool-access.test.js +7 -0
- package/dist/data/tools.d.ts +7 -3
- package/dist/data/tools.js +7 -1
- package/dist/invites/invite-messages.d.ts +2 -2
- package/dist/package-loader/host-authority-loading.test.d.ts +1 -0
- package/dist/package-loader/host-authority-loading.test.js +87 -0
- package/dist/package-loader/host-dispatch-policy.test.d.ts +1 -0
- package/dist/package-loader/host-dispatch-policy.test.js +56 -0
- package/dist/package-loader/index.d.ts +1 -0
- package/dist/package-loader/index.js +1 -0
- package/dist/package-loader/isolated-artifact.d.ts +53 -2
- package/dist/package-loader/isolated-artifact.js +118 -4
- package/dist/package-loader/isolated-artifact.test.js +63 -0
- package/dist/package-loader/isolated-persistent-var-gateway.js +19 -0
- package/dist/package-loader/isolated-runtime.d.ts +43 -1
- package/dist/package-loader/package-loader.d.ts +2 -0
- package/dist/package-loader/package-loader.js +64 -0
- package/dist/package-loader/package-loader.test.js +50 -2
- package/dist/package-loader/package-network-policy.d.ts +52 -0
- package/dist/package-loader/package-network-policy.js +62 -0
- package/dist/system-ids.d.ts +31 -0
- package/dist/system-ids.js +32 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { DataContext } from "../context/data-context";
|
|
1
2
|
import type { IContractProviderEndpointRequest } from "../contracts/contract-provider-router";
|
|
2
3
|
import type { IContractCall, IContractProviderEndpoint } from "../contracts/contract-proxy";
|
|
3
4
|
import type { ContractRegistry } from "../contracts/registry";
|
|
4
5
|
import type { PersistentVarScope } from "../data/persistent-vars";
|
|
5
6
|
import type { IField } from "../types/field-type";
|
|
6
|
-
import type { IIsolatedInstallResult, IIsolatedPackageArtifact } from "./isolated-artifact";
|
|
7
|
+
import type { IIsolatedContractToolRef, IIsolatedInstallResult, IIsolatedPackageArtifact } from "./isolated-artifact";
|
|
7
8
|
/** Standard table methods exposed through isolated contract-table references. */
|
|
8
9
|
export declare const ISOLATED_CONTRACT_TABLE_OPERATIONS: readonly ["get", "list", "count", "findOne", "save", "insert", "update", "delete"];
|
|
9
10
|
/** Consumer-callable operation on an isolated contract table. */
|
|
@@ -14,6 +15,14 @@ export type IsolatedContractTableOperation = (typeof ISOLATED_CONTRACT_TABLE_OPE
|
|
|
14
15
|
*/
|
|
15
16
|
export interface IIsolatedCallPrincipal {
|
|
16
17
|
userAccessLevel: number;
|
|
18
|
+
/** Signed identity retained by the host across local hops. */
|
|
19
|
+
userId?: string;
|
|
20
|
+
/** Strict runtime tool-dispatch scope; never supplied by guest arguments. */
|
|
21
|
+
strictActionScope?: boolean;
|
|
22
|
+
/** Effective level of the currently executing ordinary tool. */
|
|
23
|
+
callingToolAccessLevel?: number;
|
|
24
|
+
/** Effective permission from the host, never requested package metadata. */
|
|
25
|
+
authorityPropagation?: "cap" | "preserve";
|
|
17
26
|
/** Omit for a direct user invocation. */
|
|
18
27
|
assistantAccessLevel?: number;
|
|
19
28
|
}
|
|
@@ -73,6 +82,25 @@ export interface IIsolatedPackageRuntime {
|
|
|
73
82
|
provides(contractId: string, version: number): boolean;
|
|
74
83
|
/** True when this runtime has installed `packageId`. */
|
|
75
84
|
isInstalled(packageId: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Run a tool the package provides, starting its worker if needed.
|
|
87
|
+
*
|
|
88
|
+
* Used by System Scheduler. The principal defaults to Self for compatibility,
|
|
89
|
+
* but schedulers should pass the current user's trusted access level.
|
|
90
|
+
*
|
|
91
|
+
* @param packageId - Installed package that declares the tool.
|
|
92
|
+
* @param ref - Contract tool to invoke.
|
|
93
|
+
* @param args - JSON value passed as the tool argument.
|
|
94
|
+
* @param principal - Trusted caller authority. Defaults to Self when omitted.
|
|
95
|
+
*/
|
|
96
|
+
invokeOwnedTool?(packageId: string, ref: IIsolatedContractToolRef, args: unknown, principal?: IIsolatedCallPrincipal): Promise<unknown>;
|
|
97
|
+
/** Narrow a projected action turn by the trusted consumer's selected contract consume ceiling. */
|
|
98
|
+
actionDispatchPrincipal?(principal: IIsolatedCallPrincipal, consumerPackageId?: string, ref?: IIsolatedContractToolRef): IIsolatedCallPrincipal;
|
|
99
|
+
/** Project aliases whose wrapper and canonical targets allow the trusted caller. */
|
|
100
|
+
authorizedActionNames?(packageId: string, principal: IIsolatedCallPrincipal, consumerPackageId?: string, selectedContract?: {
|
|
101
|
+
contractId: string;
|
|
102
|
+
version: number;
|
|
103
|
+
}): string[] | Promise<string[]>;
|
|
76
104
|
/** Terminate every worker and drop installed state. */
|
|
77
105
|
dispose(): Promise<void>;
|
|
78
106
|
}
|
|
@@ -199,12 +227,26 @@ export interface IIsolatedContractProviderGateway {
|
|
|
199
227
|
*/
|
|
200
228
|
resolveEndpoint(request: IIsolatedContractProviderEndpointRequest): Promise<IContractProviderEndpoint | undefined>;
|
|
201
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Resolve the signed-in local user for a runtime's owning data context.
|
|
232
|
+
*
|
|
233
|
+
* Invoked only by the host for guest-originated gateway calls. The user id and
|
|
234
|
+
* data context must come from authenticated host state, never guest payloads.
|
|
235
|
+
* Return `undefined` when no signed-in identity is available; protected tools
|
|
236
|
+
* then retain their existing missing-caller-identity denial.
|
|
237
|
+
*/
|
|
238
|
+
export type IsolatedLocalUserContextResolver = () => {
|
|
239
|
+
userId: string;
|
|
240
|
+
dataContext: DataContext;
|
|
241
|
+
} | undefined;
|
|
202
242
|
/** Options passed to a registered {@link IsolatedPackageRuntimeFactory}. */
|
|
203
243
|
export interface IIsolatedPackageRuntimeFactoryOptions {
|
|
204
244
|
/** Shared per-data-context contract registry from {@link PackageLoader}. */
|
|
205
245
|
registry: ContractRegistry;
|
|
206
246
|
/** Owning data-context id (personal user id or group id). */
|
|
207
247
|
dataContextId: string;
|
|
248
|
+
/** Trusted local identity and role-lookup context for guest-to-host calls. */
|
|
249
|
+
getLocalUserContext?: IsolatedLocalUserContextResolver;
|
|
208
250
|
/**
|
|
209
251
|
* Host-owned table capability for this data context. Required when an
|
|
210
252
|
* isolated package declares tables.
|
|
@@ -28,6 +28,7 @@ export declare class PackageLoader {
|
|
|
28
28
|
static PeersSDK: any;
|
|
29
29
|
/** Host-injected Zod module used as the `zod` require. */
|
|
30
30
|
static Zod: any;
|
|
31
|
+
private hostConsumes;
|
|
31
32
|
private packageInstances;
|
|
32
33
|
/** Packages that were installed via the contract-based path (tools/assistants/tables already saved with packageId). */
|
|
33
34
|
private contractInstalledPackages;
|
|
@@ -64,6 +65,7 @@ export declare class PackageLoader {
|
|
|
64
65
|
isIsolatedInstalled(packageId: string): boolean;
|
|
65
66
|
/** Return whether this host configured an isolated-package runtime. */
|
|
66
67
|
supportsIsolatedPackages(): boolean;
|
|
68
|
+
private dispatchToolFromProvider;
|
|
67
69
|
/**
|
|
68
70
|
* Return the active provider selected by this data context's trusted registry.
|
|
69
71
|
*
|
|
@@ -45,6 +45,7 @@ class PackageLoader {
|
|
|
45
45
|
static PeersSDK;
|
|
46
46
|
/** Host-injected Zod module used as the `zod` require. */
|
|
47
47
|
static Zod;
|
|
48
|
+
hostConsumes = new Map();
|
|
48
49
|
packageInstances = {};
|
|
49
50
|
/** Packages that were installed via the contract-based path (tools/assistants/tables already saved with packageId). */
|
|
50
51
|
contractInstalledPackages = new Set();
|
|
@@ -74,6 +75,10 @@ class PackageLoader {
|
|
|
74
75
|
this.isolatedRuntime = factory({
|
|
75
76
|
registry: this.contractRegistry,
|
|
76
77
|
dataContextId: dataContext.dataContextId,
|
|
78
|
+
getLocalUserContext: () => {
|
|
79
|
+
const userId = this.dataContext.userContext?.userId;
|
|
80
|
+
return userId ? { userId, dataContext: this.dataContext } : undefined;
|
|
81
|
+
},
|
|
77
82
|
tableGateway: dataContext.tableContainer
|
|
78
83
|
? (0, isolated_table_gateway_1.createIsolatedPackageTableGateway)(dataContext)
|
|
79
84
|
: undefined,
|
|
@@ -110,6 +115,62 @@ class PackageLoader {
|
|
|
110
115
|
supportsIsolatedPackages() {
|
|
111
116
|
return this.isolatedRuntime !== undefined;
|
|
112
117
|
}
|
|
118
|
+
async dispatchToolFromProvider(packageId, target, args, context) {
|
|
119
|
+
if (!context.authority?.userId ||
|
|
120
|
+
!context.dataContext ||
|
|
121
|
+
context.dataContext.dataContextId !== this.dataContext.dataContextId)
|
|
122
|
+
throw new Error("Missing trusted execution context");
|
|
123
|
+
if (target.targetDeviceId)
|
|
124
|
+
throw new Error("Strict delegated calls cannot target another device until authority transport is supported");
|
|
125
|
+
if (target.dataContextId && target.dataContextId !== this.dataContext.dataContextId)
|
|
126
|
+
throw new Error("Cross-context action dispatch is denied");
|
|
127
|
+
const own = this.contractRegistry
|
|
128
|
+
.getRegisteredProviderIds(target.contractId, target.version)
|
|
129
|
+
.includes(packageId);
|
|
130
|
+
const consume = this.hostConsumes
|
|
131
|
+
.get(packageId)
|
|
132
|
+
?.find((c) => c.contractId === target.contractId && c.version === target.version);
|
|
133
|
+
if (!own && !consume)
|
|
134
|
+
throw new Error("Undeclared contract consumption");
|
|
135
|
+
if (own && target.providerPackageId && target.providerPackageId !== packageId && !consume)
|
|
136
|
+
throw new Error("Provider substitution is denied for package-owned targets");
|
|
137
|
+
const selected = own && (!target.providerPackageId || target.providerPackageId === packageId)
|
|
138
|
+
? packageId
|
|
139
|
+
: consume
|
|
140
|
+
? this.contractRegistry.selectProvider(consume)?.providerPackageId
|
|
141
|
+
: undefined;
|
|
142
|
+
if (!selected)
|
|
143
|
+
throw new Error("No declared contract provider is available");
|
|
144
|
+
if (target.providerPackageId && target.providerPackageId !== selected)
|
|
145
|
+
throw new Error("Provider substitution is denied");
|
|
146
|
+
const providerPackageId = selected;
|
|
147
|
+
const authority = this.isolatedRuntime?.actionDispatchPrincipal?.(context.authority, packageId, target) ??
|
|
148
|
+
context.authority;
|
|
149
|
+
const callContext = { ...context, authority, callerPackageId: packageId };
|
|
150
|
+
const endpoint = await this.resolveContractEndpoint({
|
|
151
|
+
contractId: target.contractId,
|
|
152
|
+
version: target.version,
|
|
153
|
+
dataContextId: this.dataContext.dataContextId,
|
|
154
|
+
providerPackageId,
|
|
155
|
+
context: callContext,
|
|
156
|
+
notify: async () => undefined,
|
|
157
|
+
});
|
|
158
|
+
try {
|
|
159
|
+
return await endpoint.handleCall({
|
|
160
|
+
contractId: target.contractId,
|
|
161
|
+
version: target.version,
|
|
162
|
+
name: target.toolName,
|
|
163
|
+
member: "tool",
|
|
164
|
+
operation: "run",
|
|
165
|
+
args: [args],
|
|
166
|
+
providerPackageId,
|
|
167
|
+
dataContextId: this.dataContext.dataContextId,
|
|
168
|
+
}, callContext);
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
endpoint.dispose();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
113
174
|
/**
|
|
114
175
|
* Return the active provider selected by this data context's trusted registry.
|
|
115
176
|
*
|
|
@@ -201,6 +262,7 @@ class PackageLoader {
|
|
|
201
262
|
}
|
|
202
263
|
: resolution;
|
|
203
264
|
const endpoint = (0, contract_proxy_1.createContractProviderEndpoint)(localResolution, {
|
|
265
|
+
dispatchTool: (target, args, context) => this.dispatchToolFromProvider(providerPackageId, target, args, context),
|
|
204
266
|
context: request.context,
|
|
205
267
|
notify: (notification) => request.notify({
|
|
206
268
|
...notification,
|
|
@@ -314,6 +376,7 @@ class PackageLoader {
|
|
|
314
376
|
* @param packageId - Package to unload.
|
|
315
377
|
*/
|
|
316
378
|
async unloadPackage(packageId) {
|
|
379
|
+
this.hostConsumes.delete(packageId);
|
|
317
380
|
if (this.isolatedRuntime?.isInstalled(packageId)) {
|
|
318
381
|
await this.isolatedRuntime.uninstall(packageId);
|
|
319
382
|
}
|
|
@@ -625,6 +688,7 @@ class PackageLoader {
|
|
|
625
688
|
await (0, contract_package_loader_1.installContractPackage)(this.dataContext, packageDefinition, {
|
|
626
689
|
registry: this.contractRegistry,
|
|
627
690
|
});
|
|
691
|
+
this.hostConsumes.set(packageDefinition.packageId, packageDefinition.consumes);
|
|
628
692
|
this.contractInstalledPackages.add(packageDefinition.packageId);
|
|
629
693
|
await this.correctPackageVersion(pkg, selectedPackageVersion, packageDefinition.version);
|
|
630
694
|
// Build a proper IPeersPackage from the contract definition so callers
|
|
@@ -12,6 +12,7 @@ jest.mock("../data/package-versions", () => ({
|
|
|
12
12
|
}));
|
|
13
13
|
const contract_resolvers_1 = require("../contracts/contract-resolvers");
|
|
14
14
|
const registry_1 = require("../contracts/registry");
|
|
15
|
+
const access_level_1 = require("../data/access-level");
|
|
15
16
|
const system_ids_1 = require("../system-ids");
|
|
16
17
|
const utils_1 = require("../utils");
|
|
17
18
|
const isolated_artifact_1 = require("./isolated-artifact");
|
|
@@ -142,6 +143,46 @@ describe("PackageLoader.contractRegistry", () => {
|
|
|
142
143
|
expect(resolver).toHaveBeenCalledWith({ dataContext });
|
|
143
144
|
endpoint.dispose();
|
|
144
145
|
});
|
|
146
|
+
it("does not supply local identity to ordinary callers that omit it", async () => {
|
|
147
|
+
const userId = (0, utils_1.newid)();
|
|
148
|
+
const dataContext = {
|
|
149
|
+
dataContextId: userId,
|
|
150
|
+
userContext: { userId, deviceId: () => "local-device" },
|
|
151
|
+
};
|
|
152
|
+
const loader = new package_loader_1.PackageLoader(dataContext);
|
|
153
|
+
const contractId = (0, utils_1.newid)();
|
|
154
|
+
const write = jest.fn();
|
|
155
|
+
(0, contract_resolvers_1.registerContractResolver)(contractId, 1, () => ({
|
|
156
|
+
contractId,
|
|
157
|
+
version: 1,
|
|
158
|
+
tools: {
|
|
159
|
+
invoke: {
|
|
160
|
+
tool: { toolId: (0, utils_1.newid)(), name: "invoke", accessLevel: access_level_1.AccessLevel.Writer },
|
|
161
|
+
toolFn: write,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}));
|
|
165
|
+
const endpoint = await loader.resolveContractEndpoint({
|
|
166
|
+
contractId,
|
|
167
|
+
version: 1,
|
|
168
|
+
context: {},
|
|
169
|
+
notify: async () => undefined,
|
|
170
|
+
});
|
|
171
|
+
try {
|
|
172
|
+
await expect(endpoint.handleCall({
|
|
173
|
+
contractId,
|
|
174
|
+
version: 1,
|
|
175
|
+
member: "tool",
|
|
176
|
+
name: "invoke",
|
|
177
|
+
operation: "run",
|
|
178
|
+
args: [],
|
|
179
|
+
})).rejects.toThrow("missing caller identity or trusted context for tool 'invoke'");
|
|
180
|
+
expect(write).not.toHaveBeenCalled();
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
endpoint.dispose();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
145
186
|
});
|
|
146
187
|
const mockGetFileContents = jest.fn();
|
|
147
188
|
jest.mock("../data/files", () => ({
|
|
@@ -364,8 +405,8 @@ describe("PackageLoader isolated artifacts", () => {
|
|
|
364
405
|
await expect(loader.loadPackage(pkg)).rejects.toThrow(/JSON is invalid/);
|
|
365
406
|
expect(globalThis.__shouldNotEvalOnHost).toBeUndefined();
|
|
366
407
|
});
|
|
367
|
-
it("passes
|
|
368
|
-
const factory = jest.fn(() => ({
|
|
408
|
+
it("passes gateways and a trusted local identity resolver from its data context", () => {
|
|
409
|
+
const factory = jest.fn((_options) => ({
|
|
369
410
|
install: jest.fn(async () => ({ packageId, provided: [], consumes: [] })),
|
|
370
411
|
replace: jest.fn(async () => ({ packageId, provided: [], consumes: [] })),
|
|
371
412
|
uninstall: jest.fn(async () => undefined),
|
|
@@ -381,11 +422,13 @@ describe("PackageLoader isolated artifacts", () => {
|
|
|
381
422
|
tableContainer,
|
|
382
423
|
};
|
|
383
424
|
dataContext.userContext = {
|
|
425
|
+
userId: (0, utils_1.newid)(),
|
|
384
426
|
userDataContext: dataContext,
|
|
385
427
|
};
|
|
386
428
|
new package_loader_1.PackageLoader(dataContext);
|
|
387
429
|
expect(factory).toHaveBeenCalledWith(expect.objectContaining({
|
|
388
430
|
dataContextId: "ctx-tables",
|
|
431
|
+
getLocalUserContext: expect.any(Function),
|
|
389
432
|
providerGateway: expect.objectContaining({
|
|
390
433
|
resolveEndpoint: expect.any(Function),
|
|
391
434
|
}),
|
|
@@ -399,6 +442,11 @@ describe("PackageLoader isolated artifacts", () => {
|
|
|
399
442
|
save: expect.any(Function),
|
|
400
443
|
}),
|
|
401
444
|
}));
|
|
445
|
+
const resolveLocalUser = factory.mock.calls[0][0].getLocalUserContext;
|
|
446
|
+
expect(resolveLocalUser?.()).toEqual({ userId: dataContext.userContext.userId, dataContext });
|
|
447
|
+
expect(resolveLocalUser?.()?.dataContext).toBe(dataContext);
|
|
448
|
+
dataContext.userContext = undefined;
|
|
449
|
+
expect(resolveLocalUser?.()).toBeUndefined();
|
|
402
450
|
});
|
|
403
451
|
it("unloads an isolated package on force reload and disable", async () => {
|
|
404
452
|
const runtime = makeRuntime();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side record of an isolated package's declared outbound HTTP policy.
|
|
3
|
+
*
|
|
4
|
+
* Populated when the isolated runtime installs a manifest and read by System HTTP.
|
|
5
|
+
* Secrets are not stored here; {@link IPackageNetworkCredential.secretVar} is a
|
|
6
|
+
* logical name the host resolves at request time.
|
|
7
|
+
*/
|
|
8
|
+
/** How System HTTP injects one secret the guest never receives. */
|
|
9
|
+
export interface IPackageNetworkCredential {
|
|
10
|
+
/** Name the guest passes as `credentialRef`. */
|
|
11
|
+
ref: string;
|
|
12
|
+
/** Logical persistent-variable name. The host prefixes it with the package id. */
|
|
13
|
+
secretVar: string;
|
|
14
|
+
/** Where the secret persistent variable lives. Defaults to `user`. */
|
|
15
|
+
scope?: "user" | "device";
|
|
16
|
+
/** Request header the host sets from the secret. */
|
|
17
|
+
header: string;
|
|
18
|
+
/** Header value template. Must contain the literal `{secret}`. */
|
|
19
|
+
format: string;
|
|
20
|
+
}
|
|
21
|
+
/** Outbound HTTP permission recorded for one installed package in one data context. */
|
|
22
|
+
export interface IPackageNetworkPolicy {
|
|
23
|
+
/** Exact hostnames the package may request. `https` only. */
|
|
24
|
+
allowedHosts: string[];
|
|
25
|
+
/** Secrets the host may attach. The guest names a `ref`, never the value. */
|
|
26
|
+
credentials: IPackageNetworkCredential[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Record or clear the network policy for one package in one data context.
|
|
30
|
+
*
|
|
31
|
+
* Pass `undefined` when the package is uninstalled or declares no network block.
|
|
32
|
+
* The policy is process memory; install republishes it.
|
|
33
|
+
*
|
|
34
|
+
* @param dataContextId - Personal or group context that installed the package.
|
|
35
|
+
* @param packageId - Trusted package id from the manifest, not from a guest payload.
|
|
36
|
+
* @param policy - Declared allowlist and credential refs, or `undefined` to forget it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function setPackageNetworkPolicy(dataContextId: string, packageId: string, policy: IPackageNetworkPolicy | undefined): void;
|
|
39
|
+
/**
|
|
40
|
+
* Return the network policy installed for this package, if it declared one.
|
|
41
|
+
*
|
|
42
|
+
* @param dataContextId - Context whose runtime installed the package.
|
|
43
|
+
* @param packageId - Package that is calling System HTTP.
|
|
44
|
+
* @returns A copy of the policy, or `undefined` when HTTP is not declared.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getPackageNetworkPolicy(dataContextId: string, packageId: string): IPackageNetworkPolicy | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Drop every recorded network policy.
|
|
49
|
+
*
|
|
50
|
+
* @internal Test-only. Production install and uninstall update one package at a time.
|
|
51
|
+
*/
|
|
52
|
+
export declare function _clearPackageNetworkPoliciesForTests(): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Host-side record of an isolated package's declared outbound HTTP policy.
|
|
4
|
+
*
|
|
5
|
+
* Populated when the isolated runtime installs a manifest and read by System HTTP.
|
|
6
|
+
* Secrets are not stored here; {@link IPackageNetworkCredential.secretVar} is a
|
|
7
|
+
* logical name the host resolves at request time.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.setPackageNetworkPolicy = setPackageNetworkPolicy;
|
|
11
|
+
exports.getPackageNetworkPolicy = getPackageNetworkPolicy;
|
|
12
|
+
exports._clearPackageNetworkPoliciesForTests = _clearPackageNetworkPoliciesForTests;
|
|
13
|
+
const policies = new Map();
|
|
14
|
+
function policyKey(dataContextId, packageId) {
|
|
15
|
+
return `${dataContextId}:${packageId}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Record or clear the network policy for one package in one data context.
|
|
19
|
+
*
|
|
20
|
+
* Pass `undefined` when the package is uninstalled or declares no network block.
|
|
21
|
+
* The policy is process memory; install republishes it.
|
|
22
|
+
*
|
|
23
|
+
* @param dataContextId - Personal or group context that installed the package.
|
|
24
|
+
* @param packageId - Trusted package id from the manifest, not from a guest payload.
|
|
25
|
+
* @param policy - Declared allowlist and credential refs, or `undefined` to forget it.
|
|
26
|
+
*/
|
|
27
|
+
function setPackageNetworkPolicy(dataContextId, packageId, policy) {
|
|
28
|
+
const key = policyKey(dataContextId, packageId);
|
|
29
|
+
if (!policy) {
|
|
30
|
+
policies.delete(key);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
policies.set(key, {
|
|
34
|
+
allowedHosts: [...policy.allowedHosts],
|
|
35
|
+
credentials: policy.credentials.map((credential) => ({ ...credential })),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Return the network policy installed for this package, if it declared one.
|
|
40
|
+
*
|
|
41
|
+
* @param dataContextId - Context whose runtime installed the package.
|
|
42
|
+
* @param packageId - Package that is calling System HTTP.
|
|
43
|
+
* @returns A copy of the policy, or `undefined` when HTTP is not declared.
|
|
44
|
+
*/
|
|
45
|
+
function getPackageNetworkPolicy(dataContextId, packageId) {
|
|
46
|
+
const policy = policies.get(policyKey(dataContextId, packageId));
|
|
47
|
+
if (!policy) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
allowedHosts: [...policy.allowedHosts],
|
|
52
|
+
credentials: policy.credentials.map((credential) => ({ ...credential })),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Drop every recorded network policy.
|
|
57
|
+
*
|
|
58
|
+
* @internal Test-only. Production install and uninstall update one package at a time.
|
|
59
|
+
*/
|
|
60
|
+
function _clearPackageNetworkPoliciesForTests() {
|
|
61
|
+
policies.clear();
|
|
62
|
+
}
|
package/dist/system-ids.d.ts
CHANGED
|
@@ -152,3 +152,34 @@ export declare const localFoldersToolIds: {
|
|
|
152
152
|
readonly trash: "00mukk9dwejbuehqzszpyxefx";
|
|
153
153
|
readonly purgeTrash: "00mukk9dwe6co8gvuy44kmuzd";
|
|
154
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* Contract id for the local-only System HTTP surface.
|
|
157
|
+
* Host-mediated fetch for isolated packages. Not available over device-to-device connections.
|
|
158
|
+
*/
|
|
159
|
+
export declare const httpContractId = "00muxgugn4tzd527r3cwnie2o";
|
|
160
|
+
/** Stable IDs for tools in System HTTP v1. */
|
|
161
|
+
export declare const httpToolIds: {
|
|
162
|
+
readonly request: "00muxgugn6e3dan5ej6dotzy5";
|
|
163
|
+
readonly cancel: "00muxgugn6scnni9563focivs";
|
|
164
|
+
readonly describePolicy: "00muxgugn6kouo2ocpun70q31";
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Contract id for the local-only System Contract Catalog.
|
|
168
|
+
* Lists every registered provider of a contract version so a hub package can fan out.
|
|
169
|
+
*/
|
|
170
|
+
export declare const contractCatalogContractId = "00muxgugn6ncjuunb8r28puae";
|
|
171
|
+
/** Stable IDs for tools in System Contract Catalog v1. */
|
|
172
|
+
export declare const contractCatalogToolIds: {
|
|
173
|
+
readonly listContractProviders: "00muxgugn6ek5apk8d5jtfavp";
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Contract id for the local-only System Scheduler.
|
|
177
|
+
* Device-local timers that wake an isolated package's own tool. Not synced and not remote.
|
|
178
|
+
*/
|
|
179
|
+
export declare const schedulerContractId = "00muxgugn6pj2o0lcu7kxkvrs";
|
|
180
|
+
/** Stable IDs for tools in System Scheduler v1. */
|
|
181
|
+
export declare const schedulerToolIds: {
|
|
182
|
+
readonly schedule: "00muxgugn6t0o5s7239zg6bf5";
|
|
183
|
+
readonly cancel: "00muxgugn6vqfxpppodqlgfhg";
|
|
184
|
+
readonly list: "00muxgugn661g0qmpuwafrmsi4";
|
|
185
|
+
};
|
package/dist/system-ids.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
3
|
+
exports.schedulerToolIds = exports.schedulerContractId = exports.contractCatalogToolIds = exports.contractCatalogContractId = exports.httpToolIds = exports.httpContractId = exports.localFoldersToolIds = exports.localFoldersContractId = exports.identityToolIds = exports.identityContractId = exports.invitesToolIds = exports.invitesContractId = exports.toolAccessControlToolIds = exports.toolAccessControlContractId = exports.networkControlContractId = exports.networkDiagnosticsContractId = exports.deviceOperationsContractId = exports.logsContractId = exports.peersSystemPackageId = exports.peersCoreRevokedPublishPublicKeys = exports.peersCorePublishPublicKey = exports.peersCorePackageRepoUrl = exports.peersCorePackageId = exports.createGroupToolId = exports.queryDatabaseToolId = exports.runWorkflowToolId = exports.defaultSendMessageToolId = exports.defaultAssistantRunnerToolId = exports.adminAssistantId = exports.openCodeAssistantId = exports.defaultAssistantId = exports.peersRootUserId = void 0;
|
|
4
4
|
/** Stable user ID that owns built-in Peers system records. */
|
|
5
5
|
exports.peersRootUserId = "000peers0user000000000001";
|
|
6
6
|
/** Default assistant used when no user-selected assistant is available. */
|
|
@@ -159,3 +159,34 @@ exports.localFoldersToolIds = {
|
|
|
159
159
|
trash: "00mukk9dwejbuehqzszpyxefx",
|
|
160
160
|
purgeTrash: "00mukk9dwe6co8gvuy44kmuzd",
|
|
161
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* Contract id for the local-only System HTTP surface.
|
|
164
|
+
* Host-mediated fetch for isolated packages. Not available over device-to-device connections.
|
|
165
|
+
*/
|
|
166
|
+
exports.httpContractId = "00muxgugn4tzd527r3cwnie2o";
|
|
167
|
+
/** Stable IDs for tools in System HTTP v1. */
|
|
168
|
+
exports.httpToolIds = {
|
|
169
|
+
request: "00muxgugn6e3dan5ej6dotzy5",
|
|
170
|
+
cancel: "00muxgugn6scnni9563focivs",
|
|
171
|
+
describePolicy: "00muxgugn6kouo2ocpun70q31",
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Contract id for the local-only System Contract Catalog.
|
|
175
|
+
* Lists every registered provider of a contract version so a hub package can fan out.
|
|
176
|
+
*/
|
|
177
|
+
exports.contractCatalogContractId = "00muxgugn6ncjuunb8r28puae";
|
|
178
|
+
/** Stable IDs for tools in System Contract Catalog v1. */
|
|
179
|
+
exports.contractCatalogToolIds = {
|
|
180
|
+
listContractProviders: "00muxgugn6ek5apk8d5jtfavp",
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Contract id for the local-only System Scheduler.
|
|
184
|
+
* Device-local timers that wake an isolated package's own tool. Not synced and not remote.
|
|
185
|
+
*/
|
|
186
|
+
exports.schedulerContractId = "00muxgugn6pj2o0lcu7kxkvrs";
|
|
187
|
+
/** Stable IDs for tools in System Scheduler v1. */
|
|
188
|
+
exports.schedulerToolIds = {
|
|
189
|
+
schedule: "00muxgugn6t0o5s7239zg6bf5",
|
|
190
|
+
cancel: "00muxgugn6vqfxpppodqlgfhg",
|
|
191
|
+
list: "00muxgugn661g0qmpuwafrmsi4",
|
|
192
|
+
};
|