@nullplatform/ui-plugin-sdk 0.2.0 → 0.4.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/dist/bridge.d.ts +3 -0
- package/dist/bridge.js +21 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.js +231 -54
- package/dist/components.d.ts +151 -3
- package/dist/components.js +46 -25
- package/dist/contract/allowlist.d.ts +6 -0
- package/dist/contract/allowlist.js +14 -0
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/contract/when.d.ts +6 -0
- package/dist/contract/when.js +49 -25
- package/dist/contract-cjs/allowlist.js +15 -0
- package/dist/contract-cjs/index.js +2 -1
- package/dist/contract-cjs/when.js +50 -26
- package/dist/protocol.d.ts +11 -1
- package/dist/protocol.js +96 -7
- package/dist/worker.js +23 -7
- package/package.json +1 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type ApiRequest, type BridgeMethodName, type BridgeMethods, type HostMessage, type HttpRequest, type HttpResponse, type NavigationTarget, type PluginContext, type SnackbarOptions, type WorkerMessage } from './protocol.js';
|
|
5
5
|
export declare class BridgeClient {
|
|
6
|
+
private readonly timeoutMs;
|
|
6
7
|
private port;
|
|
7
8
|
private pending;
|
|
8
9
|
private seq;
|
|
10
|
+
constructor(timeoutMs?: number);
|
|
11
|
+
dispose(): void;
|
|
9
12
|
attach(port: MessagePort): void;
|
|
10
13
|
post(message: WorkerMessage, transfer?: Transferable[]): void;
|
|
11
14
|
call<M extends BridgeMethodName>(method: M, ...args: Parameters<BridgeMethods[M]>): ReturnType<BridgeMethods[M]>;
|
package/dist/bridge.js
CHANGED
|
@@ -3,10 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BridgeError, deserializeError, } from './protocol.js';
|
|
5
5
|
export class BridgeClient {
|
|
6
|
+
timeoutMs;
|
|
6
7
|
port = null;
|
|
7
8
|
pending = new Map();
|
|
8
9
|
seq = 0;
|
|
10
|
+
constructor(timeoutMs = 30000) {
|
|
11
|
+
this.timeoutMs = timeoutMs;
|
|
12
|
+
}
|
|
13
|
+
dispose() {
|
|
14
|
+
for (const pending of this.pending.values()) {
|
|
15
|
+
clearTimeout(pending.timer);
|
|
16
|
+
pending.reject(new BridgeError('Bridge closed', 'DISPOSED'));
|
|
17
|
+
}
|
|
18
|
+
this.pending.clear();
|
|
19
|
+
this.port = null;
|
|
20
|
+
}
|
|
9
21
|
attach(port) {
|
|
22
|
+
this.dispose();
|
|
10
23
|
this.port = port;
|
|
11
24
|
}
|
|
12
25
|
post(message, transfer) {
|
|
@@ -17,11 +30,17 @@ export class BridgeClient {
|
|
|
17
30
|
call(method, ...args) {
|
|
18
31
|
const id = `c${++this.seq}`;
|
|
19
32
|
const promise = new Promise((resolve, reject) => {
|
|
20
|
-
this.pending.
|
|
33
|
+
if (this.pending.size >= 32) {
|
|
34
|
+
reject(new BridgeError('Too many pending calls', 'RATE_LIMIT'));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const timer = setTimeout(() => { this.pending.delete(id); reject(new BridgeError('Bridge call timed out', 'TIMEOUT')); }, this.timeoutMs);
|
|
38
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
21
39
|
try {
|
|
22
40
|
this.post({ type: 'call', id, method, args });
|
|
23
41
|
}
|
|
24
42
|
catch (error) {
|
|
43
|
+
clearTimeout(timer);
|
|
25
44
|
this.pending.delete(id);
|
|
26
45
|
reject(error);
|
|
27
46
|
}
|
|
@@ -35,6 +54,7 @@ export class BridgeClient {
|
|
|
35
54
|
const pending = this.pending.get(message.id);
|
|
36
55
|
if (!pending)
|
|
37
56
|
return true;
|
|
57
|
+
clearTimeout(pending.timer);
|
|
38
58
|
this.pending.delete(message.id);
|
|
39
59
|
if (message.ok)
|
|
40
60
|
pending.resolve(message.value);
|
package/dist/catalog.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* This file is pure data so it can be imported by the host without pulling
|
|
9
9
|
* the DOM polyfill.
|
|
10
10
|
*/
|
|
11
|
-
export type PropertyType =
|
|
11
|
+
export type PropertyType = "string" | "number" | "boolean" | "object" | "array";
|
|
12
12
|
export interface CatalogElementSpec {
|
|
13
13
|
/** Custom element tag name. */
|
|
14
14
|
tag: string;
|
package/dist/catalog.js
CHANGED
|
@@ -9,105 +9,282 @@
|
|
|
9
9
|
* the DOM polyfill.
|
|
10
10
|
*/
|
|
11
11
|
export const CATALOG = [
|
|
12
|
-
{ tag: 'np-image', component: 'Image', properties: { src: 'string', alt: 'string', width: 'number', height: 'number' }, events: {} },
|
|
13
12
|
{
|
|
14
|
-
tag:
|
|
15
|
-
component:
|
|
16
|
-
properties: {
|
|
13
|
+
tag: "np-network-graph",
|
|
14
|
+
component: "NetworkGraph",
|
|
15
|
+
properties: { nodes: "array", edges: "array", selected: "string" },
|
|
16
|
+
events: { nodePress: "onNodePress" },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
tag: "np-text-field",
|
|
20
|
+
component: "TextField",
|
|
21
|
+
properties: {
|
|
22
|
+
label: "string",
|
|
23
|
+
value: "string",
|
|
24
|
+
multiline: "boolean",
|
|
25
|
+
disabled: "boolean",
|
|
26
|
+
placeholder: "string",
|
|
27
|
+
error: "string",
|
|
28
|
+
},
|
|
29
|
+
events: { valueChange: "onValueChange" },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
tag: "np-select",
|
|
33
|
+
component: "Select",
|
|
34
|
+
properties: {
|
|
35
|
+
label: "string",
|
|
36
|
+
value: "string",
|
|
37
|
+
values: "array",
|
|
38
|
+
options: "array",
|
|
39
|
+
multiple: "boolean",
|
|
40
|
+
disabled: "boolean",
|
|
41
|
+
},
|
|
42
|
+
events: { valueChange: "onValueChange" },
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
tag: "np-switch",
|
|
46
|
+
component: "Switch",
|
|
47
|
+
properties: { label: "string", checked: "boolean", disabled: "boolean" },
|
|
48
|
+
events: { valueChange: "onValueChange" },
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
tag: "np-image",
|
|
52
|
+
component: "Image",
|
|
53
|
+
properties: {
|
|
54
|
+
src: "string",
|
|
55
|
+
alt: "string",
|
|
56
|
+
width: "number",
|
|
57
|
+
height: "number",
|
|
58
|
+
},
|
|
17
59
|
events: {},
|
|
18
|
-
slots: ['action'],
|
|
19
60
|
},
|
|
20
61
|
{
|
|
21
|
-
tag:
|
|
22
|
-
component:
|
|
23
|
-
properties: {
|
|
62
|
+
tag: "np-card",
|
|
63
|
+
component: "Card",
|
|
64
|
+
properties: { title: "string", subtitle: "string", padding: "string" },
|
|
24
65
|
events: {},
|
|
66
|
+
slots: ["action"],
|
|
25
67
|
},
|
|
26
68
|
{
|
|
27
|
-
tag:
|
|
28
|
-
component:
|
|
29
|
-
properties: {
|
|
69
|
+
tag: "np-stack",
|
|
70
|
+
component: "Stack",
|
|
71
|
+
properties: {
|
|
72
|
+
direction: "string",
|
|
73
|
+
spacing: "number",
|
|
74
|
+
align: "string",
|
|
75
|
+
justify: "string",
|
|
76
|
+
wrap: "boolean",
|
|
77
|
+
},
|
|
30
78
|
events: {},
|
|
31
79
|
},
|
|
32
80
|
{
|
|
33
|
-
tag:
|
|
34
|
-
component:
|
|
35
|
-
properties: {
|
|
36
|
-
|
|
81
|
+
tag: "np-text",
|
|
82
|
+
component: "Text",
|
|
83
|
+
properties: {
|
|
84
|
+
variant: "string",
|
|
85
|
+
color: "string",
|
|
86
|
+
align: "string",
|
|
87
|
+
noWrap: "boolean",
|
|
88
|
+
},
|
|
89
|
+
events: {},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
tag: "np-button",
|
|
93
|
+
component: "Button",
|
|
94
|
+
properties: {
|
|
95
|
+
variant: "string",
|
|
96
|
+
color: "string",
|
|
97
|
+
size: "string",
|
|
98
|
+
disabled: "boolean",
|
|
99
|
+
loading: "boolean",
|
|
100
|
+
icon: "string",
|
|
101
|
+
},
|
|
102
|
+
events: { press: "onPress" },
|
|
37
103
|
},
|
|
38
104
|
{
|
|
39
|
-
tag:
|
|
40
|
-
component:
|
|
41
|
-
properties: {
|
|
105
|
+
tag: "np-chip",
|
|
106
|
+
component: "Chip",
|
|
107
|
+
properties: {
|
|
108
|
+
label: "string",
|
|
109
|
+
color: "string",
|
|
110
|
+
variant: "string",
|
|
111
|
+
size: "string",
|
|
112
|
+
},
|
|
42
113
|
events: {},
|
|
43
114
|
},
|
|
44
115
|
{
|
|
45
|
-
tag:
|
|
46
|
-
component:
|
|
47
|
-
properties: { to:
|
|
48
|
-
events: { press:
|
|
116
|
+
tag: "np-link",
|
|
117
|
+
component: "Link",
|
|
118
|
+
properties: { to: "string", params: "object", href: "string" },
|
|
119
|
+
events: { press: "onPress" },
|
|
49
120
|
},
|
|
50
121
|
{
|
|
51
|
-
tag:
|
|
52
|
-
component:
|
|
53
|
-
properties: {
|
|
54
|
-
|
|
122
|
+
tag: "np-table",
|
|
123
|
+
component: "Table",
|
|
124
|
+
properties: {
|
|
125
|
+
columns: "array",
|
|
126
|
+
rows: "array",
|
|
127
|
+
dense: "boolean",
|
|
128
|
+
emptyMessage: "string",
|
|
129
|
+
},
|
|
130
|
+
events: { rowPress: "onRowPress" },
|
|
55
131
|
},
|
|
56
132
|
{
|
|
57
|
-
tag:
|
|
58
|
-
component:
|
|
59
|
-
properties: { height:
|
|
133
|
+
tag: "np-skeleton",
|
|
134
|
+
component: "Skeleton",
|
|
135
|
+
properties: { height: "number", width: "string", variant: "string" },
|
|
60
136
|
events: {},
|
|
61
137
|
},
|
|
62
138
|
{
|
|
63
|
-
tag:
|
|
64
|
-
component:
|
|
65
|
-
properties: { title:
|
|
139
|
+
tag: "np-empty",
|
|
140
|
+
component: "Empty",
|
|
141
|
+
properties: { title: "string", description: "string" },
|
|
66
142
|
events: {},
|
|
67
143
|
},
|
|
68
144
|
{
|
|
69
|
-
tag:
|
|
70
|
-
component:
|
|
71
|
-
properties: { severity:
|
|
145
|
+
tag: "np-alert",
|
|
146
|
+
component: "Alert",
|
|
147
|
+
properties: { severity: "string", title: "string" },
|
|
72
148
|
events: {},
|
|
73
149
|
},
|
|
74
150
|
{
|
|
75
|
-
tag:
|
|
76
|
-
component:
|
|
77
|
-
properties: { icon:
|
|
151
|
+
tag: "np-icon",
|
|
152
|
+
component: "Icon",
|
|
153
|
+
properties: { icon: "string", size: "number", color: "string" },
|
|
78
154
|
events: {},
|
|
79
155
|
},
|
|
80
156
|
{
|
|
81
|
-
tag:
|
|
82
|
-
component:
|
|
157
|
+
tag: "np-divider",
|
|
158
|
+
component: "Divider",
|
|
83
159
|
properties: {},
|
|
84
160
|
events: {},
|
|
85
161
|
},
|
|
86
162
|
{
|
|
87
|
-
tag:
|
|
88
|
-
component:
|
|
89
|
-
properties: { content:
|
|
163
|
+
tag: "np-markdown",
|
|
164
|
+
component: "Markdown",
|
|
165
|
+
properties: { content: "string" },
|
|
90
166
|
events: {},
|
|
91
167
|
},
|
|
92
168
|
{
|
|
93
|
-
tag:
|
|
94
|
-
component:
|
|
95
|
-
properties: { content:
|
|
169
|
+
tag: "np-code",
|
|
170
|
+
component: "Code",
|
|
171
|
+
properties: { content: "string", language: "string", maxHeight: "number" },
|
|
96
172
|
events: {},
|
|
97
173
|
},
|
|
98
174
|
{
|
|
99
|
-
tag:
|
|
100
|
-
component:
|
|
101
|
-
properties: {
|
|
102
|
-
|
|
175
|
+
tag: "np-ego-graph",
|
|
176
|
+
component: "EgoGraph",
|
|
177
|
+
properties: {
|
|
178
|
+
focus: "string",
|
|
179
|
+
inbound: "array",
|
|
180
|
+
outbound: "array",
|
|
181
|
+
height: "number",
|
|
182
|
+
},
|
|
183
|
+
events: { nodePress: "onNodePress" },
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
tag: "np-box",
|
|
187
|
+
component: "Box",
|
|
188
|
+
properties: {
|
|
189
|
+
padding: "string",
|
|
190
|
+
height: "string",
|
|
191
|
+
width: "string",
|
|
192
|
+
grow: "boolean",
|
|
193
|
+
},
|
|
194
|
+
events: {},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
// Responsive grid: as many columns as fit `min` px wide, up to `columns`.
|
|
198
|
+
tag: "np-grid",
|
|
199
|
+
component: "Grid",
|
|
200
|
+
properties: { columns: "number", min: "number", gap: "number" },
|
|
201
|
+
events: {},
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
// Big number tile: label, formatted value, optional delta with a trend arrow and tone.
|
|
205
|
+
tag: "np-metric",
|
|
206
|
+
component: "Metric",
|
|
207
|
+
properties: {
|
|
208
|
+
label: "string",
|
|
209
|
+
value: "string",
|
|
210
|
+
delta: "string",
|
|
211
|
+
trend: "string",
|
|
212
|
+
tone: "string",
|
|
213
|
+
hint: "string",
|
|
214
|
+
spark: "array",
|
|
215
|
+
color: "string",
|
|
216
|
+
},
|
|
217
|
+
events: {},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
tag: "np-sparkline",
|
|
221
|
+
component: "Sparkline",
|
|
222
|
+
properties: {
|
|
223
|
+
values: "array",
|
|
224
|
+
height: "number",
|
|
225
|
+
color: "string",
|
|
226
|
+
area: "boolean",
|
|
227
|
+
},
|
|
228
|
+
events: {},
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
// Time series. `series: [{ name, values, color? }]`, `categories` are the x labels (same length as values).
|
|
232
|
+
tag: "np-line-chart",
|
|
233
|
+
component: "LineChart",
|
|
234
|
+
properties: {
|
|
235
|
+
series: "array",
|
|
236
|
+
categories: "array",
|
|
237
|
+
stacked: "boolean",
|
|
238
|
+
area: "boolean",
|
|
239
|
+
height: "number",
|
|
240
|
+
format: "string",
|
|
241
|
+
currency: "string",
|
|
242
|
+
hideLegend: "boolean",
|
|
243
|
+
},
|
|
244
|
+
events: { pointPress: "onPointPress" },
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
tag: "np-bar-chart",
|
|
248
|
+
component: "BarChart",
|
|
249
|
+
properties: {
|
|
250
|
+
series: "array",
|
|
251
|
+
categories: "array",
|
|
252
|
+
stacked: "boolean",
|
|
253
|
+
horizontal: "boolean",
|
|
254
|
+
height: "number",
|
|
255
|
+
format: "string",
|
|
256
|
+
currency: "string",
|
|
257
|
+
hideLegend: "boolean",
|
|
258
|
+
},
|
|
259
|
+
events: { barPress: "onBarPress" },
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
// Part-to-whole. `items: [{ name, value, color? }]`; the center shows `total` or the sum.
|
|
263
|
+
tag: "np-donut",
|
|
264
|
+
component: "Donut",
|
|
265
|
+
properties: {
|
|
266
|
+
items: "array",
|
|
267
|
+
total: "string",
|
|
268
|
+
height: "number",
|
|
269
|
+
format: "string",
|
|
270
|
+
currency: "string",
|
|
271
|
+
hideLegend: "boolean",
|
|
272
|
+
},
|
|
273
|
+
events: { slicePress: "onSlicePress" },
|
|
103
274
|
},
|
|
104
275
|
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
276
|
+
// Horizontal share bar, 0..1.
|
|
277
|
+
tag: "np-progress-bar",
|
|
278
|
+
component: "ProgressBar",
|
|
279
|
+
properties: {
|
|
280
|
+
value: "number",
|
|
281
|
+
label: "string",
|
|
282
|
+
color: "string",
|
|
283
|
+
height: "number",
|
|
284
|
+
},
|
|
108
285
|
events: {},
|
|
109
286
|
},
|
|
110
287
|
];
|
|
111
288
|
export const CATALOG_BY_TAG = new Map(CATALOG.map((spec) => [spec.tag, spec]));
|
|
112
289
|
/** Name of the wrapper element remote-dom uses for React elements passed as props. */
|
|
113
|
-
export const FRAGMENT_TAG =
|
|
290
|
+
export const FRAGMENT_TAG = "remote-fragment";
|
package/dist/components.d.ts
CHANGED
|
@@ -3,12 +3,57 @@ import "./polyfill.js";
|
|
|
3
3
|
* React components a plugin renders with. Each one maps to a catalog element;
|
|
4
4
|
* the host decides how it looks.
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import { type ComponentType, type ReactNode } from
|
|
6
|
+
import "@remote-dom/react/polyfill";
|
|
7
|
+
import { type ComponentType, type ReactNode } from "react";
|
|
8
|
+
export declare const TextField: ComponentType<{
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
multiline?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
onValueChange?: (value: string) => void;
|
|
16
|
+
} & {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const Select: ComponentType<{
|
|
20
|
+
label: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
values?: string[];
|
|
23
|
+
options: Array<{
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}>;
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
onValueChange?: (value: string | string[]) => void;
|
|
30
|
+
} & {
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const Switch: ComponentType<{
|
|
34
|
+
label: string;
|
|
35
|
+
checked: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
onValueChange?: (value: boolean) => void;
|
|
38
|
+
} & {
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
}>;
|
|
41
|
+
export declare const NetworkGraph: ComponentType<{
|
|
42
|
+
nodes: Array<Record<string, unknown>>;
|
|
43
|
+
edges: Array<{
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
config_status?: string;
|
|
47
|
+
}>;
|
|
48
|
+
selected?: string;
|
|
49
|
+
onNodePress?: (id: string) => void;
|
|
50
|
+
} & {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
}>;
|
|
8
53
|
export interface TableColumn {
|
|
9
54
|
key: string;
|
|
10
55
|
header: string;
|
|
11
|
-
align?:
|
|
56
|
+
align?: "left" | "right" | "center";
|
|
12
57
|
width?: number | string;
|
|
13
58
|
}
|
|
14
59
|
export type TableRow = Record<string, string | number | boolean | null | undefined> & {
|
|
@@ -147,3 +192,106 @@ export declare const Box: ComponentType<{
|
|
|
147
192
|
} & {
|
|
148
193
|
children?: ReactNode;
|
|
149
194
|
}>;
|
|
195
|
+
/** Responsive grid: as many columns as fit `min` px, up to `columns`. */
|
|
196
|
+
export declare const Grid: ComponentType<{
|
|
197
|
+
columns?: number;
|
|
198
|
+
min?: number;
|
|
199
|
+
gap?: number;
|
|
200
|
+
} & {
|
|
201
|
+
children?: ReactNode;
|
|
202
|
+
}>;
|
|
203
|
+
export type ValueFormat = "number" | "currency" | "percent" | "compact";
|
|
204
|
+
/** Big number tile. `trend` draws the arrow; `tone` colors the delta (`positive` = good, whatever the direction). */
|
|
205
|
+
export declare const Metric: ComponentType<{
|
|
206
|
+
label: string;
|
|
207
|
+
value: string;
|
|
208
|
+
delta?: string;
|
|
209
|
+
trend?: "up" | "down" | "flat";
|
|
210
|
+
tone?: "positive" | "negative" | "neutral";
|
|
211
|
+
hint?: string;
|
|
212
|
+
/** Recent values drawn as a small sparkline next to the number. */
|
|
213
|
+
spark?: number[];
|
|
214
|
+
/** Theme color name (`primary`, `info`, `success`, `warning`, `error`, `secondary`) or `palette:<n>`. */
|
|
215
|
+
color?: string;
|
|
216
|
+
} & {
|
|
217
|
+
children?: ReactNode;
|
|
218
|
+
}>;
|
|
219
|
+
/**
|
|
220
|
+
* Colors a plugin can name without knowing the host theme: theme roles or palette slots.
|
|
221
|
+
* Use the same one for the same concept across charts so a category keeps its hue everywhere.
|
|
222
|
+
*/
|
|
223
|
+
export type ThemeColor = "primary" | "info" | "success" | "warning" | "error" | "secondary" | "grey" | "muted" | `palette:${number}`;
|
|
224
|
+
/** `area` fills under the line; off by default. */
|
|
225
|
+
export declare const Sparkline: ComponentType<{
|
|
226
|
+
values: number[];
|
|
227
|
+
height?: number;
|
|
228
|
+
color?: string;
|
|
229
|
+
area?: boolean;
|
|
230
|
+
} & {
|
|
231
|
+
children?: ReactNode;
|
|
232
|
+
}>;
|
|
233
|
+
export interface ChartSeries {
|
|
234
|
+
name: string;
|
|
235
|
+
values: Array<number | null>;
|
|
236
|
+
color?: ThemeColor | string;
|
|
237
|
+
}
|
|
238
|
+
export interface ChartPoint {
|
|
239
|
+
series: string;
|
|
240
|
+
category: string;
|
|
241
|
+
value: number;
|
|
242
|
+
index: number;
|
|
243
|
+
}
|
|
244
|
+
/** Time series; `categories` are the x labels, one per value. */
|
|
245
|
+
export declare const LineChart: ComponentType<{
|
|
246
|
+
series: ChartSeries[];
|
|
247
|
+
categories: string[];
|
|
248
|
+
stacked?: boolean;
|
|
249
|
+
area?: boolean;
|
|
250
|
+
height?: number;
|
|
251
|
+
format?: ValueFormat;
|
|
252
|
+
currency?: string;
|
|
253
|
+
/** Legends show by default; remote-dom booleans default to false, hence the negative flag. */
|
|
254
|
+
hideLegend?: boolean;
|
|
255
|
+
onPointPress?: (point: ChartPoint) => void;
|
|
256
|
+
} & {
|
|
257
|
+
children?: ReactNode;
|
|
258
|
+
}>;
|
|
259
|
+
export declare const BarChart: ComponentType<{
|
|
260
|
+
series: ChartSeries[];
|
|
261
|
+
categories: string[];
|
|
262
|
+
stacked?: boolean;
|
|
263
|
+
horizontal?: boolean;
|
|
264
|
+
height?: number;
|
|
265
|
+
format?: ValueFormat;
|
|
266
|
+
currency?: string;
|
|
267
|
+
hideLegend?: boolean;
|
|
268
|
+
onBarPress?: (point: ChartPoint) => void;
|
|
269
|
+
} & {
|
|
270
|
+
children?: ReactNode;
|
|
271
|
+
}>;
|
|
272
|
+
export interface DonutItem {
|
|
273
|
+
name: string;
|
|
274
|
+
value: number;
|
|
275
|
+
color?: ThemeColor | string;
|
|
276
|
+
}
|
|
277
|
+
/** Part-to-whole ring; the center shows `total` or the formatted sum. */
|
|
278
|
+
export declare const Donut: ComponentType<{
|
|
279
|
+
items: DonutItem[];
|
|
280
|
+
total?: string;
|
|
281
|
+
height?: number;
|
|
282
|
+
format?: ValueFormat;
|
|
283
|
+
currency?: string;
|
|
284
|
+
hideLegend?: boolean;
|
|
285
|
+
onSlicePress?: (item: DonutItem) => void;
|
|
286
|
+
} & {
|
|
287
|
+
children?: ReactNode;
|
|
288
|
+
}>;
|
|
289
|
+
/** Horizontal share bar, `value` in 0..1. */
|
|
290
|
+
export declare const ProgressBar: ComponentType<{
|
|
291
|
+
value: number;
|
|
292
|
+
label?: string;
|
|
293
|
+
color?: string;
|
|
294
|
+
height?: number;
|
|
295
|
+
} & {
|
|
296
|
+
children?: ReactNode;
|
|
297
|
+
}>;
|
package/dist/components.js
CHANGED
|
@@ -3,11 +3,11 @@ import "./polyfill.js";
|
|
|
3
3
|
* React components a plugin renders with. Each one maps to a catalog element;
|
|
4
4
|
* the host decides how it looks.
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import { createRemoteComponent } from
|
|
8
|
-
import { createElement } from
|
|
9
|
-
import { CATALOG_BY_TAG } from
|
|
10
|
-
import { defineCatalogElements } from
|
|
6
|
+
import "@remote-dom/react/polyfill";
|
|
7
|
+
import { createRemoteComponent } from "@remote-dom/react";
|
|
8
|
+
import { createElement } from "react";
|
|
9
|
+
import { CATALOG_BY_TAG } from "./catalog.js";
|
|
10
|
+
import { defineCatalogElements } from "./elements.js";
|
|
11
11
|
const elements = defineCatalogElements();
|
|
12
12
|
function component(tag) {
|
|
13
13
|
const spec = CATALOG_BY_TAG.get(tag);
|
|
@@ -16,7 +16,9 @@ function component(tag) {
|
|
|
16
16
|
const eventProps = {};
|
|
17
17
|
for (const [event, prop] of Object.entries(spec.events))
|
|
18
18
|
eventProps[prop] = { event };
|
|
19
|
-
const Remote = createRemoteComponent(tag, elements.get(tag), {
|
|
19
|
+
const Remote = createRemoteComponent(tag, elements.get(tag), {
|
|
20
|
+
eventProps: eventProps,
|
|
21
|
+
});
|
|
20
22
|
const handlerProps = Object.values(spec.events);
|
|
21
23
|
if (handlerProps.length === 0)
|
|
22
24
|
return Remote;
|
|
@@ -25,9 +27,11 @@ function component(tag) {
|
|
|
25
27
|
const mapped = { ...props };
|
|
26
28
|
for (const prop of handlerProps) {
|
|
27
29
|
const handler = props[prop];
|
|
28
|
-
if (typeof handler ===
|
|
30
|
+
if (typeof handler === "function") {
|
|
29
31
|
mapped[prop] = (event) => {
|
|
30
|
-
const detail = event && typeof event ===
|
|
32
|
+
const detail = event && typeof event === "object" && "detail" in event
|
|
33
|
+
? event.detail
|
|
34
|
+
: event;
|
|
31
35
|
return handler(detail);
|
|
32
36
|
};
|
|
33
37
|
}
|
|
@@ -37,21 +41,38 @@ function component(tag) {
|
|
|
37
41
|
Wrapped.displayName = spec.component;
|
|
38
42
|
return Wrapped;
|
|
39
43
|
}
|
|
40
|
-
export const
|
|
41
|
-
export const
|
|
42
|
-
export const
|
|
43
|
-
export const
|
|
44
|
-
export const
|
|
45
|
-
export const
|
|
46
|
-
export const
|
|
47
|
-
export const
|
|
48
|
-
export const
|
|
49
|
-
export const
|
|
50
|
-
export const
|
|
51
|
-
export const
|
|
52
|
-
export const
|
|
53
|
-
export const
|
|
54
|
-
export const
|
|
44
|
+
export const TextField = component("np-text-field");
|
|
45
|
+
export const Select = component("np-select");
|
|
46
|
+
export const Switch = component("np-switch");
|
|
47
|
+
export const NetworkGraph = component("np-network-graph");
|
|
48
|
+
export const Image = component("np-image");
|
|
49
|
+
export const Card = component("np-card");
|
|
50
|
+
export const Stack = component("np-stack");
|
|
51
|
+
export const Text = component("np-text");
|
|
52
|
+
export const Button = component("np-button");
|
|
53
|
+
export const Chip = component("np-chip");
|
|
54
|
+
export const Link = component("np-link");
|
|
55
|
+
export const Table = component("np-table");
|
|
56
|
+
export const Skeleton = component("np-skeleton");
|
|
57
|
+
export const Empty = component("np-empty");
|
|
58
|
+
export const Alert = component("np-alert");
|
|
59
|
+
export const Icon = component("np-icon");
|
|
60
|
+
export const Divider = component("np-divider");
|
|
61
|
+
export const Markdown = component("np-markdown");
|
|
62
|
+
export const Code = component("np-code");
|
|
55
63
|
/** Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right. */
|
|
56
|
-
export const EgoGraph = component(
|
|
57
|
-
export const Box = component(
|
|
64
|
+
export const EgoGraph = component("np-ego-graph");
|
|
65
|
+
export const Box = component("np-box");
|
|
66
|
+
/** Responsive grid: as many columns as fit `min` px, up to `columns`. */
|
|
67
|
+
export const Grid = component("np-grid");
|
|
68
|
+
/** Big number tile. `trend` draws the arrow; `tone` colors the delta (`positive` = good, whatever the direction). */
|
|
69
|
+
export const Metric = component("np-metric");
|
|
70
|
+
/** `area` fills under the line; off by default. */
|
|
71
|
+
export const Sparkline = component("np-sparkline");
|
|
72
|
+
/** Time series; `categories` are the x labels, one per value. */
|
|
73
|
+
export const LineChart = component("np-line-chart");
|
|
74
|
+
export const BarChart = component("np-bar-chart");
|
|
75
|
+
/** Part-to-whole ring; the center shows `total` or the formatted sum. */
|
|
76
|
+
export const Donut = component("np-donut");
|
|
77
|
+
/** Horizontal share bar, `value` in 0..1. */
|
|
78
|
+
export const ProgressBar = component("np-progress-bar");
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ApiPermission, HttpPermission } from './manifest.js';
|
|
2
2
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
3
3
|
export declare function normalizePath(path: string): string[] | null;
|
|
4
|
+
/**
|
|
5
|
+
* The one canonical spelling of a plugin path: decoded once, validated, re-encoded per segment.
|
|
6
|
+
* The allowlist decision and the request the host actually sends must both use this string, so
|
|
7
|
+
* that nothing downstream can resolve a path other than the authorized one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function canonicalizePath(path: string): string | null;
|
|
4
10
|
/**
|
|
5
11
|
* Decides whether a plugin API request (a nullplatform public API path) is covered
|
|
6
12
|
* by its declared `permissions.api`. Query strings are never part of the decision.
|
|
@@ -14,8 +14,22 @@ export function normalizePath(path) {
|
|
|
14
14
|
const segments = decoded.split('/').slice(1);
|
|
15
15
|
if (segments.some((segment) => segment === '' || segment === '.' || segment === '..'))
|
|
16
16
|
return null;
|
|
17
|
+
// A legitimately encoded path has no `%` left after one decode. One that still does is
|
|
18
|
+
// double-encoded, and would resolve to a different path in any component that decodes again
|
|
19
|
+
// than the one this allowlist just authorized.
|
|
20
|
+
if (segments.some((segment) => segment.includes('%')))
|
|
21
|
+
return null;
|
|
17
22
|
return segments;
|
|
18
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* The one canonical spelling of a plugin path: decoded once, validated, re-encoded per segment.
|
|
26
|
+
* The allowlist decision and the request the host actually sends must both use this string, so
|
|
27
|
+
* that nothing downstream can resolve a path other than the authorized one.
|
|
28
|
+
*/
|
|
29
|
+
export function canonicalizePath(path) {
|
|
30
|
+
const segments = normalizePath(path);
|
|
31
|
+
return segments ? '/' + segments.map(encodeURIComponent).join('/') : null;
|
|
32
|
+
}
|
|
19
33
|
/** `{param}` placeholders match exactly one non-empty segment. */
|
|
20
34
|
function pathMatches(pattern, requestSegments) {
|
|
21
35
|
const patternSegments = normalizePath(pattern);
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
|
|
2
|
-
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath } from './allowlist.js';
|
|
2
|
+
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
3
3
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, type WhenQuery, type ContextRoot, type Rollout, } from './when.js';
|
|
4
4
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
package/dist/contract/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, } from './manifest.js';
|
|
2
|
-
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath } from './allowlist.js';
|
|
2
|
+
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
3
3
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, } from './when.js';
|
|
4
4
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
package/dist/contract/when.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ export type WhenQuery = Record<string, unknown>;
|
|
|
2
2
|
/** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
|
|
3
3
|
export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "deployment", "user"];
|
|
4
4
|
export type ContextRoot = (typeof CONTEXT_ROOTS)[number];
|
|
5
|
+
export declare const WHEN_LIMITS: {
|
|
6
|
+
readonly depth: 16;
|
|
7
|
+
readonly nodes: 512;
|
|
8
|
+
readonly array: 100;
|
|
9
|
+
readonly string: 1024;
|
|
10
|
+
};
|
|
5
11
|
export declare class WhenError extends Error {
|
|
6
12
|
constructor(message: string);
|
|
7
13
|
}
|
package/dist/contract/when.js
CHANGED
|
@@ -7,7 +7,8 @@ import sift from 'sift';
|
|
|
7
7
|
/** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
|
|
8
8
|
export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'deployment', 'user'];
|
|
9
9
|
/** Operators that would execute code or are meaningless outside MongoDB. */
|
|
10
|
-
const
|
|
10
|
+
const ALLOWED_OPERATORS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$exists', '$size', '$all', '$elemMatch', '$not', '$and', '$or', '$nor', '$mod']);
|
|
11
|
+
export const WHEN_LIMITS = { depth: 16, nodes: 512, array: 100, string: 1024 };
|
|
11
12
|
/** Logical operators whose operands are themselves queries against the same document. */
|
|
12
13
|
const LOGICAL_LIST_OPERATORS = new Set(['$and', '$or', '$nor']);
|
|
13
14
|
export class WhenError extends Error {
|
|
@@ -21,44 +22,67 @@ const rootOf = (field) => field.split('.')[0];
|
|
|
21
22
|
/** Top-level roots referenced by a query (walks `$and` / `$or` / `$nor`; field operands are never roots). */
|
|
22
23
|
export function extractRoots(when) {
|
|
23
24
|
const roots = new Set();
|
|
24
|
-
const
|
|
25
|
+
const pending = [when];
|
|
26
|
+
let visited = 0;
|
|
27
|
+
while (pending.length && visited++ < WHEN_LIMITS.nodes) {
|
|
28
|
+
const query = pending.pop();
|
|
25
29
|
if (!isPlainObject(query))
|
|
26
|
-
|
|
30
|
+
continue;
|
|
27
31
|
for (const [key, value] of Object.entries(query)) {
|
|
28
32
|
if (key.startsWith('$')) {
|
|
29
33
|
if (LOGICAL_LIST_OPERATORS.has(key) && Array.isArray(value))
|
|
30
|
-
value.
|
|
34
|
+
pending.push(...value.slice(0, WHEN_LIMITS.array));
|
|
31
35
|
else if (key === '$not')
|
|
32
|
-
|
|
33
|
-
continue;
|
|
36
|
+
pending.push(value);
|
|
34
37
|
}
|
|
35
|
-
|
|
38
|
+
else
|
|
39
|
+
roots.add(rootOf(key));
|
|
36
40
|
}
|
|
37
|
-
}
|
|
38
|
-
walk(when);
|
|
41
|
+
}
|
|
39
42
|
return [...roots];
|
|
40
43
|
}
|
|
41
44
|
/** Deep check for forbidden operators and non-JSON values (functions, symbols). */
|
|
42
|
-
function assertSafe(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
function assertSafe(input) {
|
|
46
|
+
let nodes = 0;
|
|
47
|
+
const seen = new WeakSet();
|
|
48
|
+
const walk = (value, depth) => {
|
|
49
|
+
if (++nodes > WHEN_LIMITS.nodes || depth > WHEN_LIMITS.depth)
|
|
50
|
+
throw new WhenError('when exceeds complexity limits');
|
|
51
|
+
if (typeof value === 'string') {
|
|
52
|
+
if (value.length > WHEN_LIMITS.string)
|
|
53
|
+
throw new WhenError('when string exceeds limit');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (value === null || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
|
|
57
|
+
return;
|
|
58
|
+
if (typeof value !== 'object' || (!Array.isArray(value) && !isPlainObject(value)))
|
|
59
|
+
throw new WhenError('when must be plain JSON');
|
|
60
|
+
if (seen.has(value))
|
|
61
|
+
throw new WhenError('when must not contain cycles');
|
|
62
|
+
seen.add(value);
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
if (value.length > WHEN_LIMITS.array)
|
|
65
|
+
throw new WhenError('when array exceeds limit');
|
|
66
|
+
value.forEach(item => walk(item, depth + 1));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
for (const [key, item] of Object.entries(value)) {
|
|
70
|
+
if (key.length > WHEN_LIMITS.string || key.split('.').some(part => ['__proto__', 'prototype', 'constructor'].includes(part)))
|
|
71
|
+
throw new WhenError('Invalid when field');
|
|
72
|
+
if (key.startsWith('$') && !ALLOWED_OPERATORS.has(key))
|
|
73
|
+
throw new WhenError(`Operator ${key} is not allowed`);
|
|
74
|
+
walk(item, depth + 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
seen.delete(value);
|
|
78
|
+
};
|
|
79
|
+
walk(input, 0);
|
|
56
80
|
}
|
|
57
81
|
/** Validates an untrusted condition: plain object, JSON only, no code operators, known roots. Returns it unchanged. */
|
|
58
82
|
export function validateWhen(input) {
|
|
59
83
|
if (!isPlainObject(input))
|
|
60
84
|
throw new WhenError('when must be an object');
|
|
61
|
-
assertSafe(input
|
|
85
|
+
assertSafe(input);
|
|
62
86
|
for (const root of extractRoots(input)) {
|
|
63
87
|
if (!CONTEXT_ROOTS.includes(root)) {
|
|
64
88
|
throw new WhenError(`Unknown context root "${root}" (allowed: ${CONTEXT_ROOTS.join(', ')})`);
|
|
@@ -71,7 +95,7 @@ export function evaluateWhen(when, context) {
|
|
|
71
95
|
if (!when || Object.keys(when).length === 0)
|
|
72
96
|
return true;
|
|
73
97
|
try {
|
|
74
|
-
return sift(when)(context ?? {});
|
|
98
|
+
return sift(validateWhen(when))(context ?? {});
|
|
75
99
|
}
|
|
76
100
|
catch {
|
|
77
101
|
return false;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRequestAllowed = void 0;
|
|
4
4
|
exports.normalizePath = normalizePath;
|
|
5
|
+
exports.canonicalizePath = canonicalizePath;
|
|
5
6
|
exports.isApiRequestAllowed = isApiRequestAllowed;
|
|
6
7
|
exports.isHttpRequestAllowed = isHttpRequestAllowed;
|
|
7
8
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
@@ -20,8 +21,22 @@ function normalizePath(path) {
|
|
|
20
21
|
const segments = decoded.split('/').slice(1);
|
|
21
22
|
if (segments.some((segment) => segment === '' || segment === '.' || segment === '..'))
|
|
22
23
|
return null;
|
|
24
|
+
// A legitimately encoded path has no `%` left after one decode. One that still does is
|
|
25
|
+
// double-encoded, and would resolve to a different path in any component that decodes again
|
|
26
|
+
// than the one this allowlist just authorized.
|
|
27
|
+
if (segments.some((segment) => segment.includes('%')))
|
|
28
|
+
return null;
|
|
23
29
|
return segments;
|
|
24
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The one canonical spelling of a plugin path: decoded once, validated, re-encoded per segment.
|
|
33
|
+
* The allowlist decision and the request the host actually sends must both use this string, so
|
|
34
|
+
* that nothing downstream can resolve a path other than the authorized one.
|
|
35
|
+
*/
|
|
36
|
+
function canonicalizePath(path) {
|
|
37
|
+
const segments = normalizePath(path);
|
|
38
|
+
return segments ? '/' + segments.map(encodeURIComponent).join('/') : null;
|
|
39
|
+
}
|
|
25
40
|
/** `{param}` placeholders match exactly one non-empty segment. */
|
|
26
41
|
function pathMatches(pattern, requestSegments) {
|
|
27
42
|
const patternSegments = normalizePath(pattern);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveAssetUrl = exports.validateStorageUrl = exports.PLUGIN_STORAGE_ORIGIN = exports.WhenError = exports.rolloutIncludes = exports.evaluateWhen = exports.validateWhen = exports.extractRoots = exports.CONTEXT_ROOTS = exports.normalizePath = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.ManifestError = exports.isSectionSlot = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
|
|
3
|
+
exports.resolveAssetUrl = exports.validateStorageUrl = exports.PLUGIN_STORAGE_ORIGIN = exports.WhenError = exports.rolloutIncludes = exports.evaluateWhen = exports.validateWhen = exports.extractRoots = exports.CONTEXT_ROOTS = exports.canonicalizePath = exports.normalizePath = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.ManifestError = exports.isSectionSlot = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
|
|
4
4
|
var manifest_1 = require("./manifest");
|
|
5
5
|
Object.defineProperty(exports, "PROTOCOL_VERSION", { enumerable: true, get: function () { return manifest_1.PROTOCOL_VERSION; } });
|
|
6
6
|
Object.defineProperty(exports, "validateManifest", { enumerable: true, get: function () { return manifest_1.validateManifest; } });
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "isApiRequestAllowed", { enumerable: true, get: f
|
|
|
11
11
|
Object.defineProperty(exports, "isHttpRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isHttpRequestAllowed; } });
|
|
12
12
|
Object.defineProperty(exports, "isRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isRequestAllowed; } });
|
|
13
13
|
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return allowlist_1.normalizePath; } });
|
|
14
|
+
Object.defineProperty(exports, "canonicalizePath", { enumerable: true, get: function () { return allowlist_1.canonicalizePath; } });
|
|
14
15
|
var when_1 = require("./when");
|
|
15
16
|
Object.defineProperty(exports, "CONTEXT_ROOTS", { enumerable: true, get: function () { return when_1.CONTEXT_ROOTS; } });
|
|
16
17
|
Object.defineProperty(exports, "extractRoots", { enumerable: true, get: function () { return when_1.extractRoots; } });
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WhenError = exports.CONTEXT_ROOTS = void 0;
|
|
6
|
+
exports.WhenError = exports.WHEN_LIMITS = exports.CONTEXT_ROOTS = void 0;
|
|
7
7
|
exports.extractRoots = extractRoots;
|
|
8
8
|
exports.validateWhen = validateWhen;
|
|
9
9
|
exports.evaluateWhen = evaluateWhen;
|
|
@@ -17,7 +17,8 @@ const sift_1 = __importDefault(require("sift"));
|
|
|
17
17
|
/** Roots a condition may reference. The API knows how to load each one; anything else is rejected at write time. */
|
|
18
18
|
exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'deployment', 'user'];
|
|
19
19
|
/** Operators that would execute code or are meaningless outside MongoDB. */
|
|
20
|
-
const
|
|
20
|
+
const ALLOWED_OPERATORS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin', '$exists', '$size', '$all', '$elemMatch', '$not', '$and', '$or', '$nor', '$mod']);
|
|
21
|
+
exports.WHEN_LIMITS = { depth: 16, nodes: 512, array: 100, string: 1024 };
|
|
21
22
|
/** Logical operators whose operands are themselves queries against the same document. */
|
|
22
23
|
const LOGICAL_LIST_OPERATORS = new Set(['$and', '$or', '$nor']);
|
|
23
24
|
class WhenError extends Error {
|
|
@@ -32,44 +33,67 @@ const rootOf = (field) => field.split('.')[0];
|
|
|
32
33
|
/** Top-level roots referenced by a query (walks `$and` / `$or` / `$nor`; field operands are never roots). */
|
|
33
34
|
function extractRoots(when) {
|
|
34
35
|
const roots = new Set();
|
|
35
|
-
const
|
|
36
|
+
const pending = [when];
|
|
37
|
+
let visited = 0;
|
|
38
|
+
while (pending.length && visited++ < exports.WHEN_LIMITS.nodes) {
|
|
39
|
+
const query = pending.pop();
|
|
36
40
|
if (!isPlainObject(query))
|
|
37
|
-
|
|
41
|
+
continue;
|
|
38
42
|
for (const [key, value] of Object.entries(query)) {
|
|
39
43
|
if (key.startsWith('$')) {
|
|
40
44
|
if (LOGICAL_LIST_OPERATORS.has(key) && Array.isArray(value))
|
|
41
|
-
value.
|
|
45
|
+
pending.push(...value.slice(0, exports.WHEN_LIMITS.array));
|
|
42
46
|
else if (key === '$not')
|
|
43
|
-
|
|
44
|
-
continue;
|
|
47
|
+
pending.push(value);
|
|
45
48
|
}
|
|
46
|
-
|
|
49
|
+
else
|
|
50
|
+
roots.add(rootOf(key));
|
|
47
51
|
}
|
|
48
|
-
}
|
|
49
|
-
walk(when);
|
|
52
|
+
}
|
|
50
53
|
return [...roots];
|
|
51
54
|
}
|
|
52
55
|
/** Deep check for forbidden operators and non-JSON values (functions, symbols). */
|
|
53
|
-
function assertSafe(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
function assertSafe(input) {
|
|
57
|
+
let nodes = 0;
|
|
58
|
+
const seen = new WeakSet();
|
|
59
|
+
const walk = (value, depth) => {
|
|
60
|
+
if (++nodes > exports.WHEN_LIMITS.nodes || depth > exports.WHEN_LIMITS.depth)
|
|
61
|
+
throw new WhenError('when exceeds complexity limits');
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
if (value.length > exports.WHEN_LIMITS.string)
|
|
64
|
+
throw new WhenError('when string exceeds limit');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (value === null || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
|
|
68
|
+
return;
|
|
69
|
+
if (typeof value !== 'object' || (!Array.isArray(value) && !isPlainObject(value)))
|
|
70
|
+
throw new WhenError('when must be plain JSON');
|
|
71
|
+
if (seen.has(value))
|
|
72
|
+
throw new WhenError('when must not contain cycles');
|
|
73
|
+
seen.add(value);
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
if (value.length > exports.WHEN_LIMITS.array)
|
|
76
|
+
throw new WhenError('when array exceeds limit');
|
|
77
|
+
value.forEach(item => walk(item, depth + 1));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
for (const [key, item] of Object.entries(value)) {
|
|
81
|
+
if (key.length > exports.WHEN_LIMITS.string || key.split('.').some(part => ['__proto__', 'prototype', 'constructor'].includes(part)))
|
|
82
|
+
throw new WhenError('Invalid when field');
|
|
83
|
+
if (key.startsWith('$') && !ALLOWED_OPERATORS.has(key))
|
|
84
|
+
throw new WhenError(`Operator ${key} is not allowed`);
|
|
85
|
+
walk(item, depth + 1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
seen.delete(value);
|
|
89
|
+
};
|
|
90
|
+
walk(input, 0);
|
|
67
91
|
}
|
|
68
92
|
/** Validates an untrusted condition: plain object, JSON only, no code operators, known roots. Returns it unchanged. */
|
|
69
93
|
function validateWhen(input) {
|
|
70
94
|
if (!isPlainObject(input))
|
|
71
95
|
throw new WhenError('when must be an object');
|
|
72
|
-
assertSafe(input
|
|
96
|
+
assertSafe(input);
|
|
73
97
|
for (const root of extractRoots(input)) {
|
|
74
98
|
if (!exports.CONTEXT_ROOTS.includes(root)) {
|
|
75
99
|
throw new WhenError(`Unknown context root "${root}" (allowed: ${exports.CONTEXT_ROOTS.join(', ')})`);
|
|
@@ -82,7 +106,7 @@ function evaluateWhen(when, context) {
|
|
|
82
106
|
if (!when || Object.keys(when).length === 0)
|
|
83
107
|
return true;
|
|
84
108
|
try {
|
|
85
|
-
return (0, sift_1.default)(when)(context ?? {});
|
|
109
|
+
return (0, sift_1.default)(validateWhen(when))(context ?? {});
|
|
86
110
|
}
|
|
87
111
|
catch {
|
|
88
112
|
return false;
|
package/dist/protocol.d.ts
CHANGED
|
@@ -128,6 +128,9 @@ export type HostMessage = {
|
|
|
128
128
|
} | {
|
|
129
129
|
type: 'unmount';
|
|
130
130
|
mountId: string;
|
|
131
|
+
} | {
|
|
132
|
+
type: 'release-functions';
|
|
133
|
+
ids: string[];
|
|
131
134
|
} | {
|
|
132
135
|
type: 'context';
|
|
133
136
|
context: PluginContext;
|
|
@@ -146,11 +149,14 @@ export type HostMessage = {
|
|
|
146
149
|
export interface SerializedError {
|
|
147
150
|
message: string;
|
|
148
151
|
code?: string;
|
|
152
|
+
/** HTTP status, when the failure came from a request the host made for the plugin. */
|
|
153
|
+
status?: number;
|
|
149
154
|
stack?: string;
|
|
150
155
|
}
|
|
151
156
|
export declare class BridgeError extends Error {
|
|
152
157
|
code: string;
|
|
153
|
-
|
|
158
|
+
status?: number;
|
|
159
|
+
constructor(message: string, code?: string, status?: number);
|
|
154
160
|
}
|
|
155
161
|
export declare function serializeError(error: unknown): SerializedError;
|
|
156
162
|
export declare function deserializeError(error: SerializedError): BridgeError;
|
|
@@ -168,3 +174,7 @@ export declare function deserializeFunctions(value: unknown, resolve: (id: strin
|
|
|
168
174
|
*/
|
|
169
175
|
export declare function toCloneable(value: unknown, seen?: WeakSet<object>): unknown;
|
|
170
176
|
export declare function createIdGenerator(prefix: string): () => string;
|
|
177
|
+
/** Bound work before traversing data received from an untrusted worker. */
|
|
178
|
+
export declare function assertWireValue(value: unknown): void;
|
|
179
|
+
/** Deadline also covers custom adapters/loaders that ignore cancellation. */
|
|
180
|
+
export declare function withDeadline<T>(promise: Promise<T>, timeoutMs?: number, signal?: AbortSignal): Promise<T>;
|
package/dist/protocol.js
CHANGED
|
@@ -9,23 +9,62 @@
|
|
|
9
9
|
export const PROTOCOL_VERSION = 1;
|
|
10
10
|
export class BridgeError extends Error {
|
|
11
11
|
code;
|
|
12
|
-
|
|
12
|
+
status;
|
|
13
|
+
constructor(message, code = 'BRIDGE_ERROR', status) {
|
|
13
14
|
super(message);
|
|
14
15
|
this.name = 'BridgeError';
|
|
15
16
|
this.code = code;
|
|
17
|
+
if (status !== undefined)
|
|
18
|
+
this.status = status;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A rejection that is not an `Error`. The hosts' API clients reject with plain objects —
|
|
23
|
+
* RTK Query with `{ status, data }`, others with the parsed body — and `String(value)` on
|
|
24
|
+
* one of those yields `[object Object]`, which is how a real 404 reached plugins as an
|
|
25
|
+
* unreadable string. Pulls out the status and the most specific message it can find.
|
|
26
|
+
*/
|
|
27
|
+
function fromPlainObject(error) {
|
|
28
|
+
const status = typeof error.status === 'number' ? error.status : undefined;
|
|
29
|
+
const payload = error.data ?? error.body ?? error;
|
|
30
|
+
// A non-JSON response leaves the body as a plain string (RTK Query does this), and that
|
|
31
|
+
// string IS the reason — reading it only as an object would drop it.
|
|
32
|
+
const body = (typeof payload === 'object' && payload !== null ? payload : {});
|
|
33
|
+
const candidate = [
|
|
34
|
+
typeof payload === 'string' ? payload : undefined,
|
|
35
|
+
typeof body.message === 'string' ? body.message : undefined,
|
|
36
|
+
typeof body.error === 'string' ? body.error : undefined,
|
|
37
|
+
typeof error.message === 'string' ? error.message : undefined,
|
|
38
|
+
typeof error.error === 'string' ? error.error : undefined,
|
|
39
|
+
].find((value) => value !== undefined && value !== '');
|
|
40
|
+
// A status alone still says more than `[object Object]`; with neither, let the caller
|
|
41
|
+
// fall back rather than inventing a message.
|
|
42
|
+
if (candidate === undefined && status === undefined)
|
|
43
|
+
return null;
|
|
44
|
+
const code = typeof error.code === 'string' ? error.code : status !== undefined ? `HTTP_${status}` : undefined;
|
|
45
|
+
return { message: candidate ?? `Request failed with status ${status}`, code, status };
|
|
46
|
+
}
|
|
18
47
|
export function serializeError(error) {
|
|
19
48
|
if (error instanceof BridgeError)
|
|
20
|
-
return { message: error.message, code: error.code, stack: error.stack };
|
|
49
|
+
return { message: error.message, code: error.code, status: error.status, stack: error.stack };
|
|
21
50
|
if (error instanceof Error) {
|
|
22
|
-
const code = error
|
|
23
|
-
return {
|
|
51
|
+
const { code, status } = error;
|
|
52
|
+
return {
|
|
53
|
+
message: error.message,
|
|
54
|
+
code: typeof code === 'string' ? code : undefined,
|
|
55
|
+
status: typeof status === 'number' ? status : undefined,
|
|
56
|
+
stack: error.stack,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (typeof error === 'object' && error !== null) {
|
|
60
|
+
const extracted = fromPlainObject(error);
|
|
61
|
+
if (extracted)
|
|
62
|
+
return extracted;
|
|
24
63
|
}
|
|
25
64
|
return { message: String(error) };
|
|
26
65
|
}
|
|
27
66
|
export function deserializeError(error) {
|
|
28
|
-
const bridgeError = new BridgeError(error.message, error.code);
|
|
67
|
+
const bridgeError = new BridgeError(error.message, error.code, error.status);
|
|
29
68
|
if (error.stack)
|
|
30
69
|
bridgeError.stack = error.stack;
|
|
31
70
|
return bridgeError;
|
|
@@ -90,12 +129,14 @@ export function toCloneable(value, seen = new WeakSet()) {
|
|
|
90
129
|
}
|
|
91
130
|
if (typeof Node !== 'undefined' && value instanceof Node)
|
|
92
131
|
return undefined;
|
|
93
|
-
if (Array.isArray(value))
|
|
94
|
-
return value.map((item) => toCloneable(item, seen));
|
|
95
132
|
if (type === 'object') {
|
|
96
133
|
if (seen.has(value))
|
|
97
134
|
return undefined;
|
|
98
135
|
seen.add(value);
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value))
|
|
138
|
+
return value.map((item) => toCloneable(item, seen));
|
|
139
|
+
if (type === 'object') {
|
|
99
140
|
const out = {};
|
|
100
141
|
for (const [key, item] of Object.entries(value)) {
|
|
101
142
|
const cloned = toCloneable(item, seen);
|
|
@@ -110,3 +151,51 @@ let counter = 0;
|
|
|
110
151
|
export function createIdGenerator(prefix) {
|
|
111
152
|
return () => `${prefix}-${++counter}`;
|
|
112
153
|
}
|
|
154
|
+
/** Bound work before traversing data received from an untrusted worker. */
|
|
155
|
+
export function assertWireValue(value) {
|
|
156
|
+
let nodes = 0, characters = 0;
|
|
157
|
+
const seen = new WeakSet();
|
|
158
|
+
const walk = (item, depth) => {
|
|
159
|
+
if (++nodes > 50000 || depth > 32)
|
|
160
|
+
throw new BridgeError('Message exceeds complexity limit', 'MESSAGE_LIMIT');
|
|
161
|
+
if (typeof item === 'string')
|
|
162
|
+
characters += item.length;
|
|
163
|
+
else if (item && typeof item === 'object') {
|
|
164
|
+
if (seen.has(item))
|
|
165
|
+
throw new BridgeError('Cyclic message', 'INVALID_MESSAGE');
|
|
166
|
+
seen.add(item);
|
|
167
|
+
for (const [key, child] of Object.entries(item)) {
|
|
168
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key))
|
|
169
|
+
throw new BridgeError('Unsafe message key', 'INVALID_MESSAGE');
|
|
170
|
+
characters += key.length;
|
|
171
|
+
walk(child, depth + 1);
|
|
172
|
+
}
|
|
173
|
+
seen.delete(item);
|
|
174
|
+
}
|
|
175
|
+
else if (!['undefined', 'boolean', 'number'].includes(typeof item) && item !== null) {
|
|
176
|
+
throw new BridgeError('Message must contain plain data', 'INVALID_MESSAGE');
|
|
177
|
+
}
|
|
178
|
+
if (characters > 2 * 1024 * 1024)
|
|
179
|
+
throw new BridgeError('Message exceeds size limit', 'MESSAGE_LIMIT');
|
|
180
|
+
};
|
|
181
|
+
walk(value, 0);
|
|
182
|
+
}
|
|
183
|
+
/** Deadline also covers custom adapters/loaders that ignore cancellation. */
|
|
184
|
+
export function withDeadline(promise, timeoutMs = 30000, signal) {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
const finish = (error, value) => {
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
signal?.removeEventListener('abort', abort);
|
|
189
|
+
if (error)
|
|
190
|
+
reject(error);
|
|
191
|
+
else
|
|
192
|
+
resolve(value);
|
|
193
|
+
};
|
|
194
|
+
const abort = () => finish(new BridgeError('Operation cancelled', 'DISPOSED'));
|
|
195
|
+
const timer = setTimeout(() => finish(new BridgeError('Operation timed out', 'TIMEOUT')), timeoutMs);
|
|
196
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
197
|
+
if (signal?.aborted)
|
|
198
|
+
abort();
|
|
199
|
+
promise.then(value => finish(undefined, value), error => finish(error));
|
|
200
|
+
});
|
|
201
|
+
}
|
package/dist/worker.js
CHANGED
|
@@ -3,19 +3,18 @@ import "./polyfill.js";
|
|
|
3
3
|
* Worker-side runtime: receives the MessagePort from the sandbox bootstrap,
|
|
4
4
|
* mounts widgets into remote-dom roots and relays mutations to the host.
|
|
5
5
|
*/
|
|
6
|
-
import { createElement } from 'react';
|
|
6
|
+
import { Component, createElement } from 'react';
|
|
7
7
|
import { createRoot } from 'react-dom/client';
|
|
8
8
|
import { BatchingRemoteConnection } from '@remote-dom/core/elements';
|
|
9
9
|
import { defineCatalogElements, ROOT_TAG } from './elements.js';
|
|
10
10
|
import { bridge } from './bridge.js';
|
|
11
11
|
import { PluginContextProvider, broadcastContext } from './context.js';
|
|
12
12
|
import { PROTOCOL_VERSION, createIdGenerator, serializeError, serializeFunctions, } from './protocol.js';
|
|
13
|
-
const functions = new Map();
|
|
14
13
|
const nextFunctionId = createIdGenerator('fn');
|
|
15
14
|
const mounts = new Map();
|
|
16
15
|
let definition = null;
|
|
17
16
|
let pluginId = 'unknown';
|
|
18
|
-
function createConnection(port, mountId) {
|
|
17
|
+
function createConnection(port, mountId, functions) {
|
|
19
18
|
const raw = {
|
|
20
19
|
mutate(records) {
|
|
21
20
|
const cloneable = serializeFunctions(records, nextFunctionId, functions);
|
|
@@ -27,6 +26,14 @@ function createConnection(port, mountId) {
|
|
|
27
26
|
};
|
|
28
27
|
return new BatchingRemoteConnection(raw);
|
|
29
28
|
}
|
|
29
|
+
class WorkerErrorBoundary extends Component {
|
|
30
|
+
state = { failed: false };
|
|
31
|
+
static getDerivedStateFromError() { return { failed: true }; }
|
|
32
|
+
componentDidCatch(error) {
|
|
33
|
+
this.props.port.postMessage({ type: 'error', mountId: this.props.mountId, error: serializeError(error) });
|
|
34
|
+
}
|
|
35
|
+
render() { return this.state.failed ? null : this.props.children; }
|
|
36
|
+
}
|
|
30
37
|
function mount(port, message) {
|
|
31
38
|
if (!definition)
|
|
32
39
|
throw new Error('defineUI() was not called before mount');
|
|
@@ -36,10 +43,11 @@ function mount(port, message) {
|
|
|
36
43
|
defineCatalogElements();
|
|
37
44
|
const element = document.createElement(ROOT_TAG);
|
|
38
45
|
document.body.append(element);
|
|
39
|
-
|
|
46
|
+
const functions = new Map();
|
|
47
|
+
element.connect(createConnection(port, message.mountId, functions));
|
|
40
48
|
const root = createRoot(element);
|
|
41
|
-
root.render(createElement(PluginContextProvider, { initial: message.context }, createElement(Widget, { slot: message.slot, config: message.config })));
|
|
42
|
-
mounts.set(message.mountId, { root, element });
|
|
49
|
+
root.render(createElement(PluginContextProvider, { initial: message.context }, createElement(WorkerErrorBoundary, { port, mountId: message.mountId }, createElement(Widget, { slot: message.slot, config: message.config }))));
|
|
50
|
+
mounts.set(message.mountId, { root, element, functions });
|
|
43
51
|
}
|
|
44
52
|
function unmount(mountId) {
|
|
45
53
|
const current = mounts.get(mountId);
|
|
@@ -50,7 +58,7 @@ function unmount(mountId) {
|
|
|
50
58
|
mounts.delete(mountId);
|
|
51
59
|
}
|
|
52
60
|
async function invokeFunction(port, message) {
|
|
53
|
-
const fn = functions.get(message.fnId);
|
|
61
|
+
const fn = [...mounts.values()].map(mount => mount.functions.get(message.fnId)).find(Boolean);
|
|
54
62
|
if (!fn) {
|
|
55
63
|
port.postMessage({ type: 'fn-result', id: message.id, ok: false, error: { message: `Unknown function ${message.fnId}` } });
|
|
56
64
|
return;
|
|
@@ -85,6 +93,11 @@ function handle(port, message) {
|
|
|
85
93
|
case 'unmount':
|
|
86
94
|
unmount(message.mountId);
|
|
87
95
|
break;
|
|
96
|
+
case 'release-functions':
|
|
97
|
+
for (const mount of mounts.values())
|
|
98
|
+
for (const id of message.ids)
|
|
99
|
+
mount.functions.delete(id);
|
|
100
|
+
break;
|
|
88
101
|
case 'context':
|
|
89
102
|
broadcastContext(message.context);
|
|
90
103
|
break;
|
|
@@ -106,6 +119,9 @@ function handle(port, message) {
|
|
|
106
119
|
/** Connects this worker to the host through the port handed over by the sandbox. */
|
|
107
120
|
export function connect(port) {
|
|
108
121
|
bridge.attach(port);
|
|
122
|
+
globalThis.addEventListener('unhandledrejection', (event) => {
|
|
123
|
+
port.postMessage({ type: 'error', error: serializeError(event.reason) });
|
|
124
|
+
});
|
|
109
125
|
port.onmessage = (event) => handle(port, event.data);
|
|
110
126
|
port.start?.();
|
|
111
127
|
port.postMessage({
|