@nullplatform/ui-plugin-sdk 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/bin/ui-plugin-sdk.mjs +49 -0
- package/cli/devServer.mjs +99 -0
- package/dist/catalog.js +0 -6
- package/dist/components.d.ts +0 -5
- package/dist/components.generated.d.ts +70 -0
- package/dist/components.generated.js +7 -1
- package/dist/components.js +0 -1
- package/dist/contract/allowlist.d.ts +2 -0
- package/dist/contract/allowlist.js +1 -1
- package/dist/contract/fixtures.d.ts +17 -0
- package/dist/contract/fixtures.js +27 -0
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +1 -0
- package/dist/contract-cjs/allowlist.js +1 -0
- package/dist/contract-cjs/fixtures.js +30 -0
- package/dist/contract-cjs/index.js +3 -1
- package/dist/contracts.generated.d.ts +101 -0
- package/dist/contracts.generated.js +43 -1
- package/package.json +16 -4
package/README.md
CHANGED
|
@@ -36,3 +36,35 @@ The SDK carries no API keys. Publish your plugin bundle through the UI API, pin
|
|
|
36
36
|
as a `ui_bundle` component of a central nullplatform Package, and install the exact
|
|
37
37
|
package revision on the desired NRN. Installing this npm SDK does not publish or
|
|
38
38
|
install a plugin in nullplatform.
|
|
39
|
+
|
|
40
|
+
## Local development
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install --save-dev vite @vitejs/plugin-react
|
|
44
|
+
npx ui-plugin-sdk dev --https
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`ui-plugin-sdk dev` rebuilds the plugin with your project's Vite on every change and
|
|
48
|
+
serves `manifest.json`, `dist/plugin.js` and `fixtures.json` on `localhost:4300`
|
|
49
|
+
(`--port` to change it). The nullplatform dashboard only loads `https://localhost`,
|
|
50
|
+
so serve with `--https` and a locally trusted certificate, by default
|
|
51
|
+
`.certs/localhost.pem` and `.certs/localhost-key.pem`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
mkcert -install
|
|
55
|
+
mkcert -cert-file .certs/localhost.pem -key-file .certs/localhost-key.pem localhost 127.0.0.1
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`fixtures.json` holds test answers for the plugin's API calls, keyed like the
|
|
59
|
+
manifest's `permissions.api`. A preview answers from it instead of the API, and a
|
|
60
|
+
call with no fixture fails as a 404:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"GET /application/{id}": { "id": 42, "name": "checkout-api" },
|
|
65
|
+
"GET /scope": { "results": [{ "id": 1, "name": "production" }] }
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The query string is not part of the key, and a key with more literal segments wins
|
|
70
|
+
(`/application/me` over `/application/{id}`).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { startDevServer } from '../cli/devServer.mjs';
|
|
5
|
+
|
|
6
|
+
const HELP = `Usage: ui-plugin-sdk dev [options]
|
|
7
|
+
|
|
8
|
+
Rebuilds your plugin on every change and serves manifest.json, dist/plugin.js and
|
|
9
|
+
fixtures.json on localhost, ready to load from the nullplatform dashboard.
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--port <n> port to serve on (default: $PORT or 4300)
|
|
13
|
+
--https serve over https; the deployed dashboard only loads https://localhost
|
|
14
|
+
--cert <file> certificate for --https (default: $DEV_TLS_CERT or .certs/localhost.pem)
|
|
15
|
+
--key <file> key for --https (default: $DEV_TLS_KEY or .certs/localhost-key.pem)
|
|
16
|
+
--root <dir> the plugin's folder (default: the current one)
|
|
17
|
+
-h, --help show this help
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const { values, positionals } = parseArgs({
|
|
21
|
+
allowPositionals: true,
|
|
22
|
+
options: {
|
|
23
|
+
port: { type: 'string' },
|
|
24
|
+
https: { type: 'boolean' },
|
|
25
|
+
cert: { type: 'string' },
|
|
26
|
+
key: { type: 'string' },
|
|
27
|
+
root: { type: 'string' },
|
|
28
|
+
help: { type: 'boolean', short: 'h' },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (values.help || positionals[0] !== 'dev') {
|
|
33
|
+
console.log(HELP);
|
|
34
|
+
process.exit(values.help ? 0 : 1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const port = Number(values.port ?? process.env.PORT ?? 4300);
|
|
38
|
+
if (!Number.isInteger(port) || port <= 0) {
|
|
39
|
+
console.error(`[plugin dev] invalid port: ${values.port ?? process.env.PORT}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
await startDevServer({
|
|
44
|
+
root: resolve(values.root ?? process.cwd()),
|
|
45
|
+
port,
|
|
46
|
+
https: values.https || ['1', 'true'].includes(String(process.env.HTTPS ?? '').toLowerCase()),
|
|
47
|
+
cert: values.cert,
|
|
48
|
+
key: values.key,
|
|
49
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ui-plugin-sdk dev`: rebuilds the plugin on every change (Vite, from the plugin's own project)
|
|
3
|
+
* and serves `manifest.json`, `dist/plugin.js` and `fixtures.json` on localhost, with the CORS,
|
|
4
|
+
* private-network and ETag headers a host needs to load and reload it.
|
|
5
|
+
*
|
|
6
|
+
* The deployed dashboard only reaches `https://localhost` (its CSP allows `https:` and scheme-less
|
|
7
|
+
* `localhost:*`, which inherits the page's https), so loading a plugin there needs `--https` and a
|
|
8
|
+
* locally trusted certificate, e.g. from mkcert.
|
|
9
|
+
*/
|
|
10
|
+
import { createServer as createHttpServer } from 'node:http';
|
|
11
|
+
import { createServer as createHttpsServer } from 'node:https';
|
|
12
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
13
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { dirname, join, resolve } from 'node:path';
|
|
16
|
+
import { pathToFileURL } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const FILES = {
|
|
19
|
+
'/manifest.json': { path: 'manifest.json', type: 'application/json' },
|
|
20
|
+
'/plugin.js': { path: 'dist/plugin.js', type: 'text/javascript' },
|
|
21
|
+
'/fixtures.json': { path: 'fixtures.json', type: 'application/json', optional: true },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** The request handler, on its own so it can be tested without a build. */
|
|
25
|
+
export function createDevHandler({ root }) {
|
|
26
|
+
return async (req, res) => {
|
|
27
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
28
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
29
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
30
|
+
res.setHeader('Access-Control-Expose-Headers', 'ETag');
|
|
31
|
+
// Chrome asks before a public page (the deployed dashboard) reaches localhost.
|
|
32
|
+
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
|
33
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
34
|
+
if (req.method === 'OPTIONS') return res.writeHead(204).end();
|
|
35
|
+
const file = FILES[url.pathname];
|
|
36
|
+
if (!file) return res.writeHead(404).end('not found');
|
|
37
|
+
const path = resolve(root, file.path);
|
|
38
|
+
const info = await stat(path).catch(() => null);
|
|
39
|
+
// A plugin without fixtures has none; a missing bundle is one Vite has not finished yet.
|
|
40
|
+
if (!info) return file.optional ? res.writeHead(404).end('no fixtures') : res.writeHead(503).end('not built yet');
|
|
41
|
+
const etag = `"${info.mtimeMs}"`;
|
|
42
|
+
res.setHeader('ETag', etag);
|
|
43
|
+
res.setHeader('Content-Type', file.type);
|
|
44
|
+
if (req.method === 'HEAD') return res.writeHead(200).end();
|
|
45
|
+
if (req.headers['if-none-match'] === etag) return res.writeHead(304).end();
|
|
46
|
+
res.writeHead(200).end(await readFile(path));
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `--cert`/`--key`, then DEV_TLS_CERT/DEV_TLS_KEY, then `.certs/` in the plugin or any folder above it. */
|
|
51
|
+
export function findCertificate({ root, cert, key }) {
|
|
52
|
+
if (cert || key) return { cert, key };
|
|
53
|
+
if (process.env.DEV_TLS_CERT || process.env.DEV_TLS_KEY) return { cert: process.env.DEV_TLS_CERT, key: process.env.DEV_TLS_KEY };
|
|
54
|
+
for (let dir = resolve(root); ; dir = dirname(dir)) {
|
|
55
|
+
const candidate = { cert: join(dir, '.certs/localhost.pem'), key: join(dir, '.certs/localhost-key.pem') };
|
|
56
|
+
if (existsSync(candidate.cert) && existsSync(candidate.key)) return candidate;
|
|
57
|
+
if (dirname(dir) === dir) return { cert: join(resolve(root), '.certs/localhost.pem'), key: join(resolve(root), '.certs/localhost-key.pem') };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The plugin's own Vite: the SDK ships inside every plugin bundle, so it never depends on a build tool. */
|
|
62
|
+
export async function loadVite(root) {
|
|
63
|
+
const require = createRequire(join(resolve(root), 'package.json'));
|
|
64
|
+
let manifestPath;
|
|
65
|
+
try {
|
|
66
|
+
manifestPath = require.resolve('vite/package.json');
|
|
67
|
+
} catch {
|
|
68
|
+
throw new Error('ui-plugin-sdk dev builds your plugin with Vite. Add it to the plugin: npm install --save-dev vite');
|
|
69
|
+
}
|
|
70
|
+
const { exports } = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
71
|
+
// Vite 7 exports `.` as a plain path; 5 and 6 nest it under `import`.
|
|
72
|
+
const main = exports?.['.'];
|
|
73
|
+
const entry = typeof main === 'string' ? main : (main?.import?.default ?? main?.import ?? main?.default);
|
|
74
|
+
if (typeof entry !== 'string') throw new Error(`Can't find Vite's ESM entry in ${manifestPath}`);
|
|
75
|
+
return import(pathToFileURL(join(dirname(manifestPath), entry)).href);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function startDevServer({ root, port, https, cert, key }) {
|
|
79
|
+
let tls;
|
|
80
|
+
if (https) {
|
|
81
|
+
const paths = findCertificate({ root, cert, key });
|
|
82
|
+
if (!paths.cert || !paths.key || !existsSync(paths.cert) || !existsSync(paths.key)) {
|
|
83
|
+
console.error(`[plugin dev] --https needs a trusted localhost certificate (looked for ${paths.cert} and ${paths.key}).`);
|
|
84
|
+
console.error('[plugin dev] mkcert -install');
|
|
85
|
+
console.error(`[plugin dev] mkcert -cert-file ${paths.cert} -key-file ${paths.key} localhost 127.0.0.1`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
tls = { cert: readFileSync(paths.cert), key: readFileSync(paths.key) };
|
|
89
|
+
}
|
|
90
|
+
const { build } = await loadVite(root);
|
|
91
|
+
const handler = createDevHandler({ root });
|
|
92
|
+
const server = tls ? createHttpsServer(tls, handler) : createHttpServer(handler);
|
|
93
|
+
const origin = `${tls ? 'https' : 'http'}://localhost:${port}`;
|
|
94
|
+
server.listen(port, () => {
|
|
95
|
+
console.log(`[plugin dev] serving manifest.json, plugin.js and fixtures.json on ${origin}`);
|
|
96
|
+
if (!tls) console.log('[plugin dev] the deployed dashboard only loads https://localhost: run with --https');
|
|
97
|
+
});
|
|
98
|
+
await build({ root, build: { watch: {} }, logLevel: 'info' });
|
|
99
|
+
}
|
package/dist/catalog.js
CHANGED
package/dist/components.d.ts
CHANGED
|
@@ -179,11 +179,6 @@ export declare const Icon: import("react").ComponentType<{
|
|
|
179
179
|
export declare const Divider: import("react").ComponentType<{
|
|
180
180
|
children?: ReactNode;
|
|
181
181
|
}>;
|
|
182
|
-
export declare const Markdown: import("react").ComponentType<{
|
|
183
|
-
content: string;
|
|
184
|
-
} & {
|
|
185
|
-
children?: ReactNode;
|
|
186
|
-
}>;
|
|
187
182
|
export declare const Code: import("react").ComponentType<{
|
|
188
183
|
content: string;
|
|
189
184
|
language?: string;
|
|
@@ -362,3 +362,73 @@ export declare const DataTable: import("react").ComponentType<Omit<{
|
|
|
362
362
|
}, "data" | "onChangeTableState" | "onRowClick" | "columns" | "initialState" | "paginationProps"> & {
|
|
363
363
|
children?: import("react").ReactNode;
|
|
364
364
|
}>;
|
|
365
|
+
export declare const Gauge: import("react").ComponentType<{
|
|
366
|
+
value?: number | undefined;
|
|
367
|
+
min?: number | undefined;
|
|
368
|
+
max?: number | undefined;
|
|
369
|
+
segments?: readonly unknown[] | undefined;
|
|
370
|
+
width?: number | undefined;
|
|
371
|
+
pointer?: Readonly<Record<string, unknown>> | undefined;
|
|
372
|
+
label?: Readonly<Record<string, unknown>> | undefined;
|
|
373
|
+
} & {} & {} & {
|
|
374
|
+
children?: import("react").ReactNode;
|
|
375
|
+
}>;
|
|
376
|
+
export declare const Pagination: import("react").ComponentType<{
|
|
377
|
+
count?: number | undefined;
|
|
378
|
+
page?: number | undefined;
|
|
379
|
+
defaultPage?: number | undefined;
|
|
380
|
+
siblingCount?: number | undefined;
|
|
381
|
+
boundaryCount?: number | undefined;
|
|
382
|
+
shape?: "circular" | "rounded" | undefined;
|
|
383
|
+
size?: "small" | "medium" | "large" | undefined;
|
|
384
|
+
variant?: "outlined" | "text" | undefined;
|
|
385
|
+
color?: "primary" | "secondary" | "standard" | undefined;
|
|
386
|
+
disabled?: boolean | undefined;
|
|
387
|
+
hidePrevButton?: boolean | undefined;
|
|
388
|
+
hideNextButton?: boolean | undefined;
|
|
389
|
+
showFirstButton?: boolean | undefined;
|
|
390
|
+
showLastButton?: boolean | undefined;
|
|
391
|
+
} & {
|
|
392
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
393
|
+
} & {} & {
|
|
394
|
+
children?: import("react").ReactNode;
|
|
395
|
+
}>;
|
|
396
|
+
export declare const RadioCard: import("react").ComponentType<{
|
|
397
|
+
options?: readonly unknown[] | undefined;
|
|
398
|
+
value?: string | undefined;
|
|
399
|
+
defaultValue?: string | undefined;
|
|
400
|
+
name?: string | undefined;
|
|
401
|
+
row?: boolean | undefined;
|
|
402
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
403
|
+
variant?: "outline" | "surface" | "subtle" | "solid" | undefined;
|
|
404
|
+
align?: "center" | "start" | "end" | undefined;
|
|
405
|
+
justify?: "center" | "start" | "end" | undefined;
|
|
406
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
407
|
+
indicator?: boolean | undefined;
|
|
408
|
+
disabled?: boolean | undefined;
|
|
409
|
+
readOnly?: boolean | undefined;
|
|
410
|
+
error?: boolean | undefined;
|
|
411
|
+
} & {
|
|
412
|
+
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
413
|
+
} & {} & {
|
|
414
|
+
children?: import("react").ReactNode;
|
|
415
|
+
}>;
|
|
416
|
+
export declare const CodeHighlighter: import("react").ComponentType<{
|
|
417
|
+
code?: string | undefined;
|
|
418
|
+
lang?: "bash" | "hcl" | "json" | "sql" | "yaml" | undefined;
|
|
419
|
+
} & {} & {} & {
|
|
420
|
+
children?: import("react").ReactNode;
|
|
421
|
+
}>;
|
|
422
|
+
export declare const PageEmptyState: import("react").ComponentType<{
|
|
423
|
+
title?: string | undefined;
|
|
424
|
+
description?: string | undefined;
|
|
425
|
+
} & {} & {
|
|
426
|
+
action?: import("react").ReactNode;
|
|
427
|
+
} & {
|
|
428
|
+
children?: import("react").ReactNode;
|
|
429
|
+
}>;
|
|
430
|
+
export declare const Markdown: import("react").ComponentType<{
|
|
431
|
+
content?: string | undefined;
|
|
432
|
+
} & {} & {} & {
|
|
433
|
+
children?: import("react").ReactNode;
|
|
434
|
+
}>;
|
|
@@ -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.14. 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");
|
|
@@ -40,3 +40,9 @@ export const ChipList = component("np-chip-list");
|
|
|
40
40
|
export const ActivityTimeline = component("np-activity-timeline");
|
|
41
41
|
export const ListItemButton = component("np-list-item-button");
|
|
42
42
|
export const DataTable = component("np-data-table");
|
|
43
|
+
export const Gauge = component("np-gauge");
|
|
44
|
+
export const Pagination = component("np-pagination");
|
|
45
|
+
export const RadioCard = component("np-radio-card");
|
|
46
|
+
export const CodeHighlighter = component("np-code-highlighter");
|
|
47
|
+
export const PageEmptyState = component("np-page-empty-state");
|
|
48
|
+
export const Markdown = component("np-markdown");
|
package/dist/components.js
CHANGED
|
@@ -19,7 +19,6 @@ export const Empty = component("np-empty");
|
|
|
19
19
|
export const Alert = component("np-alert");
|
|
20
20
|
export const Icon = component("np-icon");
|
|
21
21
|
export const Divider = component("np-divider");
|
|
22
|
-
export const Markdown = component("np-markdown");
|
|
23
22
|
export const Code = component("np-code");
|
|
24
23
|
/**
|
|
25
24
|
* Ego graph: the focus node in the center, what consumes it on the left, what it depends on on the right.
|
|
@@ -7,6 +7,8 @@ export declare function normalizePath(path: string): string[] | null;
|
|
|
7
7
|
* that nothing downstream can resolve a path other than the authorized one.
|
|
8
8
|
*/
|
|
9
9
|
export declare function canonicalizePath(path: string): string | null;
|
|
10
|
+
/** `{param}` placeholders match exactly one non-empty segment. */
|
|
11
|
+
export declare function pathMatches(pattern: string, requestSegments: string[]): boolean;
|
|
10
12
|
/**
|
|
11
13
|
* Decides whether a plugin API request (a nullplatform public API path) is covered
|
|
12
14
|
* by its declared `permissions.api`. Query strings are never part of the decision.
|
|
@@ -31,7 +31,7 @@ export function canonicalizePath(path) {
|
|
|
31
31
|
return segments ? '/' + segments.map(encodeURIComponent).join('/') : null;
|
|
32
32
|
}
|
|
33
33
|
/** `{param}` placeholders match exactly one non-empty segment. */
|
|
34
|
-
function pathMatches(pattern, requestSegments) {
|
|
34
|
+
export function pathMatches(pattern, requestSegments) {
|
|
35
35
|
const patternSegments = normalizePath(pattern);
|
|
36
36
|
if (!patternSegments || patternSegments.length !== requestSegments.length)
|
|
37
37
|
return false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin's local test data: response bodies keyed by `"METHOD /path"`, in the manifest's own
|
|
3
|
+
* permission syntax, so `"GET /application/{id}"` answers any application id. The query string is
|
|
4
|
+
* never part of the key; a list response carries its own paging.
|
|
5
|
+
*/
|
|
6
|
+
export type Fixtures = Record<string, unknown>;
|
|
7
|
+
export interface FixtureMatch {
|
|
8
|
+
/** The key that answered, as written in the fixtures. */
|
|
9
|
+
key: string;
|
|
10
|
+
body: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The fixture that answers a plugin API request, or null. A key with more literal segments beats
|
|
14
|
+
* one with more placeholders (`/application/me` over `/application/{id}`); between equals, the
|
|
15
|
+
* first one written wins. Keys that are not `METHOD /path` never match.
|
|
16
|
+
*/
|
|
17
|
+
export declare function matchFixture(fixtures: Fixtures, method: string, path: string): FixtureMatch | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { normalizePath, pathMatches } from './allowlist.js';
|
|
2
|
+
const KEY = /^([A-Z]+|\*) (\/\S*)$/;
|
|
3
|
+
const literalSegments = (segments) => segments.filter((segment) => !(segment.startsWith('{') && segment.endsWith('}'))).length;
|
|
4
|
+
/**
|
|
5
|
+
* The fixture that answers a plugin API request, or null. A key with more literal segments beats
|
|
6
|
+
* one with more placeholders (`/application/me` over `/application/{id}`); between equals, the
|
|
7
|
+
* first one written wins. Keys that are not `METHOD /path` never match.
|
|
8
|
+
*/
|
|
9
|
+
export function matchFixture(fixtures, method, path) {
|
|
10
|
+
const requestSegments = normalizePath(path);
|
|
11
|
+
if (!requestSegments || !fixtures || typeof fixtures !== 'object')
|
|
12
|
+
return null;
|
|
13
|
+
const requestMethod = method.toUpperCase();
|
|
14
|
+
let best = null;
|
|
15
|
+
for (const key of Object.keys(fixtures)) {
|
|
16
|
+
const parsed = KEY.exec(key);
|
|
17
|
+
if (!parsed || (parsed[1] !== '*' && parsed[1] !== requestMethod))
|
|
18
|
+
continue;
|
|
19
|
+
const patternSegments = normalizePath(parsed[2]);
|
|
20
|
+
if (!patternSegments || !pathMatches(parsed[2], requestSegments))
|
|
21
|
+
continue;
|
|
22
|
+
const literals = literalSegments(patternSegments);
|
|
23
|
+
if (!best || literals > best.literals)
|
|
24
|
+
best = { key, literals };
|
|
25
|
+
}
|
|
26
|
+
return best ? { key: best.key, body: fixtures[best.key] } : null;
|
|
27
|
+
}
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
|
|
2
2
|
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
3
|
+
export { matchFixture, type Fixtures, type FixtureMatch } from './fixtures.js';
|
|
3
4
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, type WhenQuery, type ContextRoot, type Rollout, } from './when.js';
|
|
4
5
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
|
5
6
|
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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, } from './manifest.js';
|
|
2
2
|
export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
3
|
+
export { matchFixture } from './fixtures.js';
|
|
3
4
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, } from './when.js';
|
|
4
5
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
|
5
6
|
export { TOPIC_VALUE_MAX_CHARS, isTopicName, isHostTopic, topicOwner, isFieldPath, consumeGrant, canProvideTopic, projectFields, redactBySchema, assertTopicValue, } from './topics.js';
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isRequestAllowed = void 0;
|
|
4
4
|
exports.normalizePath = normalizePath;
|
|
5
5
|
exports.canonicalizePath = canonicalizePath;
|
|
6
|
+
exports.pathMatches = pathMatches;
|
|
6
7
|
exports.isApiRequestAllowed = isApiRequestAllowed;
|
|
7
8
|
exports.isHttpRequestAllowed = isHttpRequestAllowed;
|
|
8
9
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchFixture = matchFixture;
|
|
4
|
+
const allowlist_1 = require("./allowlist");
|
|
5
|
+
const KEY = /^([A-Z]+|\*) (\/\S*)$/;
|
|
6
|
+
const literalSegments = (segments) => segments.filter((segment) => !(segment.startsWith('{') && segment.endsWith('}'))).length;
|
|
7
|
+
/**
|
|
8
|
+
* The fixture that answers a plugin API request, or null. A key with more literal segments beats
|
|
9
|
+
* one with more placeholders (`/application/me` over `/application/{id}`); between equals, the
|
|
10
|
+
* first one written wins. Keys that are not `METHOD /path` never match.
|
|
11
|
+
*/
|
|
12
|
+
function matchFixture(fixtures, method, path) {
|
|
13
|
+
const requestSegments = (0, allowlist_1.normalizePath)(path);
|
|
14
|
+
if (!requestSegments || !fixtures || typeof fixtures !== 'object')
|
|
15
|
+
return null;
|
|
16
|
+
const requestMethod = method.toUpperCase();
|
|
17
|
+
let best = null;
|
|
18
|
+
for (const key of Object.keys(fixtures)) {
|
|
19
|
+
const parsed = KEY.exec(key);
|
|
20
|
+
if (!parsed || (parsed[1] !== '*' && parsed[1] !== requestMethod))
|
|
21
|
+
continue;
|
|
22
|
+
const patternSegments = (0, allowlist_1.normalizePath)(parsed[2]);
|
|
23
|
+
if (!patternSegments || !(0, allowlist_1.pathMatches)(parsed[2], requestSegments))
|
|
24
|
+
continue;
|
|
25
|
+
const literals = literalSegments(patternSegments);
|
|
26
|
+
if (!best || literals > best.literals)
|
|
27
|
+
best = { key, literals };
|
|
28
|
+
}
|
|
29
|
+
return best ? { key: best.key, body: fixtures[best.key] } : null;
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
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.matchFixture = 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; } });
|
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "isHttpRequestAllowed", { enumerable: true, get:
|
|
|
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
14
|
Object.defineProperty(exports, "canonicalizePath", { enumerable: true, get: function () { return allowlist_1.canonicalizePath; } });
|
|
15
|
+
var fixtures_1 = require("./fixtures");
|
|
16
|
+
Object.defineProperty(exports, "matchFixture", { enumerable: true, get: function () { return fixtures_1.matchFixture; } });
|
|
15
17
|
var when_1 = require("./when");
|
|
16
18
|
Object.defineProperty(exports, "CONTEXT_ROOTS", { enumerable: true, get: function () { return when_1.CONTEXT_ROOTS; } });
|
|
17
19
|
Object.defineProperty(exports, "extractRoots", { enumerable: true, get: function () { return when_1.extractRoots; } });
|
|
@@ -508,4 +508,105 @@ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
|
|
|
508
508
|
readonly values: {
|
|
509
509
|
readonly variant: readonly ["default", "embedded"];
|
|
510
510
|
};
|
|
511
|
+
}, {
|
|
512
|
+
readonly tag: "np-gauge";
|
|
513
|
+
readonly component: "Gauge";
|
|
514
|
+
readonly properties: {
|
|
515
|
+
readonly value: "number";
|
|
516
|
+
readonly min: "number";
|
|
517
|
+
readonly max: "number";
|
|
518
|
+
readonly segments: "array";
|
|
519
|
+
readonly width: "number";
|
|
520
|
+
readonly pointer: "object";
|
|
521
|
+
readonly label: "object";
|
|
522
|
+
};
|
|
523
|
+
readonly events: {};
|
|
524
|
+
readonly cssValues: readonly ["segments[].color"];
|
|
525
|
+
}, {
|
|
526
|
+
readonly tag: "np-pagination";
|
|
527
|
+
readonly component: "Pagination";
|
|
528
|
+
readonly properties: {
|
|
529
|
+
readonly count: "number";
|
|
530
|
+
readonly page: "number";
|
|
531
|
+
readonly defaultPage: "number";
|
|
532
|
+
readonly siblingCount: "number";
|
|
533
|
+
readonly boundaryCount: "number";
|
|
534
|
+
readonly shape: "string";
|
|
535
|
+
readonly size: "string";
|
|
536
|
+
readonly variant: "string";
|
|
537
|
+
readonly color: "string";
|
|
538
|
+
readonly disabled: "boolean";
|
|
539
|
+
readonly hidePrevButton: "boolean";
|
|
540
|
+
readonly hideNextButton: "boolean";
|
|
541
|
+
readonly showFirstButton: "boolean";
|
|
542
|
+
readonly showLastButton: "boolean";
|
|
543
|
+
};
|
|
544
|
+
readonly events: {
|
|
545
|
+
readonly change: "onChange";
|
|
546
|
+
};
|
|
547
|
+
readonly values: {
|
|
548
|
+
readonly shape: readonly ["circular", "rounded"];
|
|
549
|
+
readonly size: readonly ["small", "medium", "large"];
|
|
550
|
+
readonly variant: readonly ["text", "outlined"];
|
|
551
|
+
readonly color: readonly ["primary", "secondary", "standard"];
|
|
552
|
+
};
|
|
553
|
+
}, {
|
|
554
|
+
readonly tag: "np-radio-card";
|
|
555
|
+
readonly component: "RadioCard";
|
|
556
|
+
readonly properties: {
|
|
557
|
+
readonly options: "array";
|
|
558
|
+
readonly value: "string";
|
|
559
|
+
readonly defaultValue: "string";
|
|
560
|
+
readonly name: "string";
|
|
561
|
+
readonly row: "boolean";
|
|
562
|
+
readonly size: "string";
|
|
563
|
+
readonly variant: "string";
|
|
564
|
+
readonly align: "string";
|
|
565
|
+
readonly justify: "string";
|
|
566
|
+
readonly orientation: "string";
|
|
567
|
+
readonly indicator: "boolean";
|
|
568
|
+
readonly disabled: "boolean";
|
|
569
|
+
readonly readOnly: "boolean";
|
|
570
|
+
readonly error: "boolean";
|
|
571
|
+
};
|
|
572
|
+
readonly events: {
|
|
573
|
+
readonly change: "onChange";
|
|
574
|
+
};
|
|
575
|
+
readonly values: {
|
|
576
|
+
readonly size: readonly ["sm", "md", "lg"];
|
|
577
|
+
readonly variant: readonly ["outline", "surface", "subtle", "solid"];
|
|
578
|
+
readonly align: readonly ["start", "end", "center"];
|
|
579
|
+
readonly justify: readonly ["start", "end", "center"];
|
|
580
|
+
readonly orientation: readonly ["horizontal", "vertical"];
|
|
581
|
+
};
|
|
582
|
+
}, {
|
|
583
|
+
readonly tag: "np-code-highlighter";
|
|
584
|
+
readonly component: "CodeHighlighter";
|
|
585
|
+
readonly properties: {
|
|
586
|
+
readonly code: "string";
|
|
587
|
+
readonly lang: "string";
|
|
588
|
+
};
|
|
589
|
+
readonly events: {};
|
|
590
|
+
readonly values: {
|
|
591
|
+
readonly lang: readonly ["bash", "hcl", "json", "sql", "yaml"];
|
|
592
|
+
};
|
|
593
|
+
}, {
|
|
594
|
+
readonly tag: "np-page-empty-state";
|
|
595
|
+
readonly component: "PageEmptyState";
|
|
596
|
+
readonly properties: {
|
|
597
|
+
readonly title: "string";
|
|
598
|
+
readonly description: "string";
|
|
599
|
+
};
|
|
600
|
+
readonly events: {};
|
|
601
|
+
readonly slots: readonly ["action"];
|
|
602
|
+
}, {
|
|
603
|
+
readonly tag: "np-markdown";
|
|
604
|
+
readonly component: "Markdown";
|
|
605
|
+
readonly properties: {
|
|
606
|
+
readonly content: "string";
|
|
607
|
+
};
|
|
608
|
+
readonly events: {};
|
|
609
|
+
readonly defaults: {
|
|
610
|
+
readonly content: "";
|
|
611
|
+
};
|
|
511
612
|
}];
|
|
@@ -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.14. Don't edit: change the contract in
|
|
2
2
|
// react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
|
|
3
3
|
export const UI_COMPONENTS_CONTRACTS = [
|
|
4
4
|
{
|
|
@@ -280,4 +280,46 @@ export const UI_COMPONENTS_CONTRACTS = [
|
|
|
280
280
|
events: { "stateChange": "onChangeTableState", "rowClick": "onRowClick" },
|
|
281
281
|
values: { "variant": ["default", "embedded"] },
|
|
282
282
|
},
|
|
283
|
+
{
|
|
284
|
+
tag: "np-gauge",
|
|
285
|
+
component: "Gauge",
|
|
286
|
+
properties: { "value": "number", "min": "number", "max": "number", "segments": "array", "width": "number", "pointer": "object", "label": "object" },
|
|
287
|
+
events: {},
|
|
288
|
+
cssValues: ["segments[].color"],
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
tag: "np-pagination",
|
|
292
|
+
component: "Pagination",
|
|
293
|
+
properties: { "count": "number", "page": "number", "defaultPage": "number", "siblingCount": "number", "boundaryCount": "number", "shape": "string", "size": "string", "variant": "string", "color": "string", "disabled": "boolean", "hidePrevButton": "boolean", "hideNextButton": "boolean", "showFirstButton": "boolean", "showLastButton": "boolean" },
|
|
294
|
+
events: { "change": "onChange" },
|
|
295
|
+
values: { "shape": ["circular", "rounded"], "size": ["small", "medium", "large"], "variant": ["text", "outlined"], "color": ["primary", "secondary", "standard"] },
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
tag: "np-radio-card",
|
|
299
|
+
component: "RadioCard",
|
|
300
|
+
properties: { "options": "array", "value": "string", "defaultValue": "string", "name": "string", "row": "boolean", "size": "string", "variant": "string", "align": "string", "justify": "string", "orientation": "string", "indicator": "boolean", "disabled": "boolean", "readOnly": "boolean", "error": "boolean" },
|
|
301
|
+
events: { "change": "onChange" },
|
|
302
|
+
values: { "size": ["sm", "md", "lg"], "variant": ["outline", "surface", "subtle", "solid"], "align": ["start", "end", "center"], "justify": ["start", "end", "center"], "orientation": ["horizontal", "vertical"] },
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
tag: "np-code-highlighter",
|
|
306
|
+
component: "CodeHighlighter",
|
|
307
|
+
properties: { "code": "string", "lang": "string" },
|
|
308
|
+
events: {},
|
|
309
|
+
values: { "lang": ["bash", "hcl", "json", "sql", "yaml"] },
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
tag: "np-page-empty-state",
|
|
313
|
+
component: "PageEmptyState",
|
|
314
|
+
properties: { "title": "string", "description": "string" },
|
|
315
|
+
events: {},
|
|
316
|
+
slots: ["action"],
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
tag: "np-markdown",
|
|
320
|
+
component: "Markdown",
|
|
321
|
+
properties: { "content": "string" },
|
|
322
|
+
events: {},
|
|
323
|
+
defaults: { "content": "" },
|
|
324
|
+
},
|
|
283
325
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullplatform/ui-plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "SDK for nullplatform UI plugins: catalog components, bridge client and defineUI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,8 +27,14 @@
|
|
|
27
27
|
"require": "./dist/contract-cjs/index.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"ui-plugin-sdk": "./bin/ui-plugin-sdk.mjs"
|
|
32
|
+
},
|
|
30
33
|
"files": [
|
|
31
|
-
"dist"
|
|
34
|
+
"dist",
|
|
35
|
+
"bin",
|
|
36
|
+
"cli",
|
|
37
|
+
"!cli/*.test.mjs"
|
|
32
38
|
],
|
|
33
39
|
"scripts": {
|
|
34
40
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.contract.cjs.json && node scripts/finish-build.mjs && node scripts/check-node-imports.mjs",
|
|
@@ -36,7 +42,7 @@
|
|
|
36
42
|
"test": "vitest run --passWithNoTests",
|
|
37
43
|
"sync:contracts": "node scripts/sync-contracts.mjs"
|
|
38
44
|
},
|
|
39
|
-
"uiComponentsContracts": "0.15.
|
|
45
|
+
"uiComponentsContracts": "0.15.14",
|
|
40
46
|
"dependencies": {
|
|
41
47
|
"@remote-dom/core": "^1.11.1",
|
|
42
48
|
"@remote-dom/react": "^1.2.2",
|
|
@@ -44,7 +50,13 @@
|
|
|
44
50
|
},
|
|
45
51
|
"peerDependencies": {
|
|
46
52
|
"react": "^18.2.0",
|
|
47
|
-
"react-dom": "^18.2.0"
|
|
53
|
+
"react-dom": "^18.2.0",
|
|
54
|
+
"vite": ">=5"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"vite": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
48
60
|
},
|
|
49
61
|
"devDependencies": {
|
|
50
62
|
"react": "18.2.0",
|