@nullplatform/ui-plugin-sdk 0.6.1 → 0.7.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 +6 -0
- package/dist/catalog.d.ts +9 -1
- package/dist/components.generated.d.ts +269 -0
- package/dist/components.generated.js +31 -1
- package/dist/context.d.ts +1 -0
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract/manifest.d.ts +2 -0
- package/dist/contract/manifest.js +43 -0
- package/dist/contract/topics.d.ts +40 -0
- package/dist/contract/topics.js +128 -0
- package/dist/contract-cjs/index.js +12 -1
- package/dist/contract-cjs/manifest.js +43 -0
- package/dist/contract-cjs/topics.js +140 -0
- package/dist/contracts.generated.d.ts +370 -0
- package/dist/contracts.generated.js +211 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/protocol.d.ts +21 -0
- package/dist/topics.d.ts +75 -0
- package/dist/topics.js +146 -0
- package/dist/worker.js +4 -0
- package/package.json +2 -2
package/dist/bridge.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Plugin-side client of the host bridge. The only way out of the sandbox.
|
|
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
|
+
import { topics as topicsApi } from './topics.js';
|
|
5
6
|
export declare class BridgeClient {
|
|
6
7
|
private readonly timeoutMs;
|
|
7
8
|
private port;
|
|
@@ -39,5 +40,7 @@ export declare const nullplatform: {
|
|
|
39
40
|
context: {
|
|
40
41
|
get(): Promise<PluginContext>;
|
|
41
42
|
};
|
|
43
|
+
/** Named values shared on the page through the host. `useTopic` / `useSetTopic` wrap these. */
|
|
44
|
+
readonly topics: typeof topicsApi;
|
|
42
45
|
};
|
|
43
46
|
export type NullplatformBridge = typeof nullplatform;
|
package/dist/bridge.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Plugin-side client of the host bridge. The only way out of the sandbox.
|
|
3
3
|
*/
|
|
4
4
|
import { BridgeError, deserializeError, } from './protocol.js';
|
|
5
|
+
import { topics as topicsApi } from './topics.js';
|
|
5
6
|
export class BridgeClient {
|
|
6
7
|
timeoutMs;
|
|
7
8
|
port = null;
|
|
@@ -101,4 +102,9 @@ export const nullplatform = {
|
|
|
101
102
|
return bridge.call('context.get');
|
|
102
103
|
},
|
|
103
104
|
},
|
|
105
|
+
/** Named values shared on the page through the host. `useTopic` / `useSetTopic` wrap these. */
|
|
106
|
+
get topics() {
|
|
107
|
+
// A getter: topics.ts imports this module back, so it is read on use rather than at load.
|
|
108
|
+
return topicsApi;
|
|
109
|
+
},
|
|
104
110
|
};
|
package/dist/catalog.d.ts
CHANGED
|
@@ -20,13 +20,21 @@ export interface CatalogElementSpec {
|
|
|
20
20
|
events: Record<string, string>;
|
|
21
21
|
/** Named slots (rendered as React element props). */
|
|
22
22
|
slots?: readonly string[];
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Closed lists for string props. The host drops any other value, so the element draws its default. `prop[].key`
|
|
25
|
+
* names a key of each item in an array prop, which the host drops from an item whose value isn't in the list.
|
|
26
|
+
*/
|
|
24
27
|
values?: Readonly<Record<string, readonly string[]>>;
|
|
25
28
|
/**
|
|
26
29
|
* Props that end up in CSS, which the host only passes as plain values. `prop[].key` names a key of each item
|
|
27
30
|
* in an array prop.
|
|
28
31
|
*/
|
|
29
32
|
cssValues?: readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Props that load an image, which the host only passes when they point to plugin bundle storage, as np-image's
|
|
35
|
+
* `src` does. `prop[].key` names a key of each item in an array prop.
|
|
36
|
+
*/
|
|
37
|
+
imageValues?: readonly string[];
|
|
30
38
|
/** Whether the element draws nested elements. The host drops children otherwise. */
|
|
31
39
|
children?: boolean;
|
|
32
40
|
/** What the element draws for a prop the plugin leaves out or the host drops, whichever implementation draws it. */
|
|
@@ -59,3 +59,272 @@ export declare const CircularProgress: import("react").ComponentType<{
|
|
|
59
59
|
} & {} & {} & {
|
|
60
60
|
children?: import("react").ReactNode;
|
|
61
61
|
}>;
|
|
62
|
+
export declare const DetailView: import("react").ComponentType<{
|
|
63
|
+
spacing?: number | undefined;
|
|
64
|
+
padding?: number | undefined;
|
|
65
|
+
disableDividers?: boolean | undefined;
|
|
66
|
+
loading?: boolean | undefined;
|
|
67
|
+
loadingSections?: number | undefined;
|
|
68
|
+
} & {} & {} & {
|
|
69
|
+
children?: import("react").ReactNode;
|
|
70
|
+
}>;
|
|
71
|
+
export declare const DetailHeader: import("react").ComponentType<{
|
|
72
|
+
title?: string | undefined;
|
|
73
|
+
} & {} & {
|
|
74
|
+
actions?: import("react").ReactNode;
|
|
75
|
+
} & {
|
|
76
|
+
children?: import("react").ReactNode;
|
|
77
|
+
}>;
|
|
78
|
+
export declare const DetailSection: import("react").ComponentType<{
|
|
79
|
+
label?: string | undefined;
|
|
80
|
+
spacing?: number | undefined;
|
|
81
|
+
} & {} & {} & {
|
|
82
|
+
children?: import("react").ReactNode;
|
|
83
|
+
}>;
|
|
84
|
+
export declare const DetailColumns: import("react").ComponentType<{
|
|
85
|
+
spacing?: number | undefined;
|
|
86
|
+
} & {} & {} & {
|
|
87
|
+
children?: import("react").ReactNode;
|
|
88
|
+
}>;
|
|
89
|
+
export declare const DetailColumn: import("react").ComponentType<{
|
|
90
|
+
minWidth?: number | undefined;
|
|
91
|
+
spacing?: number | undefined;
|
|
92
|
+
} & {} & {} & {
|
|
93
|
+
children?: import("react").ReactNode;
|
|
94
|
+
}>;
|
|
95
|
+
export declare const DetailRow: import("react").ComponentType<{
|
|
96
|
+
label?: string | undefined;
|
|
97
|
+
labelMinWidth?: number | undefined;
|
|
98
|
+
valueColor?: string | undefined;
|
|
99
|
+
labelColor?: string | undefined;
|
|
100
|
+
hideColon?: boolean | undefined;
|
|
101
|
+
} & {} & {
|
|
102
|
+
icon?: import("react").ReactNode;
|
|
103
|
+
} & {
|
|
104
|
+
children?: import("react").ReactNode;
|
|
105
|
+
}>;
|
|
106
|
+
export declare const FilterDropdown: import("react").ComponentType<{
|
|
107
|
+
label?: string | undefined;
|
|
108
|
+
placeholder?: string | undefined;
|
|
109
|
+
elements?: readonly unknown[] | undefined;
|
|
110
|
+
selected?: string | undefined;
|
|
111
|
+
loading?: boolean | undefined;
|
|
112
|
+
disabled?: boolean | undefined;
|
|
113
|
+
disableSort?: boolean | undefined;
|
|
114
|
+
disableClear?: boolean | undefined;
|
|
115
|
+
} & {
|
|
116
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
117
|
+
} & {} & {
|
|
118
|
+
children?: import("react").ReactNode;
|
|
119
|
+
}>;
|
|
120
|
+
export declare const FilterDropdownMultiple: import("react").ComponentType<{
|
|
121
|
+
label?: string | undefined;
|
|
122
|
+
elements?: readonly unknown[] | undefined;
|
|
123
|
+
selected?: readonly unknown[] | undefined;
|
|
124
|
+
loading?: boolean | undefined;
|
|
125
|
+
disabled?: boolean | undefined;
|
|
126
|
+
showActions?: boolean | undefined;
|
|
127
|
+
} & {
|
|
128
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
129
|
+
} & {} & {
|
|
130
|
+
children?: import("react").ReactNode;
|
|
131
|
+
}>;
|
|
132
|
+
export declare const FilterName: import("react").ComponentType<{
|
|
133
|
+
filterName?: string | undefined;
|
|
134
|
+
placeholder?: string | undefined;
|
|
135
|
+
loading?: boolean | undefined;
|
|
136
|
+
} & {
|
|
137
|
+
readonly onFilterName?: ((payload: unknown) => void) | undefined;
|
|
138
|
+
} & {} & {
|
|
139
|
+
children?: import("react").ReactNode;
|
|
140
|
+
}>;
|
|
141
|
+
export declare const ListItemIcon: import("react").ComponentType<{} & {} & {} & {
|
|
142
|
+
children?: import("react").ReactNode;
|
|
143
|
+
}>;
|
|
144
|
+
export declare const ListItemAvatar: import("react").ComponentType<{} & {} & {} & {
|
|
145
|
+
children?: import("react").ReactNode;
|
|
146
|
+
}>;
|
|
147
|
+
export declare const ListSubheader: import("react").ComponentType<{
|
|
148
|
+
color?: "default" | "primary" | "inherit" | undefined;
|
|
149
|
+
disableGutters?: boolean | undefined;
|
|
150
|
+
disableSticky?: boolean | undefined;
|
|
151
|
+
inset?: boolean | undefined;
|
|
152
|
+
} & {} & {} & {
|
|
153
|
+
children?: import("react").ReactNode;
|
|
154
|
+
}>;
|
|
155
|
+
export declare const RelativeDate: import("react").ComponentType<{
|
|
156
|
+
date?: string | undefined;
|
|
157
|
+
icon?: string | undefined;
|
|
158
|
+
label?: string | undefined;
|
|
159
|
+
hideLabel?: boolean | undefined;
|
|
160
|
+
options?: Readonly<Record<string, unknown>> | undefined;
|
|
161
|
+
showTooltip?: boolean | undefined;
|
|
162
|
+
emptyText?: string | undefined;
|
|
163
|
+
live?: boolean | undefined;
|
|
164
|
+
} & {} & {} & {
|
|
165
|
+
children?: import("react").ReactNode;
|
|
166
|
+
}>;
|
|
167
|
+
export declare const Duration: import("react").ComponentType<{
|
|
168
|
+
ms?: number | undefined;
|
|
169
|
+
from?: string | undefined;
|
|
170
|
+
to?: string | undefined;
|
|
171
|
+
running?: boolean | undefined;
|
|
172
|
+
icon?: string | undefined;
|
|
173
|
+
label?: string | undefined;
|
|
174
|
+
hideLabel?: boolean | undefined;
|
|
175
|
+
emptyText?: string | undefined;
|
|
176
|
+
} & {} & {} & {
|
|
177
|
+
children?: import("react").ReactNode;
|
|
178
|
+
}>;
|
|
179
|
+
export declare const TimelineCell: import("react").ComponentType<{
|
|
180
|
+
createdAt?: string | undefined;
|
|
181
|
+
updatedAt?: string | undefined;
|
|
182
|
+
duration?: number | undefined;
|
|
183
|
+
createdLabel?: string | undefined;
|
|
184
|
+
updatedLabel?: string | undefined;
|
|
185
|
+
durationLabel?: string | undefined;
|
|
186
|
+
options?: Readonly<Record<string, unknown>> | undefined;
|
|
187
|
+
hideLabels?: boolean | undefined;
|
|
188
|
+
running?: boolean | undefined;
|
|
189
|
+
spacing?: number | undefined;
|
|
190
|
+
} & {} & {} & {
|
|
191
|
+
children?: import("react").ReactNode;
|
|
192
|
+
}>;
|
|
193
|
+
export declare const TextMaxLine: import("react").ComponentType<{
|
|
194
|
+
variant?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "subtitle1" | "subtitle2" | "body1" | "body2" | "caption" | "overline" | "button" | undefined;
|
|
195
|
+
line?: number | undefined;
|
|
196
|
+
persistent?: boolean | undefined;
|
|
197
|
+
} & {} & {} & {
|
|
198
|
+
children?: import("react").ReactNode;
|
|
199
|
+
}>;
|
|
200
|
+
export declare const GroupHeading: import("react").ComponentType<{
|
|
201
|
+
label?: string | undefined;
|
|
202
|
+
description?: string | undefined;
|
|
203
|
+
required?: boolean | undefined;
|
|
204
|
+
} & {} & {} & {
|
|
205
|
+
children?: import("react").ReactNode;
|
|
206
|
+
}>;
|
|
207
|
+
export declare const DimensionsByline: import("react").ComponentType<{
|
|
208
|
+
dimensions?: Readonly<Record<string, unknown>> | undefined;
|
|
209
|
+
catalog?: readonly unknown[] | undefined;
|
|
210
|
+
disabled?: boolean | undefined;
|
|
211
|
+
showUnsetAxes?: boolean | undefined;
|
|
212
|
+
unsetValueLabel?: string | undefined;
|
|
213
|
+
} & {} & {} & {
|
|
214
|
+
children?: import("react").ReactNode;
|
|
215
|
+
}>;
|
|
216
|
+
export declare const Container: import("react").ComponentType<{
|
|
217
|
+
maxWidth?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
|
|
218
|
+
fixed?: boolean | undefined;
|
|
219
|
+
disableGutters?: boolean | undefined;
|
|
220
|
+
} & {} & {} & {
|
|
221
|
+
children?: import("react").ReactNode;
|
|
222
|
+
}>;
|
|
223
|
+
export declare const Scrollbar: import("react").ComponentType<{
|
|
224
|
+
fade?: boolean | undefined;
|
|
225
|
+
} & {} & {} & {
|
|
226
|
+
children?: import("react").ReactNode;
|
|
227
|
+
}>;
|
|
228
|
+
export declare const GroupedFilterDropdown: import("react").ComponentType<{
|
|
229
|
+
label?: string | undefined;
|
|
230
|
+
elements?: readonly unknown[] | undefined;
|
|
231
|
+
selected?: Readonly<Record<string, unknown>> | undefined;
|
|
232
|
+
loading?: boolean | undefined;
|
|
233
|
+
disabled?: boolean | undefined;
|
|
234
|
+
shouldFitFont?: boolean | undefined;
|
|
235
|
+
} & {
|
|
236
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
237
|
+
readonly onOpen?: ((payload: unknown) => void) | undefined;
|
|
238
|
+
} & {} & {
|
|
239
|
+
children?: import("react").ReactNode;
|
|
240
|
+
}>;
|
|
241
|
+
export declare const CopyToClipboardButton: import("react").ComponentType<{
|
|
242
|
+
text?: string | undefined;
|
|
243
|
+
tooltipCopy?: string | undefined;
|
|
244
|
+
tooltipCopied?: string | undefined;
|
|
245
|
+
icon?: string | undefined;
|
|
246
|
+
iconSize?: number | undefined;
|
|
247
|
+
} & {
|
|
248
|
+
readonly onCopy?: ((payload: unknown) => void) | undefined;
|
|
249
|
+
} & {} & {
|
|
250
|
+
children?: import("react").ReactNode;
|
|
251
|
+
}>;
|
|
252
|
+
export declare const CountdownButton: import("react").ComponentType<{
|
|
253
|
+
label?: string | undefined;
|
|
254
|
+
cooldownTime?: number | undefined;
|
|
255
|
+
fullWidth?: boolean | undefined;
|
|
256
|
+
} & {
|
|
257
|
+
readonly onClick?: ((payload: unknown) => void) | undefined;
|
|
258
|
+
} & {
|
|
259
|
+
startIcon?: import("react").ReactNode;
|
|
260
|
+
} & {
|
|
261
|
+
children?: import("react").ReactNode;
|
|
262
|
+
}>;
|
|
263
|
+
export declare const Label: import("react").ComponentType<{
|
|
264
|
+
color?: "default" | "success" | "error" | "warning" | "info" | "primary" | "secondary" | undefined;
|
|
265
|
+
variant?: "outlined" | "filled" | "ghost" | "soft" | undefined;
|
|
266
|
+
} & {} & {
|
|
267
|
+
startIcon?: import("react").ReactNode;
|
|
268
|
+
endIcon?: import("react").ReactNode;
|
|
269
|
+
} & {
|
|
270
|
+
children?: import("react").ReactNode;
|
|
271
|
+
}>;
|
|
272
|
+
export declare const Avatar: import("react").ComponentType<{
|
|
273
|
+
name?: string | undefined;
|
|
274
|
+
color?: "default" | "success" | "error" | "warning" | "info" | "primary" | "secondary" | undefined;
|
|
275
|
+
size?: "small" | "medium" | "large" | undefined;
|
|
276
|
+
variant?: "circular" | "rounded" | "square" | undefined;
|
|
277
|
+
} & {} & {} & {
|
|
278
|
+
children?: import("react").ReactNode;
|
|
279
|
+
}>;
|
|
280
|
+
export declare const IconPicker: import("react").ComponentType<{
|
|
281
|
+
value?: string | undefined;
|
|
282
|
+
prefix?: string | undefined;
|
|
283
|
+
minChars?: number | undefined;
|
|
284
|
+
debounceMs?: number | undefined;
|
|
285
|
+
placeholder?: string | undefined;
|
|
286
|
+
loadingText?: string | undefined;
|
|
287
|
+
noResultsText?: string | undefined;
|
|
288
|
+
errorText?: string | undefined;
|
|
289
|
+
helperText?: string | undefined;
|
|
290
|
+
error?: boolean | undefined;
|
|
291
|
+
label?: string | undefined;
|
|
292
|
+
size?: "small" | "medium" | undefined;
|
|
293
|
+
disabled?: boolean | undefined;
|
|
294
|
+
iconWidth?: number | undefined;
|
|
295
|
+
} & {
|
|
296
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
297
|
+
} & {} & {
|
|
298
|
+
children?: import("react").ReactNode;
|
|
299
|
+
}>;
|
|
300
|
+
export declare const TabBar: import("react").ComponentType<{
|
|
301
|
+
items?: readonly unknown[] | undefined;
|
|
302
|
+
value?: string | undefined;
|
|
303
|
+
variant?: "standard" | "scrollable" | "fullWidth" | undefined;
|
|
304
|
+
} & {
|
|
305
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
306
|
+
} & {} & {
|
|
307
|
+
children?: import("react").ReactNode;
|
|
308
|
+
}>;
|
|
309
|
+
export declare const BreadcrumbTrail: import("react").ComponentType<{
|
|
310
|
+
items?: readonly unknown[] | undefined;
|
|
311
|
+
maxItems?: number | undefined;
|
|
312
|
+
} & {
|
|
313
|
+
readonly onSelect?: ((payload: unknown) => void) | undefined;
|
|
314
|
+
} & {} & {
|
|
315
|
+
children?: import("react").ReactNode;
|
|
316
|
+
}>;
|
|
317
|
+
export declare const ChipList: import("react").ComponentType<{
|
|
318
|
+
items?: readonly unknown[] | undefined;
|
|
319
|
+
variant?: "outlined" | "filled" | "soft" | undefined;
|
|
320
|
+
loading?: boolean | undefined;
|
|
321
|
+
maxItemsToShow?: number | undefined;
|
|
322
|
+
disableListItem?: boolean | undefined;
|
|
323
|
+
} & {} & {} & {
|
|
324
|
+
children?: import("react").ReactNode;
|
|
325
|
+
}>;
|
|
326
|
+
export declare const ActivityTimeline: import("react").ComponentType<{
|
|
327
|
+
items?: readonly unknown[] | undefined;
|
|
328
|
+
} & {} & {} & {
|
|
329
|
+
children?: import("react").ReactNode;
|
|
330
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.
|
|
1
|
+
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.15.9. Don't edit: change the contract in
|
|
2
2
|
// react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
|
|
3
3
|
import { component } from "./component.js";
|
|
4
4
|
export const Badge = component("np-badge");
|
|
@@ -8,3 +8,33 @@ export const ListItem = component("np-list-item");
|
|
|
8
8
|
export const ListItemText = component("np-list-item-text");
|
|
9
9
|
export const LinearProgress = component("np-linear-progress");
|
|
10
10
|
export const CircularProgress = component("np-circular-progress");
|
|
11
|
+
export const DetailView = component("np-detail-view");
|
|
12
|
+
export const DetailHeader = component("np-detail-header");
|
|
13
|
+
export const DetailSection = component("np-detail-section");
|
|
14
|
+
export const DetailColumns = component("np-detail-columns");
|
|
15
|
+
export const DetailColumn = component("np-detail-column");
|
|
16
|
+
export const DetailRow = component("np-detail-row");
|
|
17
|
+
export const FilterDropdown = component("np-filter-dropdown");
|
|
18
|
+
export const FilterDropdownMultiple = component("np-filter-dropdown-multiple");
|
|
19
|
+
export const FilterName = component("np-filter-name");
|
|
20
|
+
export const ListItemIcon = component("np-list-item-icon");
|
|
21
|
+
export const ListItemAvatar = component("np-list-item-avatar");
|
|
22
|
+
export const ListSubheader = component("np-list-subheader");
|
|
23
|
+
export const RelativeDate = component("np-relative-date");
|
|
24
|
+
export const Duration = component("np-duration");
|
|
25
|
+
export const TimelineCell = component("np-timeline-cell");
|
|
26
|
+
export const TextMaxLine = component("np-text-max-line");
|
|
27
|
+
export const GroupHeading = component("np-group-heading");
|
|
28
|
+
export const DimensionsByline = component("np-dimensions-byline");
|
|
29
|
+
export const Container = component("np-container");
|
|
30
|
+
export const Scrollbar = component("np-scrollbar");
|
|
31
|
+
export const GroupedFilterDropdown = component("np-grouped-filter-dropdown");
|
|
32
|
+
export const CopyToClipboardButton = component("np-copy-to-clipboard-button");
|
|
33
|
+
export const CountdownButton = component("np-countdown-button");
|
|
34
|
+
export const Label = component("np-label");
|
|
35
|
+
export const Avatar = component("np-avatar");
|
|
36
|
+
export const IconPicker = component("np-icon-picker");
|
|
37
|
+
export const TabBar = component("np-tab-bar");
|
|
38
|
+
export const BreadcrumbTrail = component("np-breadcrumb-trail");
|
|
39
|
+
export const ChipList = component("np-chip-list");
|
|
40
|
+
export const ActivityTimeline = component("np-activity-timeline");
|
package/dist/context.d.ts
CHANGED
package/dist/contract/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, type
|
|
|
2
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';
|
|
5
|
+
export { TOPIC_VALUE_MAX_CHARS, isTopicName, isHostTopic, topicOwner, isFieldPath, consumeGrant, canProvideTopic, projectFields, redactBySchema, assertTopicValue, type TopicPermissions, type TopicConsumePermission, type TopicProvidePermission, } from './topics.js';
|
package/dist/contract/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, } fro
|
|
|
2
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';
|
|
5
|
+
export { TOPIC_VALUE_MAX_CHARS, isTopicName, isHostTopic, topicOwner, isFieldPath, consumeGrant, canProvideTopic, projectFields, redactBySchema, assertTopicValue, } from './topics.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type WhenQuery } from './when.js';
|
|
2
|
+
import { type TopicPermissions } from './topics.js';
|
|
2
3
|
export declare const PROTOCOL_VERSION = 1;
|
|
3
4
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
4
5
|
export interface ApiPermission {
|
|
@@ -35,6 +36,7 @@ export interface PluginManifest {
|
|
|
35
36
|
permissions?: {
|
|
36
37
|
api?: ApiPermission[];
|
|
37
38
|
http?: HttpPermission[];
|
|
39
|
+
topics?: TopicPermissions;
|
|
38
40
|
};
|
|
39
41
|
contributes: Contribution[];
|
|
40
42
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validateWhen, WhenError } from './when.js';
|
|
2
|
+
import { isFieldPath, isHostTopic, isTopicName, topicOwner } from './topics.js';
|
|
2
3
|
export const PROTOCOL_VERSION = 1;
|
|
3
4
|
export class ManifestError extends Error {
|
|
4
5
|
constructor(message) {
|
|
@@ -96,6 +97,9 @@ export function validateManifest(input) {
|
|
|
96
97
|
return { host, method: readMethod(p.method, where), path: readPath(p.path, where) };
|
|
97
98
|
});
|
|
98
99
|
}
|
|
100
|
+
if (rawPermissions.topics !== undefined) {
|
|
101
|
+
permissions.topics = readTopicPermissions(rawPermissions.topics, m.id);
|
|
102
|
+
}
|
|
99
103
|
return {
|
|
100
104
|
protocol: PROTOCOL_VERSION,
|
|
101
105
|
id: m.id,
|
|
@@ -106,3 +110,42 @@ export function validateManifest(input) {
|
|
|
106
110
|
contributes,
|
|
107
111
|
};
|
|
108
112
|
}
|
|
113
|
+
function readTopicPermissions(raw, pluginId) {
|
|
114
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
115
|
+
throw new ManifestError('permissions.topics must be an object');
|
|
116
|
+
const t = raw;
|
|
117
|
+
const topics = {};
|
|
118
|
+
if (t.consume !== undefined) {
|
|
119
|
+
if (!Array.isArray(t.consume))
|
|
120
|
+
throw new ManifestError('permissions.topics.consume must be an array');
|
|
121
|
+
topics.consume = t.consume.map((item, index) => {
|
|
122
|
+
const where = `permissions.topics.consume[${index}]`;
|
|
123
|
+
const c = (item ?? {});
|
|
124
|
+
if (!isTopicName(c.topic))
|
|
125
|
+
throw new ManifestError(`${where}.topic must look like np.<name>@<major> or <plugin>/<name>@<major>`);
|
|
126
|
+
if (c.fields === undefined) {
|
|
127
|
+
// Host topics carry page data: a plugin names what it reads instead of getting everything.
|
|
128
|
+
if (isHostTopic(c.topic))
|
|
129
|
+
throw new ManifestError(`${where}.fields is required for host topics`);
|
|
130
|
+
return { topic: c.topic };
|
|
131
|
+
}
|
|
132
|
+
if (!Array.isArray(c.fields) || c.fields.length === 0 || !c.fields.every(isFieldPath)) {
|
|
133
|
+
throw new ManifestError(`${where}.fields must be a non-empty list of dot paths`);
|
|
134
|
+
}
|
|
135
|
+
return { topic: c.topic, fields: [...c.fields] };
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (t.provide !== undefined) {
|
|
139
|
+
if (!Array.isArray(t.provide))
|
|
140
|
+
throw new ManifestError('permissions.topics.provide must be an array');
|
|
141
|
+
topics.provide = t.provide.map((item, index) => {
|
|
142
|
+
const where = `permissions.topics.provide[${index}]`;
|
|
143
|
+
const p = (item ?? {});
|
|
144
|
+
if (!isTopicName(p.topic) || topicOwner(p.topic) !== pluginId) {
|
|
145
|
+
throw new ManifestError(`${where}.topic must be one of this plugin's topics: ${pluginId}/<name>@<major>`);
|
|
146
|
+
}
|
|
147
|
+
return { topic: p.topic };
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return topics;
|
|
151
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Topics: named values shared on a page, brokered by the host. A topic keeps only its latest value.
|
|
3
|
+
*
|
|
4
|
+
* - `np.<name>@<major>` topics belong to the host (the page publishes them, e.g. `np.service.draft@1`).
|
|
5
|
+
* - `<pluginId>/<name>@<major>` topics belong to that plugin; only it can set them.
|
|
6
|
+
*/
|
|
7
|
+
/** Largest value a topic accepts, measured as JSON. */
|
|
8
|
+
export declare const TOPIC_VALUE_MAX_CHARS: number;
|
|
9
|
+
export interface TopicConsumePermission {
|
|
10
|
+
topic: string;
|
|
11
|
+
/** Dot paths the plugin receives; everything else is left out. Required for `np.*` topics. */
|
|
12
|
+
fields?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface TopicProvidePermission {
|
|
15
|
+
topic: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TopicPermissions {
|
|
18
|
+
consume?: TopicConsumePermission[];
|
|
19
|
+
provide?: TopicProvidePermission[];
|
|
20
|
+
}
|
|
21
|
+
export declare function isTopicName(topic: unknown): topic is string;
|
|
22
|
+
export declare function isHostTopic(topic: string): boolean;
|
|
23
|
+
/** The plugin id that owns a plugin topic, or undefined for host topics. */
|
|
24
|
+
export declare function topicOwner(topic: string): string | undefined;
|
|
25
|
+
export declare function isFieldPath(path: unknown): path is string;
|
|
26
|
+
/** The consume grant for a topic, if the plugin declared one. A plugin can always read the topics it provides. */
|
|
27
|
+
export declare function consumeGrant(permissions: TopicPermissions | undefined, topic: string): TopicConsumePermission | undefined;
|
|
28
|
+
export declare function canProvideTopic(permissions: TopicPermissions | undefined, pluginId: string, topic: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Keeps only the given dot paths of `value`. Without `fields`, returns the value whole.
|
|
31
|
+
* A path that crosses an array keeps that array's elements projected to the rest of the path.
|
|
32
|
+
*/
|
|
33
|
+
export declare function projectFields(value: unknown, fields?: string[]): unknown;
|
|
34
|
+
/**
|
|
35
|
+
* Removes every value the JSON schema marks as secret, at any depth: object properties, array items,
|
|
36
|
+
* `additionalProperties` and the branches of `allOf` / `anyOf` / `oneOf`. Returns a new value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function redactBySchema(value: unknown, schema: unknown): unknown;
|
|
39
|
+
/** Throws unless `value` is plain JSON within the size limit. */
|
|
40
|
+
export declare function assertTopicValue(value: unknown): void;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Topics: named values shared on a page, brokered by the host. A topic keeps only its latest value.
|
|
3
|
+
*
|
|
4
|
+
* - `np.<name>@<major>` topics belong to the host (the page publishes them, e.g. `np.service.draft@1`).
|
|
5
|
+
* - `<pluginId>/<name>@<major>` topics belong to that plugin; only it can set them.
|
|
6
|
+
*/
|
|
7
|
+
const HOST_TOPIC = /^np(\.[a-z][a-z0-9]*)+@[1-9][0-9]*$/;
|
|
8
|
+
const PLUGIN_TOPIC = /^[a-z0-9][a-z0-9-]{1,63}\/[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*@[1-9][0-9]*$/;
|
|
9
|
+
const FIELD_PATH = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
10
|
+
/** Largest value a topic accepts, measured as JSON. */
|
|
11
|
+
export const TOPIC_VALUE_MAX_CHARS = 64 * 1024;
|
|
12
|
+
export function isTopicName(topic) {
|
|
13
|
+
return typeof topic === 'string' && (HOST_TOPIC.test(topic) || PLUGIN_TOPIC.test(topic));
|
|
14
|
+
}
|
|
15
|
+
export function isHostTopic(topic) {
|
|
16
|
+
return HOST_TOPIC.test(topic);
|
|
17
|
+
}
|
|
18
|
+
/** The plugin id that owns a plugin topic, or undefined for host topics. */
|
|
19
|
+
export function topicOwner(topic) {
|
|
20
|
+
return PLUGIN_TOPIC.test(topic) ? topic.slice(0, topic.indexOf('/')) : undefined;
|
|
21
|
+
}
|
|
22
|
+
export function isFieldPath(path) {
|
|
23
|
+
return typeof path === 'string' && FIELD_PATH.test(path) && !path.split('.').some((part) => ['__proto__', 'constructor', 'prototype'].includes(part));
|
|
24
|
+
}
|
|
25
|
+
/** The consume grant for a topic, if the plugin declared one. A plugin can always read the topics it provides. */
|
|
26
|
+
export function consumeGrant(permissions, topic) {
|
|
27
|
+
const declared = permissions?.consume?.find((item) => item.topic === topic);
|
|
28
|
+
if (declared)
|
|
29
|
+
return declared;
|
|
30
|
+
if (permissions?.provide?.some((item) => item.topic === topic))
|
|
31
|
+
return { topic };
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
export function canProvideTopic(permissions, pluginId, topic) {
|
|
35
|
+
return topicOwner(topic) === pluginId && Boolean(permissions?.provide?.some((item) => item.topic === topic));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Keeps only the given dot paths of `value`. Without `fields`, returns the value whole.
|
|
39
|
+
* A path that crosses an array keeps that array's elements projected to the rest of the path.
|
|
40
|
+
*/
|
|
41
|
+
export function projectFields(value, fields) {
|
|
42
|
+
if (!fields)
|
|
43
|
+
return value;
|
|
44
|
+
if (value === null || typeof value !== 'object')
|
|
45
|
+
return undefined;
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const field of fields)
|
|
48
|
+
copyPath(value, out, field.split('.'));
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
function copyPath(source, target, path) {
|
|
52
|
+
if (source === null || typeof source !== 'object' || Array.isArray(source))
|
|
53
|
+
return;
|
|
54
|
+
const [head, ...rest] = path;
|
|
55
|
+
if (!Object.prototype.hasOwnProperty.call(source, head))
|
|
56
|
+
return;
|
|
57
|
+
const child = source[head];
|
|
58
|
+
if (rest.length === 0) {
|
|
59
|
+
target[head] = child;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(child)) {
|
|
63
|
+
const existing = Array.isArray(target[head]) ? target[head] : child.map(() => ({}));
|
|
64
|
+
child.forEach((item, index) => copyPath(item, existing[index], rest));
|
|
65
|
+
target[head] = existing;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const next = (target[head] && typeof target[head] === 'object' ? target[head] : {});
|
|
69
|
+
copyPath(child, next, rest);
|
|
70
|
+
if (Object.keys(next).length > 0)
|
|
71
|
+
target[head] = next;
|
|
72
|
+
}
|
|
73
|
+
/** Same marks nullplatform uses to mask service attributes: `secret: true` or `export.secret`. */
|
|
74
|
+
function isSecret(schema) {
|
|
75
|
+
const exported = schema.export;
|
|
76
|
+
return schema.secret === true || (Boolean(exported) && typeof exported === 'object' && exported.secret === true);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Removes every value the JSON schema marks as secret, at any depth: object properties, array items,
|
|
80
|
+
* `additionalProperties` and the branches of `allOf` / `anyOf` / `oneOf`. Returns a new value.
|
|
81
|
+
*/
|
|
82
|
+
export function redactBySchema(value, schema) {
|
|
83
|
+
if (!schema || typeof schema !== 'object')
|
|
84
|
+
return value;
|
|
85
|
+
const node = schema;
|
|
86
|
+
if (isSecret(node))
|
|
87
|
+
return undefined;
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
const items = node.items;
|
|
90
|
+
return items && typeof items === 'object' && !Array.isArray(items) ? value.map((item) => redactBySchema(item, items)) : value;
|
|
91
|
+
}
|
|
92
|
+
if (value === null || typeof value !== 'object')
|
|
93
|
+
return value;
|
|
94
|
+
let result = { ...value };
|
|
95
|
+
const properties = (node.properties ?? {});
|
|
96
|
+
const additional = node.additionalProperties;
|
|
97
|
+
for (const key of Object.keys(result)) {
|
|
98
|
+
const child = properties[key] ?? (additional && typeof additional === 'object' ? additional : undefined);
|
|
99
|
+
if (!child)
|
|
100
|
+
continue;
|
|
101
|
+
const redacted = redactBySchema(result[key], child);
|
|
102
|
+
if (redacted === undefined)
|
|
103
|
+
delete result[key];
|
|
104
|
+
else
|
|
105
|
+
result[key] = redacted;
|
|
106
|
+
}
|
|
107
|
+
for (const combinator of ['allOf', 'anyOf', 'oneOf']) {
|
|
108
|
+
const branches = node[combinator];
|
|
109
|
+
if (Array.isArray(branches))
|
|
110
|
+
for (const branch of branches)
|
|
111
|
+
result = redactBySchema(result, branch);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/** Throws unless `value` is plain JSON within the size limit. */
|
|
116
|
+
export function assertTopicValue(value) {
|
|
117
|
+
let json;
|
|
118
|
+
try {
|
|
119
|
+
json = JSON.stringify(value);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new Error('Topic values must be plain JSON');
|
|
123
|
+
}
|
|
124
|
+
if (json === undefined)
|
|
125
|
+
throw new Error('Topic values must be plain JSON');
|
|
126
|
+
if (json.length > TOPIC_VALUE_MAX_CHARS)
|
|
127
|
+
throw new Error(`Topic value exceeds ${TOPIC_VALUE_MAX_CHARS} characters`);
|
|
128
|
+
}
|
|
@@ -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.canonicalizePath = exports.normalizePath = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.ManifestError = exports.isSectionSlot = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
|
|
3
|
+
exports.assertTopicValue = exports.redactBySchema = exports.projectFields = exports.canProvideTopic = exports.consumeGrant = exports.isFieldPath = exports.topicOwner = exports.isHostTopic = exports.isTopicName = exports.TOPIC_VALUE_MAX_CHARS = 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; } });
|
|
@@ -23,3 +23,14 @@ var storage_1 = require("./storage");
|
|
|
23
23
|
Object.defineProperty(exports, "PLUGIN_STORAGE_ORIGIN", { enumerable: true, get: function () { return storage_1.PLUGIN_STORAGE_ORIGIN; } });
|
|
24
24
|
Object.defineProperty(exports, "validateStorageUrl", { enumerable: true, get: function () { return storage_1.validateStorageUrl; } });
|
|
25
25
|
Object.defineProperty(exports, "resolveAssetUrl", { enumerable: true, get: function () { return storage_1.resolveAssetUrl; } });
|
|
26
|
+
var topics_1 = require("./topics");
|
|
27
|
+
Object.defineProperty(exports, "TOPIC_VALUE_MAX_CHARS", { enumerable: true, get: function () { return topics_1.TOPIC_VALUE_MAX_CHARS; } });
|
|
28
|
+
Object.defineProperty(exports, "isTopicName", { enumerable: true, get: function () { return topics_1.isTopicName; } });
|
|
29
|
+
Object.defineProperty(exports, "isHostTopic", { enumerable: true, get: function () { return topics_1.isHostTopic; } });
|
|
30
|
+
Object.defineProperty(exports, "topicOwner", { enumerable: true, get: function () { return topics_1.topicOwner; } });
|
|
31
|
+
Object.defineProperty(exports, "isFieldPath", { enumerable: true, get: function () { return topics_1.isFieldPath; } });
|
|
32
|
+
Object.defineProperty(exports, "consumeGrant", { enumerable: true, get: function () { return topics_1.consumeGrant; } });
|
|
33
|
+
Object.defineProperty(exports, "canProvideTopic", { enumerable: true, get: function () { return topics_1.canProvideTopic; } });
|
|
34
|
+
Object.defineProperty(exports, "projectFields", { enumerable: true, get: function () { return topics_1.projectFields; } });
|
|
35
|
+
Object.defineProperty(exports, "redactBySchema", { enumerable: true, get: function () { return topics_1.redactBySchema; } });
|
|
36
|
+
Object.defineProperty(exports, "assertTopicValue", { enumerable: true, get: function () { return topics_1.assertTopicValue; } });
|