@nullplatform/ui-plugin-sdk 0.16.0 → 0.17.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.
@@ -1,4 +1,4 @@
1
- export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
1
+ export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
2
2
  export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
3
3
  export { matchFixture, type Fixtures, type FixtureMatch } from './fixtures.js';
4
4
  export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, type WhenQuery, type ContextRoot, type Rollout, } from './when.js';
@@ -1,4 +1,4 @@
1
- export { PROTOCOL_VERSION, validateManifest, isSectionSlot, ManifestError, } from './manifest.js';
1
+ export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, } from './manifest.js';
2
2
  export { isApiRequestAllowed, isHttpRequestAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
3
3
  export { matchFixture } from './fixtures.js';
4
4
  export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, } from './when.js';
@@ -51,3 +51,27 @@ export declare class ManifestError extends Error {
51
51
  export declare function isSectionSlot(slot: string): boolean;
52
52
  /** Validates an untrusted manifest object; throws `ManifestError` describing the first problem. */
53
53
  export declare function validateManifest(input: unknown): PluginManifest;
54
+ /** The platform's own blocks are `nullplatform/<block>`: no plugin may publish under that id (contract 5). */
55
+ export declare const RESERVED_PLUGIN_ID = "nullplatform";
56
+ /**
57
+ * The id a contribution goes by in block ids, flag keys and layouts: its `id`, or its widget for a revision published
58
+ * before ids were required (contract 5). One function, so every reader names an inherited contribution the same way.
59
+ */
60
+ export declare function contributionId(contribution: {
61
+ id?: string;
62
+ widget?: string;
63
+ }): string | undefined;
64
+ /**
65
+ * What a new revision must meet on top of `validateManifest` (contract 5): each contribution goes by a name unique in
66
+ * the manifest, since layouts, flags and section URLs point at it. The name is its `id` (lowercase letters, digits or
67
+ * dashes, 2-64 chars) or, without one, its widget, which is how hosts already keyed it. So a manifest that never
68
+ * repeats a widget stays publishable as it is, and one that mounts a widget twice must tell the two apart with ids.
69
+ * The plugin may not be `nullplatform`. The API applies it at publish and the CLI before uploading, so an author learns
70
+ * it before the build is pushed. Revisions published before keep working: hosts name them with `contributionId`.
71
+ */
72
+ export declare function validatePublishableManifest(input: unknown): PluginManifest;
73
+ /**
74
+ * Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
75
+ * block, its flag and its place in layouts, so the CLI warns about them.
76
+ */
77
+ export declare function unnamedContributions(manifest: PluginManifest): string[];
@@ -155,3 +155,49 @@ function readTopicPermissions(raw, pluginId) {
155
155
  }
156
156
  return topics;
157
157
  }
158
+ /** The platform's own blocks are `nullplatform/<block>`: no plugin may publish under that id (contract 5). */
159
+ export const RESERVED_PLUGIN_ID = 'nullplatform';
160
+ /**
161
+ * The id a contribution goes by in block ids, flag keys and layouts: its `id`, or its widget for a revision published
162
+ * before ids were required (contract 5). One function, so every reader names an inherited contribution the same way.
163
+ */
164
+ export function contributionId(contribution) {
165
+ return contribution.id ?? contribution.widget;
166
+ }
167
+ /**
168
+ * What a new revision must meet on top of `validateManifest` (contract 5): each contribution goes by a name unique in
169
+ * the manifest, since layouts, flags and section URLs point at it. The name is its `id` (lowercase letters, digits or
170
+ * dashes, 2-64 chars) or, without one, its widget, which is how hosts already keyed it. So a manifest that never
171
+ * repeats a widget stays publishable as it is, and one that mounts a widget twice must tell the two apart with ids.
172
+ * The plugin may not be `nullplatform`. The API applies it at publish and the CLI before uploading, so an author learns
173
+ * it before the build is pushed. Revisions published before keep working: hosts name them with `contributionId`.
174
+ */
175
+ export function validatePublishableManifest(input) {
176
+ const manifest = validateManifest(input);
177
+ if (manifest.id === RESERVED_PLUGIN_ID)
178
+ throw new ManifestError(`Plugin id "${RESERVED_PLUGIN_ID}" is reserved for the platform's own blocks`);
179
+ // `validateManifest` drops an id that isn't a string; read the raw one so a malformed id is refused, not ignored.
180
+ const raw = input.contributes;
181
+ const seen = new Map();
182
+ manifest.contributes.forEach((contribution, index) => {
183
+ const id = raw[index]?.id;
184
+ if (id !== undefined && (typeof id !== 'string' || !ID_PATTERN.test(id))) {
185
+ throw new ManifestError(`contributes[${index}].id must be lowercase letters, digits or dashes (2-64 chars)`);
186
+ }
187
+ const name = contributionId(contribution);
188
+ const first = seen.get(name);
189
+ if (first !== undefined) {
190
+ const hint = contribution.id === undefined ? '; give each an id' : '';
191
+ throw new ManifestError(`contributes[${index}] goes by "${name}", already used by contributes[${first}]${hint}`);
192
+ }
193
+ seen.set(name, index);
194
+ });
195
+ return manifest;
196
+ }
197
+ /**
198
+ * Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
199
+ * block, its flag and its place in layouts, so the CLI warns about them.
200
+ */
201
+ export function unnamedContributions(manifest) {
202
+ return manifest.contributes.flatMap((contribution, index) => (contribution.id === undefined ? [`contributes[${index}] (${contribution.widget})`] : []));
203
+ }
@@ -1,9 +1,13 @@
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.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.ManifestError = exports.isSectionSlot = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
3
+ exports.assertTopicValue = exports.redactBySchema = exports.projectFields = exports.canProvideTopic = exports.consumeGrant = exports.isFieldPath = exports.topicOwner = exports.isHostTopic = exports.isTopicName = exports.TOPIC_VALUE_MAX_CHARS = exports.resolveAssetUrl = exports.validateStorageUrl = exports.PLUGIN_STORAGE_ORIGIN = exports.WhenError = exports.rolloutIncludes = exports.evaluateWhen = exports.validateWhen = exports.extractRoots = exports.CONTEXT_ROOTS = exports.matchFixture = exports.canonicalizePath = exports.normalizePath = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.ManifestError = exports.isSectionSlot = exports.RESERVED_PLUGIN_ID = exports.contributionId = exports.unnamedContributions = 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
+ Object.defineProperty(exports, "validatePublishableManifest", { enumerable: true, get: function () { return manifest_1.validatePublishableManifest; } });
8
+ Object.defineProperty(exports, "unnamedContributions", { enumerable: true, get: function () { return manifest_1.unnamedContributions; } });
9
+ Object.defineProperty(exports, "contributionId", { enumerable: true, get: function () { return manifest_1.contributionId; } });
10
+ Object.defineProperty(exports, "RESERVED_PLUGIN_ID", { enumerable: true, get: function () { return manifest_1.RESERVED_PLUGIN_ID; } });
7
11
  Object.defineProperty(exports, "isSectionSlot", { enumerable: true, get: function () { return manifest_1.isSectionSlot; } });
8
12
  Object.defineProperty(exports, "ManifestError", { enumerable: true, get: function () { return manifest_1.ManifestError; } });
9
13
  var allowlist_1 = require("./allowlist");
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ManifestError = exports.PROTOCOL_VERSION = void 0;
3
+ exports.RESERVED_PLUGIN_ID = exports.ManifestError = exports.PROTOCOL_VERSION = void 0;
4
4
  exports.isSectionSlot = isSectionSlot;
5
5
  exports.validateManifest = validateManifest;
6
+ exports.contributionId = contributionId;
7
+ exports.validatePublishableManifest = validatePublishableManifest;
8
+ exports.unnamedContributions = unnamedContributions;
6
9
  const when_1 = require("./when");
7
10
  const topics_1 = require("./topics");
8
11
  exports.PROTOCOL_VERSION = 1;
@@ -161,3 +164,49 @@ function readTopicPermissions(raw, pluginId) {
161
164
  }
162
165
  return topics;
163
166
  }
167
+ /** The platform's own blocks are `nullplatform/<block>`: no plugin may publish under that id (contract 5). */
168
+ exports.RESERVED_PLUGIN_ID = 'nullplatform';
169
+ /**
170
+ * The id a contribution goes by in block ids, flag keys and layouts: its `id`, or its widget for a revision published
171
+ * before ids were required (contract 5). One function, so every reader names an inherited contribution the same way.
172
+ */
173
+ function contributionId(contribution) {
174
+ return contribution.id ?? contribution.widget;
175
+ }
176
+ /**
177
+ * What a new revision must meet on top of `validateManifest` (contract 5): each contribution goes by a name unique in
178
+ * the manifest, since layouts, flags and section URLs point at it. The name is its `id` (lowercase letters, digits or
179
+ * dashes, 2-64 chars) or, without one, its widget, which is how hosts already keyed it. So a manifest that never
180
+ * repeats a widget stays publishable as it is, and one that mounts a widget twice must tell the two apart with ids.
181
+ * The plugin may not be `nullplatform`. The API applies it at publish and the CLI before uploading, so an author learns
182
+ * it before the build is pushed. Revisions published before keep working: hosts name them with `contributionId`.
183
+ */
184
+ function validatePublishableManifest(input) {
185
+ const manifest = validateManifest(input);
186
+ if (manifest.id === exports.RESERVED_PLUGIN_ID)
187
+ throw new ManifestError(`Plugin id "${exports.RESERVED_PLUGIN_ID}" is reserved for the platform's own blocks`);
188
+ // `validateManifest` drops an id that isn't a string; read the raw one so a malformed id is refused, not ignored.
189
+ const raw = input.contributes;
190
+ const seen = new Map();
191
+ manifest.contributes.forEach((contribution, index) => {
192
+ const id = raw[index]?.id;
193
+ if (id !== undefined && (typeof id !== 'string' || !ID_PATTERN.test(id))) {
194
+ throw new ManifestError(`contributes[${index}].id must be lowercase letters, digits or dashes (2-64 chars)`);
195
+ }
196
+ const name = contributionId(contribution);
197
+ const first = seen.get(name);
198
+ if (first !== undefined) {
199
+ const hint = contribution.id === undefined ? '; give each an id' : '';
200
+ throw new ManifestError(`contributes[${index}] goes by "${name}", already used by contributes[${first}]${hint}`);
201
+ }
202
+ seen.set(name, index);
203
+ });
204
+ return manifest;
205
+ }
206
+ /**
207
+ * Contributions that go by their widget for lack of an `id`. Publishable, but renaming the widget would rename the
208
+ * block, its flag and its place in layouts, so the CLI warns about them.
209
+ */
210
+ function unnamedContributions(manifest) {
211
+ return manifest.contributes.flatMap((contribution, index) => (contribution.id === undefined ? [`contributes[${index}] (${contribution.widget})`] : []));
212
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nullplatform/ui-plugin-sdk",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "SDK for nullplatform UI plugins: catalog components, bridge client and defineUI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",