@nullplatform/ui-plugin-sdk 0.19.1 → 0.20.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/catalog.js +2 -0
- package/dist/components.d.ts +15 -1
- package/dist/components.generated.d.ts +7 -2
- package/dist/contractProps.d.ts +8 -0
- package/dist/filterSingleDate.d.ts +21 -0
- package/dist/filterSingleDate.js +5 -0
- package/package.json +1 -1
- package/dist/contract/documents.d.ts +0 -71
- package/dist/contract/documents.js +0 -237
- package/dist/contract-cjs/documents.js +0 -244
package/dist/catalog.js
CHANGED
package/dist/components.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type { AlertSeverity, ButtonColor, ButtonSize, ButtonVariant, CardTone, C
|
|
|
9
9
|
export * from "./components.generated.js";
|
|
10
10
|
export type { ContractProps, UiComponentsTag } from "./contractProps.js";
|
|
11
11
|
export type { CalendarEvent, CalendarEventKind, CalendarEventState, CalendarSlot, CalendarTimelineBar, CalendarTimelineRow, CalendarTimelineRowKind, } from "./calendar.js";
|
|
12
|
+
export type { FilterSingleDateChange, FilterSingleDatePreset } from "./filterSingleDate.js";
|
|
12
13
|
export type { DataTableAvatar, DataTableColor, DataTableColumn, DataTableFormatter, DataTableLabelVariant, DataTableLink, DataTablePagination, DataTableRow, DataTableRowAction, DataTableState, DataTableTypography, } from "./dataTable.js";
|
|
13
14
|
export declare const TextField: import("react").ComponentType<{
|
|
14
15
|
label: string;
|
|
@@ -349,12 +350,21 @@ export interface ScatterPoint {
|
|
|
349
350
|
label: string;
|
|
350
351
|
x: number;
|
|
351
352
|
y: number;
|
|
353
|
+
/** Text for this point's x value in its tooltip; the axis formatter when left out. */
|
|
354
|
+
xLabel?: string;
|
|
355
|
+
/** Text for this point's y value in its tooltip; the axis formatter when left out. */
|
|
356
|
+
yLabel?: string;
|
|
352
357
|
/** Relative area: the largest point gets the largest dot. Every dot is the same size when left out. */
|
|
353
358
|
size?: number;
|
|
354
359
|
color?: ThemeColor | string;
|
|
355
360
|
/** Outline with a faint fill, for points that matter less. */
|
|
356
361
|
hollow?: boolean;
|
|
357
362
|
}
|
|
363
|
+
/** A numeric position with the text the axis and tooltip should show for it. */
|
|
364
|
+
export interface ScatterAxisTick {
|
|
365
|
+
value: number;
|
|
366
|
+
label: string;
|
|
367
|
+
}
|
|
358
368
|
/**
|
|
359
369
|
* Splits the plane at `x` and `y`. `labels` names the corners and `colors` tints them, both in reading order
|
|
360
370
|
* (top left, top right, bottom left, bottom right); `null` leaves a corner untinted.
|
|
@@ -381,7 +391,11 @@ export declare const Scatter: import("react").ComponentType<{
|
|
|
381
391
|
xScale?: ScatterScale;
|
|
382
392
|
xFormat?: ValueFormat;
|
|
383
393
|
yFormat?: ValueFormat;
|
|
384
|
-
/**
|
|
394
|
+
/** Replaces generated numeric ticks and formats matching tooltip values. Useful for elapsed-time landmarks. */
|
|
395
|
+
xTicks?: ScatterAxisTick[];
|
|
396
|
+
/** Replaces generated numeric ticks and formats matching tooltip values. Useful for ordered categories. */
|
|
397
|
+
yTicks?: ScatterAxisTick[];
|
|
398
|
+
/** Axis maxima; custom ticks may extend either end. Otherwise, log x starts at the data minimum and linear axes at 0. */
|
|
385
399
|
xMax?: number;
|
|
386
400
|
yMax?: number;
|
|
387
401
|
/** The `id` of the point drawn as chosen. */
|
|
@@ -633,7 +633,7 @@ export declare const DatePickerField: import("react").ComponentType<{
|
|
|
633
633
|
} & {} & {
|
|
634
634
|
children?: import("react").ReactNode;
|
|
635
635
|
}>;
|
|
636
|
-
export declare const FilterSingleDateField: import("react").ComponentType<{
|
|
636
|
+
export declare const FilterSingleDateField: import("react").ComponentType<Omit<{
|
|
637
637
|
value?: string | undefined;
|
|
638
638
|
preset?: string | undefined;
|
|
639
639
|
presets?: readonly unknown[] | undefined;
|
|
@@ -652,7 +652,12 @@ export declare const FilterSingleDateField: import("react").ComponentType<{
|
|
|
652
652
|
hideActionButtons?: boolean | undefined;
|
|
653
653
|
} & {
|
|
654
654
|
readonly onChange?: ((payload: unknown) => void) | undefined;
|
|
655
|
-
} & {} & {
|
|
655
|
+
} & {}, "onChange" | "value" | "preset" | "presets"> & Pick<{
|
|
656
|
+
value?: string | null;
|
|
657
|
+
preset?: string | null;
|
|
658
|
+
presets?: readonly import("./filterSingleDate").FilterSingleDatePreset[];
|
|
659
|
+
onChange?: (change: import("./filterSingleDate").FilterSingleDateChange) => void;
|
|
660
|
+
}, "onChange" | "value" | "preset" | "presets"> & {
|
|
656
661
|
children?: import("react").ReactNode;
|
|
657
662
|
}>;
|
|
658
663
|
export declare const Stepper: import("react").ComponentType<{
|
package/dist/contractProps.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
import type { UI_COMPONENTS_CONTRACTS } from "./contracts.generated.js";
|
|
3
3
|
import type { CalendarEvent, CalendarSlot, CalendarTimelineBar, CalendarTimelineRow } from "./calendar.js";
|
|
4
4
|
import type { DataTableColumn, DataTablePagination, DataTableRow, DataTableState } from "./dataTable.js";
|
|
5
|
+
import type { FilterSingleDateChange, FilterSingleDatePreset } from "./filterSingleDate.js";
|
|
5
6
|
type Contract = (typeof UI_COMPONENTS_CONTRACTS)[number];
|
|
6
7
|
/** The elements the SDK takes from @nullplatform/react-ui-components' contracts. */
|
|
7
8
|
export type UiComponentsTag = Contract["tag"];
|
|
@@ -50,6 +51,13 @@ interface ContractPropTypes {
|
|
|
50
51
|
};
|
|
51
52
|
onBarPress?: (id: string) => void;
|
|
52
53
|
};
|
|
54
|
+
"np-filter-single-date": {
|
|
55
|
+
/** `null` as on `onChange`, so a controlled field takes its change back: the host drops it like a missing value. */
|
|
56
|
+
value?: string | null;
|
|
57
|
+
preset?: string | null;
|
|
58
|
+
presets?: readonly FilterSingleDatePreset[];
|
|
59
|
+
onChange?: (change: FilterSingleDateChange) => void;
|
|
60
|
+
};
|
|
53
61
|
}
|
|
54
62
|
type Typed<Tag, Props> = Tag extends keyof ContractPropTypes ? Omit<Props, keyof ContractPropTypes[Tag]> & Pick<ContractPropTypes[Tag], Extract<keyof ContractPropTypes[Tag], keyof Props>> : Props;
|
|
55
63
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `FilterSingleDateField` takes from a plugin and passes back, which its contract can only type as an array and
|
|
3
|
+
* an event. Instants are ISO-8601 strings.
|
|
4
|
+
*/
|
|
5
|
+
/** A choice listed above the calendar, resolved by the plugin when it renders ("in 7 days"). */
|
|
6
|
+
export interface FilterSingleDatePreset {
|
|
7
|
+
/** Any key but `custom`, which names the field's own calendar entry. */
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
/** The preset's instant; `null` or left out for a preset that stands for no date ("No expiration"). */
|
|
11
|
+
value?: string | null;
|
|
12
|
+
/** Listed but not selectable. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** What `onChange` passes. */
|
|
16
|
+
export interface FilterSingleDateChange {
|
|
17
|
+
/** The chosen instant as UTC ISO-8601, or `null` for no date. */
|
|
18
|
+
value: string | null;
|
|
19
|
+
/** The chosen preset's key, or `null` for a day picked on the calendar. */
|
|
20
|
+
preset: string | null;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { ApiPermission } from './manifest.js';
|
|
2
|
-
/**
|
|
3
|
-
* Plugin documents (contracts 6 to 8): a `document` contribution is a JSON view in the SDUI vocabulary that the host
|
|
4
|
-
* draws with no plugin code running. This module holds the plugin profile's first cut: which node types a document may
|
|
5
|
-
* use, and the rule every read obeys. The full shape of each node is `@nullplatform/sdui-spec`'s to check, and the
|
|
6
|
-
* caller passes the spec in (`assertDocumentVocabulary`) until it is published, so the SDK depends on no renderer.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* The plugin profile per vocabulary line (contract 7, proposal to validate with the SDUI owners): the node types a
|
|
10
|
-
* plugin document of that line may use. Within a line the list only grows, so a document published once keeps
|
|
11
|
-
* drawing; a change that would break one opens a new line. A document declares its line in its root (`vocabulary`),
|
|
12
|
-
* the `VOCABULARY_LINE` of `@nullplatform/sdui-spec`.
|
|
13
|
-
*
|
|
14
|
-
* Line 1, the first cut: layouts, labels, read controls, collections drawn as tables and navigation. Left out until
|
|
15
|
-
* the profile grows: `Definition` and `Reference` (the server expands them), `Page`, `Outlet`, `Slot`,
|
|
16
|
-
* `Categorization` and `Category` (routing and placement are the host's), and `Component` (another plugin's code).
|
|
17
|
-
*/
|
|
18
|
-
export declare const DOCUMENT_PROFILES: {
|
|
19
|
-
readonly 1: readonly ["VerticalLayout", "HorizontalLayout", "GridLayout", "Group", "Label", "Control", "Collection", "Action"];
|
|
20
|
-
};
|
|
21
|
-
/** The line documents are written in today; the API accepts every line in `DOCUMENT_PROFILES`. */
|
|
22
|
-
export declare const DOCUMENT_VOCABULARY_LINE = 1;
|
|
23
|
-
/** Node types of the current line's profile. */
|
|
24
|
-
export declare const DOCUMENT_NODE_TYPES: readonly ["VerticalLayout", "HorizontalLayout", "GridLayout", "Group", "Label", "Control", "Collection", "Action"];
|
|
25
|
-
export type DocumentNodeType = (typeof DOCUMENT_PROFILES)[keyof typeof DOCUMENT_PROFILES][number];
|
|
26
|
-
/** A document as the host receives it: a validated JSON object, drawn by the host's renderer. */
|
|
27
|
-
export type PluginDocument = Record<string, unknown> & {
|
|
28
|
-
vocabulary: number;
|
|
29
|
-
type: DocumentNodeType;
|
|
30
|
-
};
|
|
31
|
-
export declare class DocumentError extends Error {
|
|
32
|
-
constructor(message: string);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Validates an untrusted plugin document against the first cut of the plugin profile and the plugin's
|
|
36
|
-
* `permissions.api` (contract 8): every read is a public API path, GET, covered by a declared permission, with its
|
|
37
|
-
* placeholders as whole segments. Throws a `DocumentError` describing the first problem.
|
|
38
|
-
*/
|
|
39
|
-
export declare function validatePluginDocument(input: unknown, permissions: ApiPermission[] | undefined): PluginDocument;
|
|
40
|
-
/**
|
|
41
|
-
* The vocabulary a document is drawn with: `@nullplatform/sdui-spec`'s `VOCABULARY_LINE` and `resolvedNodeSchema`. The
|
|
42
|
-
* API passes it at publish and the host before drawing, so both refuse the same documents in the same words.
|
|
43
|
-
*/
|
|
44
|
-
export interface DocumentVocabulary {
|
|
45
|
-
line: number;
|
|
46
|
-
node: {
|
|
47
|
-
safeParse(input: unknown): {
|
|
48
|
-
success: boolean;
|
|
49
|
-
error?: {
|
|
50
|
-
issues: readonly {
|
|
51
|
-
path: readonly PropertyKey[];
|
|
52
|
-
message: string;
|
|
53
|
-
}[];
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Checks a document against the vocabulary itself (contract 6): a node as the server would answer it, the shape SDUI's
|
|
60
|
-
* renderer draws (ids are uuids, links are `href`, options closed per type). `vocabulary` is the plugin document's own
|
|
61
|
-
* envelope key, so it is set aside first. A line newer than the vocabulary's is refused. Run it after
|
|
62
|
-
* `validatePluginDocument`; throws a `DocumentError` naming up to five problems.
|
|
63
|
-
*/
|
|
64
|
-
export declare function assertDocumentVocabulary(document: PluginDocument, vocabulary: DocumentVocabulary): void;
|
|
65
|
-
/**
|
|
66
|
-
* Builds the check for the reads the renderer asks for while drawing a document: a read is allowed when it is a GET,
|
|
67
|
-
* the interpolated url's path matches one of the document's read urls (each placeholder exactly one segment) and
|
|
68
|
-
* `permissions.api` covers it. Query strings are never part of the decision, as with widgets. The document is walked
|
|
69
|
-
* once, here, and not on every read; a document whose reads don't pass allows none.
|
|
70
|
-
*/
|
|
71
|
-
export declare function documentReadCheck(document: PluginDocument, permissions: ApiPermission[] | undefined): (method: string, url: string) => boolean;
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { isApiRequestAllowed, normalizePath } from './allowlist.js';
|
|
2
|
-
/**
|
|
3
|
-
* Plugin documents (contracts 6 to 8): a `document` contribution is a JSON view in the SDUI vocabulary that the host
|
|
4
|
-
* draws with no plugin code running. This module holds the plugin profile's first cut: which node types a document may
|
|
5
|
-
* use, and the rule every read obeys. The full shape of each node is `@nullplatform/sdui-spec`'s to check, and the
|
|
6
|
-
* caller passes the spec in (`assertDocumentVocabulary`) until it is published, so the SDK depends on no renderer.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* The plugin profile per vocabulary line (contract 7, proposal to validate with the SDUI owners): the node types a
|
|
10
|
-
* plugin document of that line may use. Within a line the list only grows, so a document published once keeps
|
|
11
|
-
* drawing; a change that would break one opens a new line. A document declares its line in its root (`vocabulary`),
|
|
12
|
-
* the `VOCABULARY_LINE` of `@nullplatform/sdui-spec`.
|
|
13
|
-
*
|
|
14
|
-
* Line 1, the first cut: layouts, labels, read controls, collections drawn as tables and navigation. Left out until
|
|
15
|
-
* the profile grows: `Definition` and `Reference` (the server expands them), `Page`, `Outlet`, `Slot`,
|
|
16
|
-
* `Categorization` and `Category` (routing and placement are the host's), and `Component` (another plugin's code).
|
|
17
|
-
*/
|
|
18
|
-
export const DOCUMENT_PROFILES = {
|
|
19
|
-
1: ['VerticalLayout', 'HorizontalLayout', 'GridLayout', 'Group', 'Label', 'Control', 'Collection', 'Action'],
|
|
20
|
-
};
|
|
21
|
-
/** The line documents are written in today; the API accepts every line in `DOCUMENT_PROFILES`. */
|
|
22
|
-
export const DOCUMENT_VOCABULARY_LINE = 1;
|
|
23
|
-
/** Node types of the current line's profile. */
|
|
24
|
-
export const DOCUMENT_NODE_TYPES = DOCUMENT_PROFILES[DOCUMENT_VOCABULARY_LINE];
|
|
25
|
-
export class DocumentError extends Error {
|
|
26
|
-
constructor(message) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.name = 'DocumentError';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Keys that write, ask with a body, or need the server, anywhere in the document: a draft and its checks, pickers
|
|
33
|
-
* (`choices` reads candidates as a form), steps after an action, `rule` (expressions over the data, not in this
|
|
34
|
-
* cut), and what only the server writes (`contributions`, `release`).
|
|
35
|
-
*/
|
|
36
|
-
const OUT_OF_CUT_KEYS = new Set(['draft', 'body', 'validate', 'choices', 'then', 'rule', 'contributes', 'contributions', 'release']);
|
|
37
|
-
/** One `{{ … }}` placeholder that is a singular path into the context (`$.url.params.id`), never an expression. */
|
|
38
|
-
const PLACEHOLDER = /^\{\{\s*(\$(?:\.[A-Za-z_][A-Za-z0-9_]*|\[[0-9]+\])+)\s*\}\}$/;
|
|
39
|
-
/** A literal path segment: characters an API path or a host route is written with, nothing a browser would drop. */
|
|
40
|
-
const LITERAL_SEGMENT = /^[A-Za-z0-9_~-][A-Za-z0-9_.~-]*$/;
|
|
41
|
-
/**
|
|
42
|
-
* Whitespace, control characters and backslashes anywhere in a url: a browser strips tabs and newlines and reads a
|
|
43
|
-
* backslash as a slash, so `/\t/evil.example.com` would become another site.
|
|
44
|
-
*/
|
|
45
|
-
const UNSAFE_CHARACTERS = /[\s\\\u0000-\u001f\u007f]/;
|
|
46
|
-
/** A query parameter's name: a field, or a field with an operator (`name:contains`), as `sdui-spec` names them. */
|
|
47
|
-
const QUERY_PARAM = /^[a-z_][a-z0-9_.]*(:[a-z_]+)?$/;
|
|
48
|
-
/**
|
|
49
|
-
* What a placeholder segment becomes for the permission check: a pattern segment `{param}` matches it, a literal one
|
|
50
|
-
* can't, since no API path segment is written with braces.
|
|
51
|
-
*/
|
|
52
|
-
const HOLE = '{{}}';
|
|
53
|
-
const isPlainObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
54
|
-
/**
|
|
55
|
-
* Parses a read url of a plugin document: a public API path, each placeholder a whole segment or a whole query value.
|
|
56
|
-
* Throws a `DocumentError` saying what to write instead.
|
|
57
|
-
*/
|
|
58
|
-
function parseRead(url, where) {
|
|
59
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith('//')) {
|
|
60
|
-
throw new DocumentError(`${where}: "${url}" names a host; a document reads public API paths such as "/application/{{ $.url.params.id }}"`);
|
|
61
|
-
}
|
|
62
|
-
if (!url.startsWith('/'))
|
|
63
|
-
throw new DocumentError(`${where}: "${url}" must start with "/" (a public API path)`);
|
|
64
|
-
if (UNSAFE_CHARACTERS.test(url.replace(/\{\{[^}]*\}\}/g, ''))) {
|
|
65
|
-
throw new DocumentError(`${where}: "${url}" has whitespace, a control character or a backslash`);
|
|
66
|
-
}
|
|
67
|
-
const [path, query] = url.split(/\?(.*)/s, 2);
|
|
68
|
-
const segments = path.split('/').slice(1).map((segment) => {
|
|
69
|
-
if (segment.includes('{') || segment.includes('}')) {
|
|
70
|
-
if (PLACEHOLDER.test(segment))
|
|
71
|
-
return null;
|
|
72
|
-
throw new DocumentError(`${where}: "${url}": a placeholder takes a whole path segment and is a path into the context, such as {{ $.url.params.id }}`);
|
|
73
|
-
}
|
|
74
|
-
if (!LITERAL_SEGMENT.test(segment) || segment === '..') {
|
|
75
|
-
throw new DocumentError(`${where}: "${url}" has an empty, relative or encoded segment, or one with characters outside A-Z, a-z, 0-9 and _ . ~ -`);
|
|
76
|
-
}
|
|
77
|
-
return segment;
|
|
78
|
-
});
|
|
79
|
-
for (const pair of query ? query.split('&') : []) {
|
|
80
|
-
const [name, value = ''] = pair.split(/=(.*)/s, 2);
|
|
81
|
-
if (!QUERY_PARAM.test(name))
|
|
82
|
-
throw new DocumentError(`${where}: "${url}": "${name}" is not a query parameter name`);
|
|
83
|
-
if ((value.includes('{') || value.includes('}')) && !PLACEHOLDER.test(value)) {
|
|
84
|
-
throw new DocumentError(`${where}: "${url}": a placeholder takes a whole query value and is a path into the context`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return { segments };
|
|
88
|
-
}
|
|
89
|
-
const asPath = (read, hole) => '/' + read.segments.map((segment, index) => segment ?? hole(index)).join('/');
|
|
90
|
-
/** Checks one read against the plugin's `permissions.api`, with the runtime's own matcher. */
|
|
91
|
-
function assertCovered(read, url, permissions, where) {
|
|
92
|
-
if (isApiRequestAllowed(permissions, 'GET', asPath(read, () => HOLE)))
|
|
93
|
-
return;
|
|
94
|
-
const suggested = asPath(read, (index) => `{param${index}}`);
|
|
95
|
-
const hint = read.segments[0] === 'v1' ? ' Paths are relative to the public API root, without "/v1".' : '';
|
|
96
|
-
throw new DocumentError(`${where}: GET ${url} is not covered by permissions.api; declare { "method": "GET", "path": "${suggested}" } or a pattern that covers it.${hint}`);
|
|
97
|
-
}
|
|
98
|
-
function checkText(value, where) {
|
|
99
|
-
if (isPlainObject(value) && 'i18n' in value)
|
|
100
|
-
throw new DocumentError(`${where}: translatable texts ({ "i18n": … }) are not in the first cut; write the text`);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Walks every value of a node's options: each `url` is a read the plugin declared, a `schema` given as a url too,
|
|
104
|
-
* `method` is only GET, and nothing that writes or needs the server.
|
|
105
|
-
*/
|
|
106
|
-
function checkOptions(value, where, visit) {
|
|
107
|
-
if (Array.isArray(value)) {
|
|
108
|
-
value.forEach((item, index) => checkOptions(item, `${where}[${index}]`, visit));
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (!isPlainObject(value))
|
|
112
|
-
return;
|
|
113
|
-
checkText(value, where);
|
|
114
|
-
for (const [key, child] of Object.entries(value)) {
|
|
115
|
-
const at = `${where}.${key}`;
|
|
116
|
-
if (OUT_OF_CUT_KEYS.has(key))
|
|
117
|
-
throw new DocumentError(`${at} is not in the first cut of plugin documents (read-only, resolved shape)`);
|
|
118
|
-
if (key === 'method' && child !== 'GET')
|
|
119
|
-
throw new DocumentError(`${at}: a document only reads (GET)`);
|
|
120
|
-
if (key === 'kind' && child !== 'navigate')
|
|
121
|
-
throw new DocumentError(`${at}: "${String(child)}" is not in the first cut; an action only navigates`);
|
|
122
|
-
if (key === 'to')
|
|
123
|
-
throw new DocumentError(`${at}: "to" is a page the server turns into a link; a document is drawn as written, so write the host path in "href"`);
|
|
124
|
-
if (key === 'href') {
|
|
125
|
-
if (typeof child !== 'string')
|
|
126
|
-
throw new DocumentError(`${at} must be a string`);
|
|
127
|
-
// A host path, built like a read: never a scheme or a second slash (another site, a script), never `..`, only
|
|
128
|
-
// safe characters. A placeholder fills one segment; the renderer refuses a filled-in link that is not a path
|
|
129
|
-
// of this origin (sdui-engine's `isRootRelativeHref`).
|
|
130
|
-
parseRead(child, at);
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (key === 'url' || (key === 'schema' && typeof child === 'string' && child.startsWith('/'))) {
|
|
134
|
-
if (typeof child !== 'string')
|
|
135
|
-
throw new DocumentError(`${at} must be a string`);
|
|
136
|
-
visit(child, at);
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
checkOptions(child, at, visit);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function checkNode(node, where, types, visit) {
|
|
143
|
-
if (!isPlainObject(node))
|
|
144
|
-
throw new DocumentError(`${where} must be an object`);
|
|
145
|
-
const type = node.type;
|
|
146
|
-
if (typeof type !== 'string' || !types.includes(type)) {
|
|
147
|
-
throw new DocumentError(`${where}: node type "${String(type)}" is not in the first cut (${types.join(', ')})`);
|
|
148
|
-
}
|
|
149
|
-
const at = `${where}(${type})`;
|
|
150
|
-
for (const key of Object.keys(node)) {
|
|
151
|
-
if (OUT_OF_CUT_KEYS.has(key))
|
|
152
|
-
throw new DocumentError(`${at}.${key} is not in the first cut of plugin documents (read-only, resolved shape)`);
|
|
153
|
-
}
|
|
154
|
-
checkText(node.label, `${at}.label`);
|
|
155
|
-
const options = node.options;
|
|
156
|
-
if (options !== undefined && !isPlainObject(options))
|
|
157
|
-
throw new DocumentError(`${at}.options must be an object`);
|
|
158
|
-
if (type === 'Collection' && options?.format !== 'table')
|
|
159
|
-
throw new DocumentError(`${at}: a collection is drawn as a table (options.format "table") in the first cut`);
|
|
160
|
-
if (type === 'Action' && options?.kind !== 'navigate')
|
|
161
|
-
throw new DocumentError(`${at}: an action only navigates (options.kind "navigate") in the first cut`);
|
|
162
|
-
checkOptions(options, `${at}.options`, visit);
|
|
163
|
-
if (node.elements !== undefined) {
|
|
164
|
-
if (!Array.isArray(node.elements))
|
|
165
|
-
throw new DocumentError(`${at}.elements must be an array`);
|
|
166
|
-
node.elements.forEach((child, index) => checkNode(child, `${at}.elements[${index}]`, types, visit));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/** Every read url of a document that already passed `validatePluginDocument`, in document order. */
|
|
170
|
-
function readsOf(document, permissions) {
|
|
171
|
-
const reads = [];
|
|
172
|
-
const types = DOCUMENT_PROFILES[document.vocabulary] ?? [];
|
|
173
|
-
checkNode(document, 'document', types, (url, where) => {
|
|
174
|
-
const read = parseRead(url, where);
|
|
175
|
-
assertCovered(read, url, permissions, where);
|
|
176
|
-
reads.push(read);
|
|
177
|
-
});
|
|
178
|
-
return reads;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Validates an untrusted plugin document against the first cut of the plugin profile and the plugin's
|
|
182
|
-
* `permissions.api` (contract 8): every read is a public API path, GET, covered by a declared permission, with its
|
|
183
|
-
* placeholders as whole segments. Throws a `DocumentError` describing the first problem.
|
|
184
|
-
*/
|
|
185
|
-
export function validatePluginDocument(input, permissions) {
|
|
186
|
-
if (!isPlainObject(input))
|
|
187
|
-
throw new DocumentError('A document must be a JSON object');
|
|
188
|
-
if (typeof input.vocabulary !== 'number' || !(input.vocabulary in DOCUMENT_PROFILES)) {
|
|
189
|
-
throw new DocumentError(`A document declares its vocabulary line in its root: "vocabulary": ${DOCUMENT_VOCABULARY_LINE} (accepted: ${Object.keys(DOCUMENT_PROFILES).join(', ')})`);
|
|
190
|
-
}
|
|
191
|
-
readsOf(input, permissions);
|
|
192
|
-
return input;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Checks a document against the vocabulary itself (contract 6): a node as the server would answer it, the shape SDUI's
|
|
196
|
-
* renderer draws (ids are uuids, links are `href`, options closed per type). `vocabulary` is the plugin document's own
|
|
197
|
-
* envelope key, so it is set aside first. A line newer than the vocabulary's is refused. Run it after
|
|
198
|
-
* `validatePluginDocument`; throws a `DocumentError` naming up to five problems.
|
|
199
|
-
*/
|
|
200
|
-
export function assertDocumentVocabulary(document, vocabulary) {
|
|
201
|
-
const { vocabulary: line, ...node } = document;
|
|
202
|
-
if (line > vocabulary.line) {
|
|
203
|
-
throw new DocumentError(`The document's vocabulary line ${line} is newer than this platform's (${vocabulary.line})`);
|
|
204
|
-
}
|
|
205
|
-
const parsed = vocabulary.node.safeParse(node);
|
|
206
|
-
if (parsed.success)
|
|
207
|
-
return;
|
|
208
|
-
const issues = (parsed.error?.issues ?? [])
|
|
209
|
-
.slice(0, 5)
|
|
210
|
-
.map((issue) => `${issue.path.length ? '/' + issue.path.map(String).join('/') : '/'}: ${issue.message}`);
|
|
211
|
-
throw new DocumentError(`The document is not a view the renderer draws: ${issues.join('; ')}`);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Builds the check for the reads the renderer asks for while drawing a document: a read is allowed when it is a GET,
|
|
215
|
-
* the interpolated url's path matches one of the document's read urls (each placeholder exactly one segment) and
|
|
216
|
-
* `permissions.api` covers it. Query strings are never part of the decision, as with widgets. The document is walked
|
|
217
|
-
* once, here, and not on every read; a document whose reads don't pass allows none.
|
|
218
|
-
*/
|
|
219
|
-
export function documentReadCheck(document, permissions) {
|
|
220
|
-
let reads;
|
|
221
|
-
try {
|
|
222
|
-
reads = readsOf(document, permissions);
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
reads = [];
|
|
226
|
-
}
|
|
227
|
-
return (method, url) => {
|
|
228
|
-
if (method.toUpperCase() !== 'GET')
|
|
229
|
-
return false;
|
|
230
|
-
const [path] = url.split('?', 1);
|
|
231
|
-
const requested = normalizePath(path);
|
|
232
|
-
if (!requested || !isApiRequestAllowed(permissions, 'GET', path))
|
|
233
|
-
return false;
|
|
234
|
-
return reads.some((read) => read.segments.length === requested.length &&
|
|
235
|
-
read.segments.every((segment, index) => (segment === null ? requested[index].length > 0 : segment === requested[index])));
|
|
236
|
-
};
|
|
237
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentError = exports.DOCUMENT_NODE_TYPES = exports.DOCUMENT_VOCABULARY_LINE = exports.DOCUMENT_PROFILES = void 0;
|
|
4
|
-
exports.validatePluginDocument = validatePluginDocument;
|
|
5
|
-
exports.assertDocumentVocabulary = assertDocumentVocabulary;
|
|
6
|
-
exports.documentReadCheck = documentReadCheck;
|
|
7
|
-
const allowlist_1 = require("./allowlist");
|
|
8
|
-
/**
|
|
9
|
-
* Plugin documents (contracts 6 to 8): a `document` contribution is a JSON view in the SDUI vocabulary that the host
|
|
10
|
-
* draws with no plugin code running. This module holds the plugin profile's first cut: which node types a document may
|
|
11
|
-
* use, and the rule every read obeys. The full shape of each node is `@nullplatform/sdui-spec`'s to check, and the
|
|
12
|
-
* caller passes the spec in (`assertDocumentVocabulary`) until it is published, so the SDK depends on no renderer.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* The plugin profile per vocabulary line (contract 7, proposal to validate with the SDUI owners): the node types a
|
|
16
|
-
* plugin document of that line may use. Within a line the list only grows, so a document published once keeps
|
|
17
|
-
* drawing; a change that would break one opens a new line. A document declares its line in its root (`vocabulary`),
|
|
18
|
-
* the `VOCABULARY_LINE` of `@nullplatform/sdui-spec`.
|
|
19
|
-
*
|
|
20
|
-
* Line 1, the first cut: layouts, labels, read controls, collections drawn as tables and navigation. Left out until
|
|
21
|
-
* the profile grows: `Definition` and `Reference` (the server expands them), `Page`, `Outlet`, `Slot`,
|
|
22
|
-
* `Categorization` and `Category` (routing and placement are the host's), and `Component` (another plugin's code).
|
|
23
|
-
*/
|
|
24
|
-
exports.DOCUMENT_PROFILES = {
|
|
25
|
-
1: ['VerticalLayout', 'HorizontalLayout', 'GridLayout', 'Group', 'Label', 'Control', 'Collection', 'Action'],
|
|
26
|
-
};
|
|
27
|
-
/** The line documents are written in today; the API accepts every line in `DOCUMENT_PROFILES`. */
|
|
28
|
-
exports.DOCUMENT_VOCABULARY_LINE = 1;
|
|
29
|
-
/** Node types of the current line's profile. */
|
|
30
|
-
exports.DOCUMENT_NODE_TYPES = exports.DOCUMENT_PROFILES[exports.DOCUMENT_VOCABULARY_LINE];
|
|
31
|
-
class DocumentError extends Error {
|
|
32
|
-
constructor(message) {
|
|
33
|
-
super(message);
|
|
34
|
-
this.name = 'DocumentError';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.DocumentError = DocumentError;
|
|
38
|
-
/**
|
|
39
|
-
* Keys that write, ask with a body, or need the server, anywhere in the document: a draft and its checks, pickers
|
|
40
|
-
* (`choices` reads candidates as a form), steps after an action, `rule` (expressions over the data, not in this
|
|
41
|
-
* cut), and what only the server writes (`contributions`, `release`).
|
|
42
|
-
*/
|
|
43
|
-
const OUT_OF_CUT_KEYS = new Set(['draft', 'body', 'validate', 'choices', 'then', 'rule', 'contributes', 'contributions', 'release']);
|
|
44
|
-
/** One `{{ … }}` placeholder that is a singular path into the context (`$.url.params.id`), never an expression. */
|
|
45
|
-
const PLACEHOLDER = /^\{\{\s*(\$(?:\.[A-Za-z_][A-Za-z0-9_]*|\[[0-9]+\])+)\s*\}\}$/;
|
|
46
|
-
/** A literal path segment: characters an API path or a host route is written with, nothing a browser would drop. */
|
|
47
|
-
const LITERAL_SEGMENT = /^[A-Za-z0-9_~-][A-Za-z0-9_.~-]*$/;
|
|
48
|
-
/**
|
|
49
|
-
* Whitespace, control characters and backslashes anywhere in a url: a browser strips tabs and newlines and reads a
|
|
50
|
-
* backslash as a slash, so `/\t/evil.example.com` would become another site.
|
|
51
|
-
*/
|
|
52
|
-
const UNSAFE_CHARACTERS = /[\s\\\u0000-\u001f\u007f]/;
|
|
53
|
-
/** A query parameter's name: a field, or a field with an operator (`name:contains`), as `sdui-spec` names them. */
|
|
54
|
-
const QUERY_PARAM = /^[a-z_][a-z0-9_.]*(:[a-z_]+)?$/;
|
|
55
|
-
/**
|
|
56
|
-
* What a placeholder segment becomes for the permission check: a pattern segment `{param}` matches it, a literal one
|
|
57
|
-
* can't, since no API path segment is written with braces.
|
|
58
|
-
*/
|
|
59
|
-
const HOLE = '{{}}';
|
|
60
|
-
const isPlainObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
61
|
-
/**
|
|
62
|
-
* Parses a read url of a plugin document: a public API path, each placeholder a whole segment or a whole query value.
|
|
63
|
-
* Throws a `DocumentError` saying what to write instead.
|
|
64
|
-
*/
|
|
65
|
-
function parseRead(url, where) {
|
|
66
|
-
if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith('//')) {
|
|
67
|
-
throw new DocumentError(`${where}: "${url}" names a host; a document reads public API paths such as "/application/{{ $.url.params.id }}"`);
|
|
68
|
-
}
|
|
69
|
-
if (!url.startsWith('/'))
|
|
70
|
-
throw new DocumentError(`${where}: "${url}" must start with "/" (a public API path)`);
|
|
71
|
-
if (UNSAFE_CHARACTERS.test(url.replace(/\{\{[^}]*\}\}/g, ''))) {
|
|
72
|
-
throw new DocumentError(`${where}: "${url}" has whitespace, a control character or a backslash`);
|
|
73
|
-
}
|
|
74
|
-
const [path, query] = url.split(/\?(.*)/s, 2);
|
|
75
|
-
const segments = path.split('/').slice(1).map((segment) => {
|
|
76
|
-
if (segment.includes('{') || segment.includes('}')) {
|
|
77
|
-
if (PLACEHOLDER.test(segment))
|
|
78
|
-
return null;
|
|
79
|
-
throw new DocumentError(`${where}: "${url}": a placeholder takes a whole path segment and is a path into the context, such as {{ $.url.params.id }}`);
|
|
80
|
-
}
|
|
81
|
-
if (!LITERAL_SEGMENT.test(segment) || segment === '..') {
|
|
82
|
-
throw new DocumentError(`${where}: "${url}" has an empty, relative or encoded segment, or one with characters outside A-Z, a-z, 0-9 and _ . ~ -`);
|
|
83
|
-
}
|
|
84
|
-
return segment;
|
|
85
|
-
});
|
|
86
|
-
for (const pair of query ? query.split('&') : []) {
|
|
87
|
-
const [name, value = ''] = pair.split(/=(.*)/s, 2);
|
|
88
|
-
if (!QUERY_PARAM.test(name))
|
|
89
|
-
throw new DocumentError(`${where}: "${url}": "${name}" is not a query parameter name`);
|
|
90
|
-
if ((value.includes('{') || value.includes('}')) && !PLACEHOLDER.test(value)) {
|
|
91
|
-
throw new DocumentError(`${where}: "${url}": a placeholder takes a whole query value and is a path into the context`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return { segments };
|
|
95
|
-
}
|
|
96
|
-
const asPath = (read, hole) => '/' + read.segments.map((segment, index) => segment ?? hole(index)).join('/');
|
|
97
|
-
/** Checks one read against the plugin's `permissions.api`, with the runtime's own matcher. */
|
|
98
|
-
function assertCovered(read, url, permissions, where) {
|
|
99
|
-
if ((0, allowlist_1.isApiRequestAllowed)(permissions, 'GET', asPath(read, () => HOLE)))
|
|
100
|
-
return;
|
|
101
|
-
const suggested = asPath(read, (index) => `{param${index}}`);
|
|
102
|
-
const hint = read.segments[0] === 'v1' ? ' Paths are relative to the public API root, without "/v1".' : '';
|
|
103
|
-
throw new DocumentError(`${where}: GET ${url} is not covered by permissions.api; declare { "method": "GET", "path": "${suggested}" } or a pattern that covers it.${hint}`);
|
|
104
|
-
}
|
|
105
|
-
function checkText(value, where) {
|
|
106
|
-
if (isPlainObject(value) && 'i18n' in value)
|
|
107
|
-
throw new DocumentError(`${where}: translatable texts ({ "i18n": … }) are not in the first cut; write the text`);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Walks every value of a node's options: each `url` is a read the plugin declared, a `schema` given as a url too,
|
|
111
|
-
* `method` is only GET, and nothing that writes or needs the server.
|
|
112
|
-
*/
|
|
113
|
-
function checkOptions(value, where, visit) {
|
|
114
|
-
if (Array.isArray(value)) {
|
|
115
|
-
value.forEach((item, index) => checkOptions(item, `${where}[${index}]`, visit));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (!isPlainObject(value))
|
|
119
|
-
return;
|
|
120
|
-
checkText(value, where);
|
|
121
|
-
for (const [key, child] of Object.entries(value)) {
|
|
122
|
-
const at = `${where}.${key}`;
|
|
123
|
-
if (OUT_OF_CUT_KEYS.has(key))
|
|
124
|
-
throw new DocumentError(`${at} is not in the first cut of plugin documents (read-only, resolved shape)`);
|
|
125
|
-
if (key === 'method' && child !== 'GET')
|
|
126
|
-
throw new DocumentError(`${at}: a document only reads (GET)`);
|
|
127
|
-
if (key === 'kind' && child !== 'navigate')
|
|
128
|
-
throw new DocumentError(`${at}: "${String(child)}" is not in the first cut; an action only navigates`);
|
|
129
|
-
if (key === 'to')
|
|
130
|
-
throw new DocumentError(`${at}: "to" is a page the server turns into a link; a document is drawn as written, so write the host path in "href"`);
|
|
131
|
-
if (key === 'href') {
|
|
132
|
-
if (typeof child !== 'string')
|
|
133
|
-
throw new DocumentError(`${at} must be a string`);
|
|
134
|
-
// A host path, built like a read: never a scheme or a second slash (another site, a script), never `..`, only
|
|
135
|
-
// safe characters. A placeholder fills one segment; the renderer refuses a filled-in link that is not a path
|
|
136
|
-
// of this origin (sdui-engine's `isRootRelativeHref`).
|
|
137
|
-
parseRead(child, at);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
if (key === 'url' || (key === 'schema' && typeof child === 'string' && child.startsWith('/'))) {
|
|
141
|
-
if (typeof child !== 'string')
|
|
142
|
-
throw new DocumentError(`${at} must be a string`);
|
|
143
|
-
visit(child, at);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
checkOptions(child, at, visit);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function checkNode(node, where, types, visit) {
|
|
150
|
-
if (!isPlainObject(node))
|
|
151
|
-
throw new DocumentError(`${where} must be an object`);
|
|
152
|
-
const type = node.type;
|
|
153
|
-
if (typeof type !== 'string' || !types.includes(type)) {
|
|
154
|
-
throw new DocumentError(`${where}: node type "${String(type)}" is not in the first cut (${types.join(', ')})`);
|
|
155
|
-
}
|
|
156
|
-
const at = `${where}(${type})`;
|
|
157
|
-
for (const key of Object.keys(node)) {
|
|
158
|
-
if (OUT_OF_CUT_KEYS.has(key))
|
|
159
|
-
throw new DocumentError(`${at}.${key} is not in the first cut of plugin documents (read-only, resolved shape)`);
|
|
160
|
-
}
|
|
161
|
-
checkText(node.label, `${at}.label`);
|
|
162
|
-
const options = node.options;
|
|
163
|
-
if (options !== undefined && !isPlainObject(options))
|
|
164
|
-
throw new DocumentError(`${at}.options must be an object`);
|
|
165
|
-
if (type === 'Collection' && options?.format !== 'table')
|
|
166
|
-
throw new DocumentError(`${at}: a collection is drawn as a table (options.format "table") in the first cut`);
|
|
167
|
-
if (type === 'Action' && options?.kind !== 'navigate')
|
|
168
|
-
throw new DocumentError(`${at}: an action only navigates (options.kind "navigate") in the first cut`);
|
|
169
|
-
checkOptions(options, `${at}.options`, visit);
|
|
170
|
-
if (node.elements !== undefined) {
|
|
171
|
-
if (!Array.isArray(node.elements))
|
|
172
|
-
throw new DocumentError(`${at}.elements must be an array`);
|
|
173
|
-
node.elements.forEach((child, index) => checkNode(child, `${at}.elements[${index}]`, types, visit));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/** Every read url of a document that already passed `validatePluginDocument`, in document order. */
|
|
177
|
-
function readsOf(document, permissions) {
|
|
178
|
-
const reads = [];
|
|
179
|
-
const types = exports.DOCUMENT_PROFILES[document.vocabulary] ?? [];
|
|
180
|
-
checkNode(document, 'document', types, (url, where) => {
|
|
181
|
-
const read = parseRead(url, where);
|
|
182
|
-
assertCovered(read, url, permissions, where);
|
|
183
|
-
reads.push(read);
|
|
184
|
-
});
|
|
185
|
-
return reads;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Validates an untrusted plugin document against the first cut of the plugin profile and the plugin's
|
|
189
|
-
* `permissions.api` (contract 8): every read is a public API path, GET, covered by a declared permission, with its
|
|
190
|
-
* placeholders as whole segments. Throws a `DocumentError` describing the first problem.
|
|
191
|
-
*/
|
|
192
|
-
function validatePluginDocument(input, permissions) {
|
|
193
|
-
if (!isPlainObject(input))
|
|
194
|
-
throw new DocumentError('A document must be a JSON object');
|
|
195
|
-
if (typeof input.vocabulary !== 'number' || !(input.vocabulary in exports.DOCUMENT_PROFILES)) {
|
|
196
|
-
throw new DocumentError(`A document declares its vocabulary line in its root: "vocabulary": ${exports.DOCUMENT_VOCABULARY_LINE} (accepted: ${Object.keys(exports.DOCUMENT_PROFILES).join(', ')})`);
|
|
197
|
-
}
|
|
198
|
-
readsOf(input, permissions);
|
|
199
|
-
return input;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Checks a document against the vocabulary itself (contract 6): a node as the server would answer it, the shape SDUI's
|
|
203
|
-
* renderer draws (ids are uuids, links are `href`, options closed per type). `vocabulary` is the plugin document's own
|
|
204
|
-
* envelope key, so it is set aside first. A line newer than the vocabulary's is refused. Run it after
|
|
205
|
-
* `validatePluginDocument`; throws a `DocumentError` naming up to five problems.
|
|
206
|
-
*/
|
|
207
|
-
function assertDocumentVocabulary(document, vocabulary) {
|
|
208
|
-
const { vocabulary: line, ...node } = document;
|
|
209
|
-
if (line > vocabulary.line) {
|
|
210
|
-
throw new DocumentError(`The document's vocabulary line ${line} is newer than this platform's (${vocabulary.line})`);
|
|
211
|
-
}
|
|
212
|
-
const parsed = vocabulary.node.safeParse(node);
|
|
213
|
-
if (parsed.success)
|
|
214
|
-
return;
|
|
215
|
-
const issues = (parsed.error?.issues ?? [])
|
|
216
|
-
.slice(0, 5)
|
|
217
|
-
.map((issue) => `${issue.path.length ? '/' + issue.path.map(String).join('/') : '/'}: ${issue.message}`);
|
|
218
|
-
throw new DocumentError(`The document is not a view the renderer draws: ${issues.join('; ')}`);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Builds the check for the reads the renderer asks for while drawing a document: a read is allowed when it is a GET,
|
|
222
|
-
* the interpolated url's path matches one of the document's read urls (each placeholder exactly one segment) and
|
|
223
|
-
* `permissions.api` covers it. Query strings are never part of the decision, as with widgets. The document is walked
|
|
224
|
-
* once, here, and not on every read; a document whose reads don't pass allows none.
|
|
225
|
-
*/
|
|
226
|
-
function documentReadCheck(document, permissions) {
|
|
227
|
-
let reads;
|
|
228
|
-
try {
|
|
229
|
-
reads = readsOf(document, permissions);
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
reads = [];
|
|
233
|
-
}
|
|
234
|
-
return (method, url) => {
|
|
235
|
-
if (method.toUpperCase() !== 'GET')
|
|
236
|
-
return false;
|
|
237
|
-
const [path] = url.split('?', 1);
|
|
238
|
-
const requested = (0, allowlist_1.normalizePath)(path);
|
|
239
|
-
if (!requested || !(0, allowlist_1.isApiRequestAllowed)(permissions, 'GET', path))
|
|
240
|
-
return false;
|
|
241
|
-
return reads.some((read) => read.segments.length === requested.length &&
|
|
242
|
-
read.segments.every((segment, index) => (segment === null ? requested[index].length > 0 : segment === requested[index])));
|
|
243
|
-
};
|
|
244
|
-
}
|