@nullplatform/ui-plugin-sdk 0.20.0-beta.0 → 0.21.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.
@@ -41,6 +41,81 @@ export function pathMatches(pattern, requestSegments) {
41
41
  return segment === requestSegments[index];
42
42
  });
43
43
  }
44
+ // A plugin call runs with the token of whoever is looking at the page, so a manifest that names
45
+ // one of these would act with an administrator's rights for every administrator who opens it.
46
+ // Each entry is a path prefix: it reserves that path and everything under it.
47
+ const RESERVED_FOR_EVERY_METHOD = [
48
+ // Credentials.
49
+ ['api_key'],
50
+ ['pat'],
51
+ ['token'],
52
+ ];
53
+ const RESERVED_FOR_WRITES = [
54
+ // Who may do what.
55
+ ['authz'],
56
+ ['user'],
57
+ // Which code an organization runs.
58
+ ['packages'],
59
+ ['package_revision'],
60
+ ['package_installations'],
61
+ ['artifacts'],
62
+ ['artifact_revision'],
63
+ ['plugin_bundles'],
64
+ // Catalog lake ingest: it adds entities to the catalog.
65
+ ['catalog', 'lake'],
66
+ ];
67
+ // Writes under a prefix reserved for writes that a plugin may still make. Each is exact: one
68
+ // method, never `*` (which would cover the other writes too), and one path, never a prefix, where
69
+ // `{id}` matches one segment.
70
+ const ALLOWED_UNDER_RESERVED = [
71
+ // Asks whether the viewer may do something; it grants nothing.
72
+ ['POST', '/authz/check'],
73
+ // What the authz backoffice (nullplatform/frontend-authz-backoffice) writes. Allowed for now,
74
+ // to every plugin: nothing yet tells a platform plugin from a customer's (BAC-3552).
75
+ ['POST', '/authz/role'],
76
+ ['PATCH', '/authz/role/{id}'],
77
+ ['POST', '/authz/role/{id}/action'],
78
+ ['POST', '/authz/action'],
79
+ ['PATCH', '/authz/action/{id}'],
80
+ ['POST', '/authz/action_group'],
81
+ ['PATCH', '/authz/action_group/{id}'],
82
+ ['DELETE', '/authz/action_group/{id}'],
83
+ ['POST', '/authz/role_hierarchy'],
84
+ ['DELETE', '/authz/role_hierarchy/{id}'],
85
+ ['POST', '/authz/role_action_modifier'],
86
+ ['DELETE', '/authz/role_action_modifier/{id}'],
87
+ ];
88
+ // `*` counts as a write: a permission declared with it covers the writes too.
89
+ const WRITE_METHODS = new Set(['POST', 'PUT', 'PATCH', 'DELETE', '*']);
90
+ function startsWith(segments, prefix) {
91
+ return prefix.length <= segments.length && prefix.every((segment, index) => segments[index].toLowerCase() === segment);
92
+ }
93
+ function isAllowedUnderReserved(verb, segments) {
94
+ return ALLOWED_UNDER_RESERVED.some(([method, path]) => {
95
+ const pattern = path.split('/').slice(1);
96
+ return (method === verb &&
97
+ pattern.length === segments.length &&
98
+ pattern.every((segment, index) => (segment === '{id}' ? segments[index].length > 0 : segments[index].toLowerCase() === segment)));
99
+ });
100
+ }
101
+ function isReservedSegments(method, segments) {
102
+ if (RESERVED_FOR_EVERY_METHOD.some((prefix) => startsWith(segments, prefix)))
103
+ return true;
104
+ const verb = method.toUpperCase();
105
+ if (!WRITE_METHODS.has(verb))
106
+ return false;
107
+ if (isAllowedUnderReserved(verb, segments))
108
+ return false;
109
+ return RESERVED_FOR_WRITES.some((prefix) => startsWith(segments, prefix));
110
+ }
111
+ /**
112
+ * True when no plugin may call `method` on `path`, whatever its manifest declares. A path that
113
+ * does not normalize is not reserved: `isApiRequestAllowed` already refuses it.
114
+ */
115
+ export function isReservedApiRequest(method, path) {
116
+ const segments = normalizePath(path);
117
+ return segments !== null && isReservedSegments(method, segments);
118
+ }
44
119
  /**
45
120
  * Decides whether a plugin API request (a nullplatform public API path) is covered
46
121
  * by its declared `permissions.api`. Query strings are never part of the decision.
@@ -52,6 +127,9 @@ export function isApiRequestAllowed(permissions, method, path) {
52
127
  const requestSegments = normalizePath(path);
53
128
  if (!requestSegments)
54
129
  return false;
130
+ // Checked on the request, not on the declared patterns, so a placeholder cannot reach one.
131
+ if (isReservedSegments(requestMethod, requestSegments))
132
+ return false;
55
133
  return permissions.some((permission) => (permission.method === '*' || permission.method === requestMethod) && pathMatches(permission.path, requestSegments));
56
134
  }
57
135
  /** @deprecated use `isApiRequestAllowed`. */
@@ -82,29 +160,3 @@ export function isHttpRequestAllowed(permissions, method, url) {
82
160
  (permission.method === '*' || permission.method === requestMethod) &&
83
161
  pathMatches(permission.path, requestSegments));
84
162
  }
85
- /**
86
- * Decides whether a file may be uploaded to `url` under `permissions.upload`: https only, no credentials in the URL,
87
- * and a declared host. An exact host matches itself (port included when declared); `*.example.com` matches every
88
- * host under `example.com` on the default port, never `example.com` itself. The path and the query are the
89
- * upload's own business: a presigned POST goes to `/`.
90
- */
91
- export function isUploadAllowed(permissions, url) {
92
- if (!permissions?.length)
93
- return false;
94
- let parsed;
95
- try {
96
- parsed = new URL(url);
97
- }
98
- catch {
99
- return false;
100
- }
101
- if (parsed.protocol !== 'https:' || parsed.username || parsed.password)
102
- return false;
103
- const host = parsed.host.toLowerCase();
104
- return permissions.some((permission) => {
105
- const declared = permission.host.toLowerCase();
106
- if (!declared.startsWith('*.'))
107
- return declared === host;
108
- return !parsed.port && host.endsWith(declared.slice(1));
109
- });
110
- }
@@ -1,8 +1,8 @@
1
- export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type UploadPermission, type HttpMethod, } from './manifest.js';
1
+ export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, validateAuthoredApiPermissions, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
2
2
  export { PLACE_ROOTS, missingContext, contextSatisfies, readPlaceRoots, type PlaceRoot } from './context.js';
3
3
  export { pageOf, layoutConflicts, type LayoutConflict } from './layout.js';
4
4
  export { PAGE_AREAS, REQUIRED_PAGE_AREA, MIN_PAGE_AREA_WIDTH, pageTemplateProblems, isPageTemplateDefinition, type PageArea, type PageTemplateBreakpoint, type PageTemplateDefinition, type PageTemplateResponsive, type PageTemplateTracks, } from './pageTemplate.js';
5
- export { isApiRequestAllowed, isHttpRequestAllowed, isUploadAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
5
+ export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, isReservedApiRequest, normalizePath, canonicalizePath } from './allowlist.js';
6
6
  export { matchFixture, type Fixtures, type FixtureMatch } from './fixtures.js';
7
7
  export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, type WhenQuery, type ContextRoot, type Rollout, } from './when.js';
8
8
  export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
@@ -1,8 +1,8 @@
1
- export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, } from './manifest.js';
1
+ export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, validateAuthoredApiPermissions, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, } from './manifest.js';
2
2
  export { PLACE_ROOTS, missingContext, contextSatisfies, readPlaceRoots } from './context.js';
3
3
  export { pageOf, layoutConflicts } from './layout.js';
4
4
  export { PAGE_AREAS, REQUIRED_PAGE_AREA, MIN_PAGE_AREA_WIDTH, pageTemplateProblems, isPageTemplateDefinition, } from './pageTemplate.js';
5
- export { isApiRequestAllowed, isHttpRequestAllowed, isUploadAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
5
+ export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, isReservedApiRequest, normalizePath, canonicalizePath } from './allowlist.js';
6
6
  export { matchFixture } from './fixtures.js';
7
7
  export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, } from './when.js';
8
8
  export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
@@ -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
- return { method: readMethod(p.method, where), path: readPath(p.path, where) };
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.
@@ -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", "service", "user"];
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;
@@ -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', 'service', 'user'];
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.isRequestAllowed = exports.isUploadAllowed = 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.validatePublishableManifest = 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.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
- return { method: readMethod(p.method, where), path: readPath(p.path, where) };
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', 'service', 'user'];
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.
@@ -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 { DataTableColumn, DataTablePagination, DataTableRow, DataTableState } from "./dataTable.js";
3
+ import type { CalendarEvent, CalendarSlot, CalendarTimelineBar, CalendarTimelineRow } from "./calendar.js";
4
+ import type { DataTableColumn, DataTableEmptyState, DataTableGrouping, 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"];
@@ -24,9 +26,45 @@ interface ContractPropTypes {
24
26
  data?: readonly DataTableRow[];
25
27
  initialState?: DataTableState;
26
28
  paginationProps?: DataTablePagination;
29
+ /**
30
+ * The name of a boolean row field: only rows where it is `true` look and act clickable. Without it, every row is
31
+ * while `onRowClick` is set. A clickable row takes keyboard focus, and Enter or Space clicks it.
32
+ */
33
+ isRowClickable?: string;
34
+ emptyStateProps?: DataTableEmptyState;
35
+ grouping?: DataTableGrouping;
27
36
  onChangeTableState?: (state: DataTableState) => void;
28
37
  onRowClick?: (row: DataTableRow) => void;
29
38
  };
39
+ "np-calendar-month": {
40
+ events?: readonly CalendarEvent[];
41
+ onEventPress?: (id: string) => void;
42
+ /** A `YYYY-MM-DD` day. */
43
+ onDayPress?: (day: string) => void;
44
+ onMorePress?: (day: string) => void;
45
+ };
46
+ "np-calendar-week": {
47
+ events?: readonly CalendarEvent[];
48
+ onEventPress?: (id: string) => void;
49
+ onSlotPress?: (slot: CalendarSlot) => void;
50
+ };
51
+ "np-calendar-timeline": {
52
+ rows?: readonly CalendarTimelineRow[];
53
+ bars?: readonly CalendarTimelineBar[];
54
+ /** The timeline reads only these two. */
55
+ emptyStateProps?: {
56
+ title?: string;
57
+ description?: string;
58
+ };
59
+ onBarPress?: (id: string) => void;
60
+ };
61
+ "np-filter-single-date": {
62
+ /** `null` as on `onChange`, so a controlled field takes its change back: the host drops it like a missing value. */
63
+ value?: string | null;
64
+ preset?: string | null;
65
+ presets?: readonly FilterSingleDatePreset[];
66
+ onChange?: (change: FilterSingleDateChange) => void;
67
+ };
30
68
  }
31
69
  type Typed<Tag, Props> = Tag extends keyof ContractPropTypes ? Omit<Props, keyof ContractPropTypes[Tag]> & Pick<ContractPropTypes[Tag], Extract<keyof ContractPropTypes[Tag], keyof Props>> : Props;
32
70
  /**