@nullplatform/ui-plugin-sdk 0.20.0-beta.0 → 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/bridge.d.ts +1 -37
- package/dist/bridge.js +0 -44
- package/dist/calendar.d.ts +58 -0
- package/dist/calendar.js +1 -0
- package/dist/catalog.js +2 -1
- package/dist/components.d.ts +16 -3
- package/dist/components.generated.d.ts +149 -6
- package/dist/components.generated.js +12 -1
- package/dist/context.d.ts +0 -6
- package/dist/contract/allowlist.d.ts +6 -8
- package/dist/contract/allowlist.js +78 -26
- package/dist/contract/index.d.ts +2 -2
- package/dist/contract/index.js +2 -2
- package/dist/contract/manifest.d.ts +9 -13
- package/dist/contract/manifest.js +24 -15
- package/dist/contract/when.d.ts +1 -1
- package/dist/contract/when.js +1 -1
- package/dist/contract-cjs/allowlist.js +79 -27
- package/dist/contract-cjs/index.js +3 -2
- package/dist/contract-cjs/manifest.js +25 -15
- package/dist/contract-cjs/when.js +1 -1
- package/dist/contractProps.d.ts +31 -0
- package/dist/contracts.generated.d.ts +157 -0
- package/dist/contracts.generated.js +78 -2
- package/dist/filterSingleDate.d.ts +21 -0
- package/dist/filterSingleDate.js +5 -0
- package/dist/host.d.ts +0 -8
- package/dist/host.js +0 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/protocol.d.ts +1 -108
- package/dist/protocol.js +0 -14
- package/dist/worker.js +1 -2
- package/package.json +2 -2
|
@@ -15,14 +15,6 @@ export interface HttpPermission {
|
|
|
15
15
|
/** Path pattern on that host, `{param}` placeholders allowed. */
|
|
16
16
|
path: string;
|
|
17
17
|
}
|
|
18
|
-
export interface UploadPermission {
|
|
19
|
-
/**
|
|
20
|
-
* A host a picked file may be uploaded to with `files.upload`: exact (`uploads.example.com`), or every host under a
|
|
21
|
-
* domain (`*.amazonaws.com`). A wildcard is allowed here, unlike in `permissions.http`, because a presigned upload
|
|
22
|
-
* names its bucket in the host. Only https is ever allowed.
|
|
23
|
-
*/
|
|
24
|
-
host: string;
|
|
25
|
-
}
|
|
26
18
|
export interface Contribution {
|
|
27
19
|
slot: string;
|
|
28
20
|
/** Widget id exported by the plugin through `defineUI`. */
|
|
@@ -50,11 +42,6 @@ export interface PluginManifest {
|
|
|
50
42
|
permissions?: {
|
|
51
43
|
api?: ApiPermission[];
|
|
52
44
|
http?: HttpPermission[];
|
|
53
|
-
/**
|
|
54
|
-
* Hosts the plugin may send a file to. Shown at install: the file is one the person picks in the host's own file
|
|
55
|
-
* picker, and the plugin never reads it, but it does choose where it goes.
|
|
56
|
-
*/
|
|
57
|
-
upload?: UploadPermission[];
|
|
58
45
|
topics?: TopicPermissions;
|
|
59
46
|
/**
|
|
60
47
|
* Draws its own pixels with `Canvas`. Shown at install: inside its rectangle the plugin can paint anything,
|
|
@@ -89,6 +76,15 @@ export declare function contributionId(contribution: {
|
|
|
89
76
|
* it before the build is pushed. Revisions published before keep working: hosts name them with `contributionId`.
|
|
90
77
|
*/
|
|
91
78
|
export declare function validatePublishableManifest(input: unknown): PluginManifest;
|
|
79
|
+
/**
|
|
80
|
+
* What a manifest's `permissions.api` must meet where the manifest is written: at publish and in developer mode, never
|
|
81
|
+
* where a stored revision is read. Each path names its resource, so a reviewer reading the manifest sees what the
|
|
82
|
+
* plugin calls, and none names an operation no plugin may call (`isReservedApiRequest`). A revision published before
|
|
83
|
+
* these rules keeps loading, and the call itself is refused (`isApiRequestAllowed`), so a page loses one call, not
|
|
84
|
+
* the whole plugin. A placeholder deeper in the path can still cover a reserved operation (`POST /catalog/{kind}/{type}`):
|
|
85
|
+
* that too is refused at call time, on the path actually requested.
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateAuthoredApiPermissions(manifest: PluginManifest): PluginManifest;
|
|
92
88
|
/**
|
|
93
89
|
* Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
|
|
94
90
|
* block, its flag and its place in layouts, so the CLI warns about them.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { validateWhen, WhenError } from './when.js';
|
|
2
2
|
import { isFieldPath, isHostTopic, isTopicName, topicOwner } from './topics.js';
|
|
3
3
|
import { PLACE_ROOTS, readPlaceRoots } from './context.js';
|
|
4
|
+
import { isReservedApiRequest } from './allowlist.js';
|
|
4
5
|
export const PROTOCOL_VERSION = 1;
|
|
5
6
|
export class ManifestError extends Error {
|
|
6
7
|
constructor(message) {
|
|
@@ -11,8 +12,6 @@ export class ManifestError extends Error {
|
|
|
11
12
|
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
12
13
|
const SLOT_PATTERN = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/;
|
|
13
14
|
const HOST_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+(:[0-9]{1,5})?$/;
|
|
14
|
-
/** `*.` and a domain of two labels or more: `*.amazonaws.com`, never `*.com`. No port. */
|
|
15
|
-
const WILDCARD_HOST_PATTERN = /^\*(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}$/;
|
|
16
15
|
const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', '*']);
|
|
17
16
|
export function isSectionSlot(slot) {
|
|
18
17
|
return slot.endsWith('.section');
|
|
@@ -95,7 +94,8 @@ export function validateManifest(input) {
|
|
|
95
94
|
permissions.api = rawPermissions.api.map((raw, index) => {
|
|
96
95
|
const p = (raw ?? {});
|
|
97
96
|
const where = `permissions.api[${index}]`;
|
|
98
|
-
|
|
97
|
+
const method = readMethod(p.method, where);
|
|
98
|
+
return { method, path: readPath(p.path, where) };
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
if (rawPermissions.http !== undefined) {
|
|
@@ -110,18 +110,6 @@ export function validateManifest(input) {
|
|
|
110
110
|
return { host, method: readMethod(p.method, where), path: readPath(p.path, where) };
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
if (rawPermissions.upload !== undefined) {
|
|
114
|
-
if (!Array.isArray(rawPermissions.upload))
|
|
115
|
-
throw new ManifestError('permissions.upload must be an array');
|
|
116
|
-
permissions.upload = rawPermissions.upload.map((raw, index) => {
|
|
117
|
-
const p = (raw ?? {});
|
|
118
|
-
const host = typeof p.host === 'string' ? p.host.toLowerCase() : '';
|
|
119
|
-
if (!HOST_PATTERN.test(host) && !WILDCARD_HOST_PATTERN.test(host)) {
|
|
120
|
-
throw new ManifestError(`permissions.upload[${index}].host must be a hostname (optional port) or "*." and a domain of two labels or more, no scheme`);
|
|
121
|
-
}
|
|
122
|
-
return { host };
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
113
|
if (rawPermissions.topics !== undefined) {
|
|
126
114
|
permissions.topics = readTopicPermissions(rawPermissions.topics, m.id);
|
|
127
115
|
}
|
|
@@ -219,6 +207,27 @@ export function validatePublishableManifest(input) {
|
|
|
219
207
|
});
|
|
220
208
|
return manifest;
|
|
221
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* What a manifest's `permissions.api` must meet where the manifest is written: at publish and in developer mode, never
|
|
212
|
+
* where a stored revision is read. Each path names its resource, so a reviewer reading the manifest sees what the
|
|
213
|
+
* plugin calls, and none names an operation no plugin may call (`isReservedApiRequest`). A revision published before
|
|
214
|
+
* these rules keeps loading, and the call itself is refused (`isApiRequestAllowed`), so a page loses one call, not
|
|
215
|
+
* the whole plugin. A placeholder deeper in the path can still cover a reserved operation (`POST /catalog/{kind}/{type}`):
|
|
216
|
+
* that too is refused at call time, on the path actually requested.
|
|
217
|
+
*/
|
|
218
|
+
export function validateAuthoredApiPermissions(manifest) {
|
|
219
|
+
(manifest.permissions?.api ?? []).forEach(({ method, path }, index) => {
|
|
220
|
+
const where = `permissions.api[${index}]`;
|
|
221
|
+
const [resource] = path.slice(1).split('/');
|
|
222
|
+
if (resource.startsWith('{') && resource.endsWith('}')) {
|
|
223
|
+
throw new ManifestError(`${where}.path must name its resource: "${resource}" cannot be the first segment`);
|
|
224
|
+
}
|
|
225
|
+
if (isReservedApiRequest(method, path)) {
|
|
226
|
+
throw new ManifestError(`${where}: plugins may not ${method === '*' ? 'call' : method} ${path}: it is reserved, because a plugin acts with the rights of whoever views it`);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return manifest;
|
|
230
|
+
}
|
|
222
231
|
/**
|
|
223
232
|
* Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
|
|
224
233
|
* block, its flag and its place in layouts, so the CLI warns about them.
|
package/dist/contract/when.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type WhenQuery = Record<string, unknown>;
|
|
|
10
10
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
11
11
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
12
12
|
*/
|
|
13
|
-
export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "
|
|
13
|
+
export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "user"];
|
|
14
14
|
export type ContextRoot = (typeof CONTEXT_ROOTS)[number];
|
|
15
15
|
export declare const WHEN_LIMITS: {
|
|
16
16
|
readonly depth: 16;
|
package/dist/contract/when.js
CHANGED
|
@@ -15,7 +15,7 @@ import sift from 'sift';
|
|
|
15
15
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
16
16
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
17
17
|
*/
|
|
18
|
-
export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', '
|
|
18
|
+
export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'user'];
|
|
19
19
|
/**
|
|
20
20
|
* In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN (or the
|
|
21
21
|
* scope's), so the platform never loads a deployment or a build and a condition on either would silently never match.
|
|
@@ -4,9 +4,9 @@ exports.isRequestAllowed = void 0;
|
|
|
4
4
|
exports.normalizePath = normalizePath;
|
|
5
5
|
exports.canonicalizePath = canonicalizePath;
|
|
6
6
|
exports.pathMatches = pathMatches;
|
|
7
|
+
exports.isReservedApiRequest = isReservedApiRequest;
|
|
7
8
|
exports.isApiRequestAllowed = isApiRequestAllowed;
|
|
8
9
|
exports.isHttpRequestAllowed = isHttpRequestAllowed;
|
|
9
|
-
exports.isUploadAllowed = isUploadAllowed;
|
|
10
10
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
11
11
|
function normalizePath(path) {
|
|
12
12
|
if (typeof path !== 'string' || !path.startsWith('/'))
|
|
@@ -50,6 +50,81 @@ function pathMatches(pattern, requestSegments) {
|
|
|
50
50
|
return segment === requestSegments[index];
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
+
// A plugin call runs with the token of whoever is looking at the page, so a manifest that names
|
|
54
|
+
// one of these would act with an administrator's rights for every administrator who opens it.
|
|
55
|
+
// Each entry is a path prefix: it reserves that path and everything under it.
|
|
56
|
+
const RESERVED_FOR_EVERY_METHOD = [
|
|
57
|
+
// Credentials.
|
|
58
|
+
['api_key'],
|
|
59
|
+
['pat'],
|
|
60
|
+
['token'],
|
|
61
|
+
];
|
|
62
|
+
const RESERVED_FOR_WRITES = [
|
|
63
|
+
// Who may do what.
|
|
64
|
+
['authz'],
|
|
65
|
+
['user'],
|
|
66
|
+
// Which code an organization runs.
|
|
67
|
+
['packages'],
|
|
68
|
+
['package_revision'],
|
|
69
|
+
['package_installations'],
|
|
70
|
+
['artifacts'],
|
|
71
|
+
['artifact_revision'],
|
|
72
|
+
['plugin_bundles'],
|
|
73
|
+
// Catalog lake ingest: it adds entities to the catalog.
|
|
74
|
+
['catalog', 'lake'],
|
|
75
|
+
];
|
|
76
|
+
// Writes under a prefix reserved for writes that a plugin may still make. Each is exact: one
|
|
77
|
+
// method, never `*` (which would cover the other writes too), and one path, never a prefix, where
|
|
78
|
+
// `{id}` matches one segment.
|
|
79
|
+
const ALLOWED_UNDER_RESERVED = [
|
|
80
|
+
// Asks whether the viewer may do something; it grants nothing.
|
|
81
|
+
['POST', '/authz/check'],
|
|
82
|
+
// What the authz backoffice (nullplatform/frontend-authz-backoffice) writes. Allowed for now,
|
|
83
|
+
// to every plugin: nothing yet tells a platform plugin from a customer's (BAC-3552).
|
|
84
|
+
['POST', '/authz/role'],
|
|
85
|
+
['PATCH', '/authz/role/{id}'],
|
|
86
|
+
['POST', '/authz/role/{id}/action'],
|
|
87
|
+
['POST', '/authz/action'],
|
|
88
|
+
['PATCH', '/authz/action/{id}'],
|
|
89
|
+
['POST', '/authz/action_group'],
|
|
90
|
+
['PATCH', '/authz/action_group/{id}'],
|
|
91
|
+
['DELETE', '/authz/action_group/{id}'],
|
|
92
|
+
['POST', '/authz/role_hierarchy'],
|
|
93
|
+
['DELETE', '/authz/role_hierarchy/{id}'],
|
|
94
|
+
['POST', '/authz/role_action_modifier'],
|
|
95
|
+
['DELETE', '/authz/role_action_modifier/{id}'],
|
|
96
|
+
];
|
|
97
|
+
// `*` counts as a write: a permission declared with it covers the writes too.
|
|
98
|
+
const WRITE_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE', '*']);
|
|
99
|
+
function startsWith(segments, prefix) {
|
|
100
|
+
return prefix.length <= segments.length && prefix.every((segment, index) => segments[index].toLowerCase() === segment);
|
|
101
|
+
}
|
|
102
|
+
function isAllowedUnderReserved(verb, segments) {
|
|
103
|
+
return ALLOWED_UNDER_RESERVED.some(([method, path]) => {
|
|
104
|
+
const pattern = path.split('/').slice(1);
|
|
105
|
+
return (method === verb &&
|
|
106
|
+
pattern.length === segments.length &&
|
|
107
|
+
pattern.every((segment, index) => (segment === '{id}' ? segments[index].length > 0 : segments[index].toLowerCase() === segment)));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function isReservedSegments(method, segments) {
|
|
111
|
+
if (RESERVED_FOR_EVERY_METHOD.some((prefix) => startsWith(segments, prefix)))
|
|
112
|
+
return true;
|
|
113
|
+
const verb = method.toUpperCase();
|
|
114
|
+
if (!WRITE_METHODS.has(verb))
|
|
115
|
+
return false;
|
|
116
|
+
if (isAllowedUnderReserved(verb, segments))
|
|
117
|
+
return false;
|
|
118
|
+
return RESERVED_FOR_WRITES.some((prefix) => startsWith(segments, prefix));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* True when no plugin may call `method` on `path`, whatever its manifest declares. A path that
|
|
122
|
+
* does not normalize is not reserved: `isApiRequestAllowed` already refuses it.
|
|
123
|
+
*/
|
|
124
|
+
function isReservedApiRequest(method, path) {
|
|
125
|
+
const segments = normalizePath(path);
|
|
126
|
+
return segments !== null && isReservedSegments(method, segments);
|
|
127
|
+
}
|
|
53
128
|
/**
|
|
54
129
|
* Decides whether a plugin API request (a nullplatform public API path) is covered
|
|
55
130
|
* by its declared `permissions.api`. Query strings are never part of the decision.
|
|
@@ -61,6 +136,9 @@ function isApiRequestAllowed(permissions, method, path) {
|
|
|
61
136
|
const requestSegments = normalizePath(path);
|
|
62
137
|
if (!requestSegments)
|
|
63
138
|
return false;
|
|
139
|
+
// Checked on the request, not on the declared patterns, so a placeholder cannot reach one.
|
|
140
|
+
if (isReservedSegments(requestMethod, requestSegments))
|
|
141
|
+
return false;
|
|
64
142
|
return permissions.some((permission) => (permission.method === '*' || permission.method === requestMethod) && pathMatches(permission.path, requestSegments));
|
|
65
143
|
}
|
|
66
144
|
/** @deprecated use `isApiRequestAllowed`. */
|
|
@@ -91,29 +169,3 @@ function isHttpRequestAllowed(permissions, method, url) {
|
|
|
91
169
|
(permission.method === '*' || permission.method === requestMethod) &&
|
|
92
170
|
pathMatches(permission.path, requestSegments));
|
|
93
171
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Decides whether a file may be uploaded to `url` under `permissions.upload`: https only, no credentials in the URL,
|
|
96
|
-
* and a declared host. An exact host matches itself (port included when declared); `*.example.com` matches every
|
|
97
|
-
* host under `example.com` on the default port, never `example.com` itself. The path and the query are the
|
|
98
|
-
* upload's own business: a presigned POST goes to `/`.
|
|
99
|
-
*/
|
|
100
|
-
function isUploadAllowed(permissions, url) {
|
|
101
|
-
if (!permissions?.length)
|
|
102
|
-
return false;
|
|
103
|
-
let parsed;
|
|
104
|
-
try {
|
|
105
|
-
parsed = new URL(url);
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (parsed.protocol !== 'https:' || parsed.username || parsed.password)
|
|
111
|
-
return false;
|
|
112
|
-
const host = parsed.host.toLowerCase();
|
|
113
|
-
return permissions.some((permission) => {
|
|
114
|
-
const declared = permission.host.toLowerCase();
|
|
115
|
-
if (!declared.startsWith('*.'))
|
|
116
|
-
return declared === host;
|
|
117
|
-
return !parsed.port && host.endsWith(declared.slice(1));
|
|
118
|
-
});
|
|
119
|
-
}
|
|
@@ -1,10 +1,11 @@
|
|
|
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.matchFixture = exports.canonicalizePath = exports.normalizePath = exports.
|
|
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.isReservedApiRequest = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.isPageTemplateDefinition = exports.pageTemplateProblems = exports.MIN_PAGE_AREA_WIDTH = exports.REQUIRED_PAGE_AREA = exports.PAGE_AREAS = exports.layoutConflicts = exports.pageOf = exports.readPlaceRoots = exports.contextSatisfies = exports.missingContext = exports.PLACE_ROOTS = exports.ManifestError = exports.isSectionSlot = exports.RESERVED_PLUGIN_ID = exports.contributionId = exports.unnamedContributions = exports.validateAuthoredApiPermissions = exports.validatePublishableManifest = 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; } });
|
|
7
7
|
Object.defineProperty(exports, "validatePublishableManifest", { enumerable: true, get: function () { return manifest_1.validatePublishableManifest; } });
|
|
8
|
+
Object.defineProperty(exports, "validateAuthoredApiPermissions", { enumerable: true, get: function () { return manifest_1.validateAuthoredApiPermissions; } });
|
|
8
9
|
Object.defineProperty(exports, "unnamedContributions", { enumerable: true, get: function () { return manifest_1.unnamedContributions; } });
|
|
9
10
|
Object.defineProperty(exports, "contributionId", { enumerable: true, get: function () { return manifest_1.contributionId; } });
|
|
10
11
|
Object.defineProperty(exports, "RESERVED_PLUGIN_ID", { enumerable: true, get: function () { return manifest_1.RESERVED_PLUGIN_ID; } });
|
|
@@ -27,8 +28,8 @@ Object.defineProperty(exports, "isPageTemplateDefinition", { enumerable: true, g
|
|
|
27
28
|
var allowlist_1 = require("./allowlist");
|
|
28
29
|
Object.defineProperty(exports, "isApiRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isApiRequestAllowed; } });
|
|
29
30
|
Object.defineProperty(exports, "isHttpRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isHttpRequestAllowed; } });
|
|
30
|
-
Object.defineProperty(exports, "isUploadAllowed", { enumerable: true, get: function () { return allowlist_1.isUploadAllowed; } });
|
|
31
31
|
Object.defineProperty(exports, "isRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isRequestAllowed; } });
|
|
32
|
+
Object.defineProperty(exports, "isReservedApiRequest", { enumerable: true, get: function () { return allowlist_1.isReservedApiRequest; } });
|
|
32
33
|
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return allowlist_1.normalizePath; } });
|
|
33
34
|
Object.defineProperty(exports, "canonicalizePath", { enumerable: true, get: function () { return allowlist_1.canonicalizePath; } });
|
|
34
35
|
var fixtures_1 = require("./fixtures");
|
|
@@ -5,10 +5,12 @@ exports.isSectionSlot = isSectionSlot;
|
|
|
5
5
|
exports.validateManifest = validateManifest;
|
|
6
6
|
exports.contributionId = contributionId;
|
|
7
7
|
exports.validatePublishableManifest = validatePublishableManifest;
|
|
8
|
+
exports.validateAuthoredApiPermissions = validateAuthoredApiPermissions;
|
|
8
9
|
exports.unnamedContributions = unnamedContributions;
|
|
9
10
|
const when_1 = require("./when");
|
|
10
11
|
const topics_1 = require("./topics");
|
|
11
12
|
const context_1 = require("./context");
|
|
13
|
+
const allowlist_1 = require("./allowlist");
|
|
12
14
|
exports.PROTOCOL_VERSION = 1;
|
|
13
15
|
class ManifestError extends Error {
|
|
14
16
|
constructor(message) {
|
|
@@ -20,8 +22,6 @@ exports.ManifestError = ManifestError;
|
|
|
20
22
|
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
21
23
|
const SLOT_PATTERN = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/;
|
|
22
24
|
const HOST_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+(:[0-9]{1,5})?$/;
|
|
23
|
-
/** `*.` and a domain of two labels or more: `*.amazonaws.com`, never `*.com`. No port. */
|
|
24
|
-
const WILDCARD_HOST_PATTERN = /^\*(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}$/;
|
|
25
25
|
const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', '*']);
|
|
26
26
|
function isSectionSlot(slot) {
|
|
27
27
|
return slot.endsWith('.section');
|
|
@@ -104,7 +104,8 @@ function validateManifest(input) {
|
|
|
104
104
|
permissions.api = rawPermissions.api.map((raw, index) => {
|
|
105
105
|
const p = (raw ?? {});
|
|
106
106
|
const where = `permissions.api[${index}]`;
|
|
107
|
-
|
|
107
|
+
const method = readMethod(p.method, where);
|
|
108
|
+
return { method, path: readPath(p.path, where) };
|
|
108
109
|
});
|
|
109
110
|
}
|
|
110
111
|
if (rawPermissions.http !== undefined) {
|
|
@@ -119,18 +120,6 @@ function validateManifest(input) {
|
|
|
119
120
|
return { host, method: readMethod(p.method, where), path: readPath(p.path, where) };
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
|
-
if (rawPermissions.upload !== undefined) {
|
|
123
|
-
if (!Array.isArray(rawPermissions.upload))
|
|
124
|
-
throw new ManifestError('permissions.upload must be an array');
|
|
125
|
-
permissions.upload = rawPermissions.upload.map((raw, index) => {
|
|
126
|
-
const p = (raw ?? {});
|
|
127
|
-
const host = typeof p.host === 'string' ? p.host.toLowerCase() : '';
|
|
128
|
-
if (!HOST_PATTERN.test(host) && !WILDCARD_HOST_PATTERN.test(host)) {
|
|
129
|
-
throw new ManifestError(`permissions.upload[${index}].host must be a hostname (optional port) or "*." and a domain of two labels or more, no scheme`);
|
|
130
|
-
}
|
|
131
|
-
return { host };
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
123
|
if (rawPermissions.topics !== undefined) {
|
|
135
124
|
permissions.topics = readTopicPermissions(rawPermissions.topics, m.id);
|
|
136
125
|
}
|
|
@@ -228,6 +217,27 @@ function validatePublishableManifest(input) {
|
|
|
228
217
|
});
|
|
229
218
|
return manifest;
|
|
230
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* What a manifest's `permissions.api` must meet where the manifest is written: at publish and in developer mode, never
|
|
222
|
+
* where a stored revision is read. Each path names its resource, so a reviewer reading the manifest sees what the
|
|
223
|
+
* plugin calls, and none names an operation no plugin may call (`isReservedApiRequest`). A revision published before
|
|
224
|
+
* these rules keeps loading, and the call itself is refused (`isApiRequestAllowed`), so a page loses one call, not
|
|
225
|
+
* the whole plugin. A placeholder deeper in the path can still cover a reserved operation (`POST /catalog/{kind}/{type}`):
|
|
226
|
+
* that too is refused at call time, on the path actually requested.
|
|
227
|
+
*/
|
|
228
|
+
function validateAuthoredApiPermissions(manifest) {
|
|
229
|
+
(manifest.permissions?.api ?? []).forEach(({ method, path }, index) => {
|
|
230
|
+
const where = `permissions.api[${index}]`;
|
|
231
|
+
const [resource] = path.slice(1).split('/');
|
|
232
|
+
if (resource.startsWith('{') && resource.endsWith('}')) {
|
|
233
|
+
throw new ManifestError(`${where}.path must name its resource: "${resource}" cannot be the first segment`);
|
|
234
|
+
}
|
|
235
|
+
if ((0, allowlist_1.isReservedApiRequest)(method, path)) {
|
|
236
|
+
throw new ManifestError(`${where}: plugins may not ${method === '*' ? 'call' : method} ${path}: it is reserved, because a plugin acts with the rights of whoever views it`);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return manifest;
|
|
240
|
+
}
|
|
231
241
|
/**
|
|
232
242
|
* Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
|
|
233
243
|
* block, its flag and its place in layouts, so the CLI warns about them.
|
|
@@ -25,7 +25,7 @@ const sift_1 = __importDefault(require("sift"));
|
|
|
25
25
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
26
26
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
27
27
|
*/
|
|
28
|
-
exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', '
|
|
28
|
+
exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'user'];
|
|
29
29
|
/**
|
|
30
30
|
* In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN (or the
|
|
31
31
|
* scope's), so the platform never loads a deployment or a build and a condition on either would silently never match.
|
package/dist/contractProps.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { UI_COMPONENTS_CONTRACTS } from "./contracts.generated.js";
|
|
3
|
+
import type { CalendarEvent, CalendarSlot, CalendarTimelineBar, CalendarTimelineRow } from "./calendar.js";
|
|
3
4
|
import type { DataTableColumn, DataTablePagination, DataTableRow, DataTableState } from "./dataTable.js";
|
|
5
|
+
import type { FilterSingleDateChange, FilterSingleDatePreset } from "./filterSingleDate.js";
|
|
4
6
|
type Contract = (typeof UI_COMPONENTS_CONTRACTS)[number];
|
|
5
7
|
/** The elements the SDK takes from @nullplatform/react-ui-components' contracts. */
|
|
6
8
|
export type UiComponentsTag = Contract["tag"];
|
|
@@ -27,6 +29,35 @@ interface ContractPropTypes {
|
|
|
27
29
|
onChangeTableState?: (state: DataTableState) => void;
|
|
28
30
|
onRowClick?: (row: DataTableRow) => void;
|
|
29
31
|
};
|
|
32
|
+
"np-calendar-month": {
|
|
33
|
+
events?: readonly CalendarEvent[];
|
|
34
|
+
onEventPress?: (id: string) => void;
|
|
35
|
+
/** A `YYYY-MM-DD` day. */
|
|
36
|
+
onDayPress?: (day: string) => void;
|
|
37
|
+
onMorePress?: (day: string) => void;
|
|
38
|
+
};
|
|
39
|
+
"np-calendar-week": {
|
|
40
|
+
events?: readonly CalendarEvent[];
|
|
41
|
+
onEventPress?: (id: string) => void;
|
|
42
|
+
onSlotPress?: (slot: CalendarSlot) => void;
|
|
43
|
+
};
|
|
44
|
+
"np-calendar-timeline": {
|
|
45
|
+
rows?: readonly CalendarTimelineRow[];
|
|
46
|
+
bars?: readonly CalendarTimelineBar[];
|
|
47
|
+
/** The timeline reads only these two. */
|
|
48
|
+
emptyStateProps?: {
|
|
49
|
+
title?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
};
|
|
52
|
+
onBarPress?: (id: string) => void;
|
|
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
|
+
};
|
|
30
61
|
}
|
|
31
62
|
type Typed<Tag, Props> = Tag extends keyof ContractPropTypes ? Omit<Props, keyof ContractPropTypes[Tag]> & Pick<ContractPropTypes[Tag], Extract<keyof ContractPropTypes[Tag], keyof Props>> : Props;
|
|
32
63
|
/**
|
|
@@ -693,6 +693,9 @@ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
|
|
|
693
693
|
readonly now: "string";
|
|
694
694
|
readonly locale: "string";
|
|
695
695
|
readonly resourceLabel: "string";
|
|
696
|
+
readonly loading: "boolean";
|
|
697
|
+
readonly emptyStateProps: "object";
|
|
698
|
+
readonly maxRows: "number";
|
|
696
699
|
};
|
|
697
700
|
readonly events: {
|
|
698
701
|
readonly barPress: "onBarPress";
|
|
@@ -765,4 +768,158 @@ export declare const UI_COMPONENTS_CONTRACTS: readonly [{
|
|
|
765
768
|
readonly events: {
|
|
766
769
|
readonly change: "onChange";
|
|
767
770
|
};
|
|
771
|
+
}, {
|
|
772
|
+
readonly tag: "np-checkbox";
|
|
773
|
+
readonly component: "Checkbox";
|
|
774
|
+
readonly properties: {
|
|
775
|
+
readonly checked: "boolean";
|
|
776
|
+
readonly disabled: "boolean";
|
|
777
|
+
};
|
|
778
|
+
readonly events: {
|
|
779
|
+
readonly change: "onChange";
|
|
780
|
+
};
|
|
781
|
+
}, {
|
|
782
|
+
readonly tag: "np-checkbox-card";
|
|
783
|
+
readonly component: "CheckboxCard";
|
|
784
|
+
readonly properties: {
|
|
785
|
+
readonly label: "string";
|
|
786
|
+
readonly description: "string";
|
|
787
|
+
readonly icon: "string";
|
|
788
|
+
readonly checked: "boolean";
|
|
789
|
+
readonly size: "string";
|
|
790
|
+
readonly variant: "string";
|
|
791
|
+
readonly align: "string";
|
|
792
|
+
readonly justify: "string";
|
|
793
|
+
readonly orientation: "string";
|
|
794
|
+
readonly indicator: "boolean";
|
|
795
|
+
readonly disabled: "boolean";
|
|
796
|
+
readonly readOnly: "boolean";
|
|
797
|
+
readonly error: "boolean";
|
|
798
|
+
};
|
|
799
|
+
readonly events: {
|
|
800
|
+
readonly change: "onChange";
|
|
801
|
+
};
|
|
802
|
+
readonly values: {
|
|
803
|
+
readonly size: readonly ["sm", "md", "lg"];
|
|
804
|
+
readonly variant: readonly ["outline", "surface", "subtle", "solid"];
|
|
805
|
+
readonly align: readonly ["start", "end", "center"];
|
|
806
|
+
readonly justify: readonly ["start", "end", "center"];
|
|
807
|
+
readonly orientation: readonly ["horizontal", "vertical"];
|
|
808
|
+
};
|
|
809
|
+
}, {
|
|
810
|
+
readonly tag: "np-slider";
|
|
811
|
+
readonly component: "Slider";
|
|
812
|
+
readonly properties: {
|
|
813
|
+
readonly value: "number";
|
|
814
|
+
readonly min: "number";
|
|
815
|
+
readonly max: "number";
|
|
816
|
+
readonly step: "number";
|
|
817
|
+
readonly disabled: "boolean";
|
|
818
|
+
readonly "aria-label": "string";
|
|
819
|
+
};
|
|
820
|
+
readonly events: {
|
|
821
|
+
readonly change: "onChange";
|
|
822
|
+
readonly changeCommitted: "onChangeCommitted";
|
|
823
|
+
};
|
|
824
|
+
}, {
|
|
825
|
+
readonly tag: "np-accordion";
|
|
826
|
+
readonly component: "Accordion";
|
|
827
|
+
readonly properties: {
|
|
828
|
+
readonly expanded: "boolean";
|
|
829
|
+
readonly defaultExpanded: "boolean";
|
|
830
|
+
readonly disabled: "boolean";
|
|
831
|
+
readonly disableGutters: "boolean";
|
|
832
|
+
};
|
|
833
|
+
readonly events: {
|
|
834
|
+
readonly change: "onChange";
|
|
835
|
+
};
|
|
836
|
+
readonly children: true;
|
|
837
|
+
}, {
|
|
838
|
+
readonly tag: "np-accordion-summary";
|
|
839
|
+
readonly component: "AccordionSummary";
|
|
840
|
+
readonly properties: {};
|
|
841
|
+
readonly events: {};
|
|
842
|
+
readonly slots: readonly ["expandIcon"];
|
|
843
|
+
readonly children: true;
|
|
844
|
+
}, {
|
|
845
|
+
readonly tag: "np-accordion-details";
|
|
846
|
+
readonly component: "AccordionDetails";
|
|
847
|
+
readonly properties: {};
|
|
848
|
+
readonly events: {};
|
|
849
|
+
readonly children: true;
|
|
850
|
+
}, {
|
|
851
|
+
readonly tag: "np-date-picker";
|
|
852
|
+
readonly component: "DatePickerField";
|
|
853
|
+
readonly properties: {
|
|
854
|
+
readonly value: "string";
|
|
855
|
+
readonly minDate: "string";
|
|
856
|
+
readonly maxDate: "string";
|
|
857
|
+
readonly timeZone: "string";
|
|
858
|
+
readonly label: "string";
|
|
859
|
+
readonly helperText: "string";
|
|
860
|
+
readonly error: "boolean";
|
|
861
|
+
readonly disabled: "boolean";
|
|
862
|
+
};
|
|
863
|
+
readonly events: {
|
|
864
|
+
readonly change: "onChange";
|
|
865
|
+
};
|
|
866
|
+
}, {
|
|
867
|
+
readonly tag: "np-filter-single-date";
|
|
868
|
+
readonly component: "FilterSingleDateField";
|
|
869
|
+
readonly properties: {
|
|
870
|
+
readonly value: "string";
|
|
871
|
+
readonly preset: "string";
|
|
872
|
+
readonly presets: "array";
|
|
873
|
+
readonly timeZone: "string";
|
|
874
|
+
readonly label: "string";
|
|
875
|
+
readonly placeholder: "string";
|
|
876
|
+
readonly customLabel: "string";
|
|
877
|
+
readonly helperText: "string";
|
|
878
|
+
readonly error: "boolean";
|
|
879
|
+
readonly required: "boolean";
|
|
880
|
+
readonly disabled: "boolean";
|
|
881
|
+
readonly minDate: "string";
|
|
882
|
+
readonly maxDate: "string";
|
|
883
|
+
readonly disablePast: "boolean";
|
|
884
|
+
readonly disableFuture: "boolean";
|
|
885
|
+
readonly hideActionButtons: "boolean";
|
|
886
|
+
};
|
|
887
|
+
readonly events: {
|
|
888
|
+
readonly change: "onChange";
|
|
889
|
+
};
|
|
890
|
+
}, {
|
|
891
|
+
readonly tag: "np-stepper";
|
|
892
|
+
readonly component: "Stepper";
|
|
893
|
+
readonly properties: {
|
|
894
|
+
readonly activeStep: "number";
|
|
895
|
+
readonly orientation: "string";
|
|
896
|
+
readonly alternativeLabel: "boolean";
|
|
897
|
+
readonly nonLinear: "boolean";
|
|
898
|
+
};
|
|
899
|
+
readonly events: {};
|
|
900
|
+
readonly values: {
|
|
901
|
+
readonly orientation: readonly ["horizontal", "vertical"];
|
|
902
|
+
};
|
|
903
|
+
readonly children: true;
|
|
904
|
+
}, {
|
|
905
|
+
readonly tag: "np-step";
|
|
906
|
+
readonly component: "Step";
|
|
907
|
+
readonly properties: {
|
|
908
|
+
readonly index: "number";
|
|
909
|
+
readonly last: "boolean";
|
|
910
|
+
readonly active: "boolean";
|
|
911
|
+
readonly completed: "boolean";
|
|
912
|
+
readonly disabled: "boolean";
|
|
913
|
+
};
|
|
914
|
+
readonly events: {};
|
|
915
|
+
readonly children: true;
|
|
916
|
+
}, {
|
|
917
|
+
readonly tag: "np-step-label";
|
|
918
|
+
readonly component: "StepLabel";
|
|
919
|
+
readonly properties: {
|
|
920
|
+
readonly error: "boolean";
|
|
921
|
+
};
|
|
922
|
+
readonly events: {};
|
|
923
|
+
readonly slots: readonly ["optional"];
|
|
924
|
+
readonly children: true;
|
|
768
925
|
}];
|