@selfhelp/shared 1.2.1 → 1.2.3

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.
@@ -0,0 +1,133 @@
1
+ import { I as IPluginManifest } from '../manifest-C8sBTLJb.mjs';
2
+
3
+ /**
4
+ * `@selfhelp/shared/testing` — the plugin certification kit.
5
+ *
6
+ * Every plugin's certification suite imports from this subpath so the
7
+ * "standard suite every plugin must pass" stays identical across plugins
8
+ * (canonical Testing Rule: plugin certification).
9
+ *
10
+ * Scope: this kit performs the **static manifest certification** — pure,
11
+ * deterministic checks a plugin's CI (and any TS consumer) can run against a
12
+ * parsed `plugin.json` without a database or a running host:
13
+ *
14
+ * - manifest-valid required fields + semver/version-format sanity
15
+ * - capabilities-vs-trust-level known capabilities, trust-level limits,
16
+ * and declared-surface ↔ capability completeness
17
+ * - compatibility-shape the adopted single-range compatibility shape
18
+ * - lookup-ownership lookup extension ownership + entries
19
+ * - db-naming owned table / data-table-prefix naming rules
20
+ *
21
+ * The **runtime** lifecycle (install → update → rollback → uninstall → purge,
22
+ * realtime-topic registration, cleanup) is enforced by the backend host
23
+ * certification (`tests/Certification/*` + `PluginCapabilityValidator` /
24
+ * `PluginApiRouteSynchronizer` etc.), not here — a TS unit kit cannot install a
25
+ * Composer package or run Doctrine migrations. The two layers are
26
+ * complementary: this kit gates the manifest before publishing; the host gates
27
+ * the actual install.
28
+ *
29
+ * Checks are built on the existing plugin SDK (`IPluginManifest`, the capability
30
+ * union, and the semver helpers) so the kit never re-implements manifest typing
31
+ * or range parsing.
32
+ */
33
+
34
+ /** Version of the certification kit contract (asserted by a stability test). */
35
+ declare const CERTIFICATION_KIT_VERSION = "1.0.0";
36
+ interface ICertificationCheckResult {
37
+ /** Stable check name (one of {@link CERTIFICATION_CHECKS}). */
38
+ readonly name: string;
39
+ readonly passed: boolean;
40
+ /** Human-readable failures; empty when the check passed. */
41
+ readonly errors: readonly string[];
42
+ }
43
+ interface IPluginCertificationReport {
44
+ readonly pluginId: string;
45
+ readonly kitVersion: string;
46
+ /** True only when every check passed. */
47
+ readonly passed: boolean;
48
+ readonly results: readonly ICertificationCheckResult[];
49
+ }
50
+ interface IPluginCertificationConfig {
51
+ /** Plugin id under test, e.g. `sh2-shp-survey-js`. */
52
+ pluginId: string;
53
+ /** Path to the plugin's `plugin.json` manifest (for reporter context). */
54
+ manifestPath?: string;
55
+ /** Path to the lock file the certification seeds from. */
56
+ lockFilePath?: string;
57
+ /** Capabilities the plugin declares; the runner asserts they are granted. */
58
+ capabilities?: readonly string[];
59
+ /** Mercure topics the plugin owns; verified through {@link mockMercureHub}. */
60
+ realtimeTopics?: readonly string[];
61
+ }
62
+ interface IPluginCertificationSuite {
63
+ readonly pluginId: string;
64
+ readonly kitVersion: string;
65
+ readonly config: IPluginCertificationConfig;
66
+ /** The ordered static checks every plugin manifest must pass. */
67
+ readonly checks: readonly string[];
68
+ /** Run all static checks against a parsed manifest and return a report. */
69
+ run(manifest: IPluginManifest): IPluginCertificationReport;
70
+ }
71
+ /** The canonical, ordered certification checks (names are the stable contract). */
72
+ declare const CERTIFICATION_CHECKS: readonly string[];
73
+ /** manifest-valid: required fields are present and well-formed. */
74
+ declare function checkManifestValid(manifest: IPluginManifest): ICertificationCheckResult;
75
+ /**
76
+ * capabilities-vs-trust-level: capabilities are known, respect the trust-level
77
+ * limits, and every declared surface has the capability that gates it.
78
+ */
79
+ declare function checkCapabilitiesVsTrustLevel(manifest: IPluginManifest): ICertificationCheckResult;
80
+ /**
81
+ * compatibility-shape: the adopted single-range compatibility shape —
82
+ * `compatibility.selfhelp` is a SemVer **range string** (not the rejected
83
+ * per-surface object), with optional platform ranges, and no unknown keys.
84
+ */
85
+ declare function checkCompatibilityShape(manifest: IPluginManifest): ICertificationCheckResult;
86
+ /** lookup-ownership: lookup extensions declare a valid ownership + entries. */
87
+ declare function checkLookupOwnership(manifest: IPluginManifest): ICertificationCheckResult;
88
+ /** db-naming: owned tables + data-table prefix follow lowercase_snake_case. */
89
+ declare function checkDbNaming(manifest: IPluginManifest): ICertificationCheckResult;
90
+ /** Run the full ordered static certification against a parsed manifest. */
91
+ declare function runCertificationChecks(manifest: IPluginManifest): ICertificationCheckResult[];
92
+ /**
93
+ * Declare a plugin certification suite. The returned suite exposes the stable
94
+ * ordered check names plus an executable {@link IPluginCertificationSuite.run}
95
+ * that validates a parsed manifest and returns a typed report.
96
+ */
97
+ declare function definePluginCertification(config: IPluginCertificationConfig): IPluginCertificationSuite;
98
+ interface IRecordedMercureUpdate {
99
+ topic: string;
100
+ data: unknown;
101
+ }
102
+ interface IMockMercureHub {
103
+ /** Record a publish call (drop-in for the real hub's publish). */
104
+ publish(topic: string, data?: unknown): void;
105
+ /** All recorded updates in publish order. */
106
+ readonly updates: readonly IRecordedMercureUpdate[];
107
+ /** Distinct topics that were published to. */
108
+ publishedTopics(): string[];
109
+ /** Number of updates published to a given topic. */
110
+ countForTopic(topic: string): number;
111
+ /** Clear all recorded updates (use in afterEach). */
112
+ reset(): void;
113
+ }
114
+ /**
115
+ * Create an in-memory Mercure hub spy. Plugins assert published topics /
116
+ * payloads against it instead of polling a real hub (canonical Testing
117
+ * Rule 13: Mercure verified via a recorder, never polling).
118
+ */
119
+ declare function mockMercureHub(): IMockMercureHub;
120
+ interface ILockFilePluginEntry {
121
+ pluginId: string;
122
+ version: string;
123
+ }
124
+ interface ILockFileSeed {
125
+ plugins: ILockFilePluginEntry[];
126
+ }
127
+ /**
128
+ * Parse the `plugins` map of a `selfhelp.plugins.lock.json` document into a
129
+ * deterministic seed list. Tolerant of partial documents.
130
+ */
131
+ declare function seedFromLockFile(lockJson: unknown): ILockFileSeed;
132
+
133
+ export { CERTIFICATION_CHECKS, CERTIFICATION_KIT_VERSION, type ICertificationCheckResult, type ILockFilePluginEntry, type ILockFileSeed, type IMockMercureHub, type IPluginCertificationConfig, type IPluginCertificationReport, type IPluginCertificationSuite, type IRecordedMercureUpdate, checkCapabilitiesVsTrustLevel, checkCompatibilityShape, checkDbNaming, checkLookupOwnership, checkManifestValid, definePluginCertification, mockMercureHub, runCertificationChecks, seedFromLockFile };
@@ -0,0 +1,133 @@
1
+ import { I as IPluginManifest } from '../manifest-C8sBTLJb.js';
2
+
3
+ /**
4
+ * `@selfhelp/shared/testing` — the plugin certification kit.
5
+ *
6
+ * Every plugin's certification suite imports from this subpath so the
7
+ * "standard suite every plugin must pass" stays identical across plugins
8
+ * (canonical Testing Rule: plugin certification).
9
+ *
10
+ * Scope: this kit performs the **static manifest certification** — pure,
11
+ * deterministic checks a plugin's CI (and any TS consumer) can run against a
12
+ * parsed `plugin.json` without a database or a running host:
13
+ *
14
+ * - manifest-valid required fields + semver/version-format sanity
15
+ * - capabilities-vs-trust-level known capabilities, trust-level limits,
16
+ * and declared-surface ↔ capability completeness
17
+ * - compatibility-shape the adopted single-range compatibility shape
18
+ * - lookup-ownership lookup extension ownership + entries
19
+ * - db-naming owned table / data-table-prefix naming rules
20
+ *
21
+ * The **runtime** lifecycle (install → update → rollback → uninstall → purge,
22
+ * realtime-topic registration, cleanup) is enforced by the backend host
23
+ * certification (`tests/Certification/*` + `PluginCapabilityValidator` /
24
+ * `PluginApiRouteSynchronizer` etc.), not here — a TS unit kit cannot install a
25
+ * Composer package or run Doctrine migrations. The two layers are
26
+ * complementary: this kit gates the manifest before publishing; the host gates
27
+ * the actual install.
28
+ *
29
+ * Checks are built on the existing plugin SDK (`IPluginManifest`, the capability
30
+ * union, and the semver helpers) so the kit never re-implements manifest typing
31
+ * or range parsing.
32
+ */
33
+
34
+ /** Version of the certification kit contract (asserted by a stability test). */
35
+ declare const CERTIFICATION_KIT_VERSION = "1.0.0";
36
+ interface ICertificationCheckResult {
37
+ /** Stable check name (one of {@link CERTIFICATION_CHECKS}). */
38
+ readonly name: string;
39
+ readonly passed: boolean;
40
+ /** Human-readable failures; empty when the check passed. */
41
+ readonly errors: readonly string[];
42
+ }
43
+ interface IPluginCertificationReport {
44
+ readonly pluginId: string;
45
+ readonly kitVersion: string;
46
+ /** True only when every check passed. */
47
+ readonly passed: boolean;
48
+ readonly results: readonly ICertificationCheckResult[];
49
+ }
50
+ interface IPluginCertificationConfig {
51
+ /** Plugin id under test, e.g. `sh2-shp-survey-js`. */
52
+ pluginId: string;
53
+ /** Path to the plugin's `plugin.json` manifest (for reporter context). */
54
+ manifestPath?: string;
55
+ /** Path to the lock file the certification seeds from. */
56
+ lockFilePath?: string;
57
+ /** Capabilities the plugin declares; the runner asserts they are granted. */
58
+ capabilities?: readonly string[];
59
+ /** Mercure topics the plugin owns; verified through {@link mockMercureHub}. */
60
+ realtimeTopics?: readonly string[];
61
+ }
62
+ interface IPluginCertificationSuite {
63
+ readonly pluginId: string;
64
+ readonly kitVersion: string;
65
+ readonly config: IPluginCertificationConfig;
66
+ /** The ordered static checks every plugin manifest must pass. */
67
+ readonly checks: readonly string[];
68
+ /** Run all static checks against a parsed manifest and return a report. */
69
+ run(manifest: IPluginManifest): IPluginCertificationReport;
70
+ }
71
+ /** The canonical, ordered certification checks (names are the stable contract). */
72
+ declare const CERTIFICATION_CHECKS: readonly string[];
73
+ /** manifest-valid: required fields are present and well-formed. */
74
+ declare function checkManifestValid(manifest: IPluginManifest): ICertificationCheckResult;
75
+ /**
76
+ * capabilities-vs-trust-level: capabilities are known, respect the trust-level
77
+ * limits, and every declared surface has the capability that gates it.
78
+ */
79
+ declare function checkCapabilitiesVsTrustLevel(manifest: IPluginManifest): ICertificationCheckResult;
80
+ /**
81
+ * compatibility-shape: the adopted single-range compatibility shape —
82
+ * `compatibility.selfhelp` is a SemVer **range string** (not the rejected
83
+ * per-surface object), with optional platform ranges, and no unknown keys.
84
+ */
85
+ declare function checkCompatibilityShape(manifest: IPluginManifest): ICertificationCheckResult;
86
+ /** lookup-ownership: lookup extensions declare a valid ownership + entries. */
87
+ declare function checkLookupOwnership(manifest: IPluginManifest): ICertificationCheckResult;
88
+ /** db-naming: owned tables + data-table prefix follow lowercase_snake_case. */
89
+ declare function checkDbNaming(manifest: IPluginManifest): ICertificationCheckResult;
90
+ /** Run the full ordered static certification against a parsed manifest. */
91
+ declare function runCertificationChecks(manifest: IPluginManifest): ICertificationCheckResult[];
92
+ /**
93
+ * Declare a plugin certification suite. The returned suite exposes the stable
94
+ * ordered check names plus an executable {@link IPluginCertificationSuite.run}
95
+ * that validates a parsed manifest and returns a typed report.
96
+ */
97
+ declare function definePluginCertification(config: IPluginCertificationConfig): IPluginCertificationSuite;
98
+ interface IRecordedMercureUpdate {
99
+ topic: string;
100
+ data: unknown;
101
+ }
102
+ interface IMockMercureHub {
103
+ /** Record a publish call (drop-in for the real hub's publish). */
104
+ publish(topic: string, data?: unknown): void;
105
+ /** All recorded updates in publish order. */
106
+ readonly updates: readonly IRecordedMercureUpdate[];
107
+ /** Distinct topics that were published to. */
108
+ publishedTopics(): string[];
109
+ /** Number of updates published to a given topic. */
110
+ countForTopic(topic: string): number;
111
+ /** Clear all recorded updates (use in afterEach). */
112
+ reset(): void;
113
+ }
114
+ /**
115
+ * Create an in-memory Mercure hub spy. Plugins assert published topics /
116
+ * payloads against it instead of polling a real hub (canonical Testing
117
+ * Rule 13: Mercure verified via a recorder, never polling).
118
+ */
119
+ declare function mockMercureHub(): IMockMercureHub;
120
+ interface ILockFilePluginEntry {
121
+ pluginId: string;
122
+ version: string;
123
+ }
124
+ interface ILockFileSeed {
125
+ plugins: ILockFilePluginEntry[];
126
+ }
127
+ /**
128
+ * Parse the `plugins` map of a `selfhelp.plugins.lock.json` document into a
129
+ * deterministic seed list. Tolerant of partial documents.
130
+ */
131
+ declare function seedFromLockFile(lockJson: unknown): ILockFileSeed;
132
+
133
+ export { CERTIFICATION_CHECKS, CERTIFICATION_KIT_VERSION, type ICertificationCheckResult, type ILockFilePluginEntry, type ILockFileSeed, type IMockMercureHub, type IPluginCertificationConfig, type IPluginCertificationReport, type IPluginCertificationSuite, type IRecordedMercureUpdate, checkCapabilitiesVsTrustLevel, checkCompatibilityShape, checkDbNaming, checkLookupOwnership, checkManifestValid, definePluginCertification, mockMercureHub, runCertificationChecks, seedFromLockFile };
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/testing/index.ts
21
+ var testing_exports = {};
22
+ __export(testing_exports, {
23
+ CERTIFICATION_CHECKS: () => CERTIFICATION_CHECKS,
24
+ CERTIFICATION_KIT_VERSION: () => CERTIFICATION_KIT_VERSION,
25
+ checkCapabilitiesVsTrustLevel: () => checkCapabilitiesVsTrustLevel,
26
+ checkCompatibilityShape: () => checkCompatibilityShape,
27
+ checkDbNaming: () => checkDbNaming,
28
+ checkLookupOwnership: () => checkLookupOwnership,
29
+ checkManifestValid: () => checkManifestValid,
30
+ definePluginCertification: () => definePluginCertification,
31
+ mockMercureHub: () => mockMercureHub,
32
+ runCertificationChecks: () => runCertificationChecks,
33
+ seedFromLockFile: () => seedFromLockFile
34
+ });
35
+ module.exports = __toCommonJS(testing_exports);
36
+
37
+ // src/plugin-sdk/version.ts
38
+ var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
39
+ function parseSemver(version) {
40
+ const match = SEMVER_REGEX.exec(version);
41
+ if (!match) {
42
+ throw new Error(`[plugin-sdk] not a valid semver: '${version}'.`);
43
+ }
44
+ return {
45
+ major: Number(match[1]),
46
+ minor: Number(match[2]),
47
+ patch: Number(match[3]),
48
+ prerelease: match[4]
49
+ };
50
+ }
51
+
52
+ // src/testing/index.ts
53
+ var CERTIFICATION_KIT_VERSION = "1.0.0";
54
+ var CERTIFICATION_CHECKS = [
55
+ "manifest-valid",
56
+ "capabilities-vs-trust-level",
57
+ "compatibility-shape",
58
+ "lookup-ownership",
59
+ "db-naming"
60
+ ];
61
+ var KNOWN_CAPABILITIES = /* @__PURE__ */ new Set([
62
+ "backendBundle",
63
+ "databaseMigrations",
64
+ "readUsers",
65
+ "writeUsers",
66
+ "deleteUsers",
67
+ "readDataTables",
68
+ "writeDataTables",
69
+ "deleteDataTables",
70
+ "externalNetworkAccess",
71
+ "scheduledJobs",
72
+ "publicCallbacks",
73
+ "adminPages",
74
+ "frontendStyles",
75
+ "mobileStyles",
76
+ "realtimePublish",
77
+ "fileUploads",
78
+ "secretAccess",
79
+ "lookupExtend",
80
+ "lookupOwnGroup"
81
+ ]);
82
+ var UNTRUSTED_FORBIDDEN_CAPABILITIES = [
83
+ "backendBundle",
84
+ "databaseMigrations",
85
+ "scheduledJobs",
86
+ "readUsers",
87
+ "writeUsers",
88
+ "deleteUsers",
89
+ "readDataTables",
90
+ "writeDataTables",
91
+ "deleteDataTables",
92
+ "secretAccess",
93
+ "externalNetworkAccess"
94
+ ];
95
+ var COMPATIBILITY_KEYS = ["selfhelp", "php", "node", "react", "reactNative", "expoSdk"];
96
+ var OWNED_TABLE_PATTERN = /^[a-z][a-z0-9_]*$/;
97
+ var OWNED_PREFIX_PATTERN = /^[a-z][a-z0-9_]*_$/;
98
+ var PLUGIN_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
99
+ var PLUGIN_API_VERSION_PATTERN = /^\d+\.\d+$/;
100
+ var RANGE_TOKEN_PATTERN = /^(\*|x|(\^|~|>=|<=|>|<|=)?\d+(\.\d+)?(\.\d+)?(-[0-9A-Za-z.-]+)?)$/;
101
+ function makeResult(name, errors) {
102
+ return { name, passed: errors.length === 0, errors };
103
+ }
104
+ function isValidRange(range) {
105
+ const clauses = range.split("||").map((c) => c.trim()).filter((c) => c !== "");
106
+ if (clauses.length === 0) {
107
+ return false;
108
+ }
109
+ return clauses.every(
110
+ (clause) => clause.split(/\s+/).filter((t) => t !== "").every((token) => RANGE_TOKEN_PATTERN.test(token))
111
+ );
112
+ }
113
+ function asCapabilityList(manifest) {
114
+ const caps = manifest.security?.capabilities;
115
+ return Array.isArray(caps) ? caps.map((c) => String(c)) : [];
116
+ }
117
+ function checkManifestValid(manifest) {
118
+ const errors = [];
119
+ if (!manifest.id || typeof manifest.id !== "string") {
120
+ errors.push("id is required.");
121
+ } else if (!PLUGIN_ID_PATTERN.test(manifest.id)) {
122
+ errors.push(`id '${manifest.id}' must match ${PLUGIN_ID_PATTERN}.`);
123
+ }
124
+ if (!manifest.name || typeof manifest.name !== "string") {
125
+ errors.push("name is required.");
126
+ }
127
+ if (!manifest.version || typeof manifest.version !== "string") {
128
+ errors.push("version is required.");
129
+ } else {
130
+ try {
131
+ parseSemver(manifest.version);
132
+ } catch {
133
+ errors.push(`version '${manifest.version}' is not valid semver.`);
134
+ }
135
+ }
136
+ if (!manifest.pluginApiVersion || typeof manifest.pluginApiVersion !== "string") {
137
+ errors.push("pluginApiVersion is required.");
138
+ } else if (!PLUGIN_API_VERSION_PATTERN.test(manifest.pluginApiVersion)) {
139
+ errors.push(`pluginApiVersion '${manifest.pluginApiVersion}' must look like '<major>.<minor>'.`);
140
+ }
141
+ if (!manifest.compatibility || typeof manifest.compatibility !== "object") {
142
+ errors.push("compatibility is required.");
143
+ }
144
+ if (!manifest.security || typeof manifest.security !== "object") {
145
+ errors.push("security is required.");
146
+ } else {
147
+ if (!manifest.security.trustLevel) {
148
+ errors.push("security.trustLevel is required.");
149
+ }
150
+ if (!Array.isArray(manifest.security.capabilities)) {
151
+ errors.push("security.capabilities must be an array.");
152
+ }
153
+ }
154
+ return makeResult("manifest-valid", errors);
155
+ }
156
+ function checkCapabilitiesVsTrustLevel(manifest) {
157
+ const errors = [];
158
+ const caps = asCapabilityList(manifest);
159
+ const capSet = new Set(caps);
160
+ const trustLevel = manifest.security?.trustLevel;
161
+ for (const cap of caps) {
162
+ if (!KNOWN_CAPABILITIES.has(cap)) {
163
+ errors.push(`unknown capability '${cap}'.`);
164
+ }
165
+ }
166
+ if (trustLevel === "untrusted") {
167
+ for (const cap of UNTRUSTED_FORBIDDEN_CAPABILITIES) {
168
+ if (capSet.has(cap)) {
169
+ errors.push(`untrusted plugins may not declare capability '${cap}'.`);
170
+ }
171
+ }
172
+ }
173
+ const require2 = (condition, capability, surface) => {
174
+ if (condition && !capSet.has(capability)) {
175
+ errors.push(`${surface} requires the '${capability}' capability.`);
176
+ }
177
+ };
178
+ require2(Boolean(manifest.backend?.bundleClass), "backendBundle", "declaring a backend bundle");
179
+ require2(Boolean(manifest.backend?.migrationsNamespace), "databaseMigrations", "declaring a migrations namespace");
180
+ require2((manifest.scheduledJobs?.length ?? 0) > 0, "scheduledJobs", "declaring scheduled jobs");
181
+ require2((manifest.adminPages?.length ?? 0) > 0, "adminPages", "declaring admin pages");
182
+ require2((manifest.realtimeTopics?.length ?? 0) > 0, "realtimePublish", "declaring realtime topics");
183
+ if ((manifest.styles?.length ?? 0) > 0 && !capSet.has("frontendStyles") && !capSet.has("mobileStyles")) {
184
+ errors.push("declaring styles requires the 'frontendStyles' or 'mobileStyles' capability.");
185
+ }
186
+ for (const ext of manifest.lookups?.extends ?? []) {
187
+ if (ext.ownership === "plugin_owned") {
188
+ require2(true, "lookupOwnGroup", `owning lookup group '${ext.typeCode}'`);
189
+ } else if (ext.ownership === "plugin_extendable") {
190
+ require2(true, "lookupExtend", `extending lookup group '${ext.typeCode}'`);
191
+ }
192
+ }
193
+ require2((manifest.dataAccess?.write?.length ?? 0) > 0, "writeDataTables", "declaring data-table writes");
194
+ require2((manifest.dataAccess?.delete?.length ?? 0) > 0, "deleteDataTables", "declaring data-table deletes");
195
+ return makeResult("capabilities-vs-trust-level", errors);
196
+ }
197
+ function checkCompatibilityShape(manifest) {
198
+ const errors = [];
199
+ const compatibility = manifest.compatibility;
200
+ if (!compatibility || typeof compatibility !== "object") {
201
+ return makeResult("compatibility-shape", ["compatibility is required."]);
202
+ }
203
+ const selfhelp = compatibility.selfhelp;
204
+ if (typeof selfhelp !== "string") {
205
+ errors.push(
206
+ "compatibility.selfhelp must be a SemVer range string (single-range shape), not an object or missing."
207
+ );
208
+ } else if (selfhelp.trim() === "" || !isValidRange(selfhelp)) {
209
+ errors.push(`compatibility.selfhelp '${selfhelp}' is not a valid SemVer range.`);
210
+ }
211
+ for (const key of Object.keys(compatibility)) {
212
+ if (!COMPATIBILITY_KEYS.includes(key)) {
213
+ errors.push(`compatibility has unknown key '${key}'.`);
214
+ continue;
215
+ }
216
+ if (key === "selfhelp") {
217
+ continue;
218
+ }
219
+ const value = compatibility[key];
220
+ if (typeof value !== "string" || !isValidRange(value)) {
221
+ errors.push(`compatibility.${key} must be a valid SemVer range string.`);
222
+ }
223
+ }
224
+ return makeResult("compatibility-shape", errors);
225
+ }
226
+ function checkLookupOwnership(manifest) {
227
+ const errors = [];
228
+ for (const ext of manifest.lookups?.extends ?? []) {
229
+ const label = ext.typeCode || "<missing typeCode>";
230
+ if (!ext.typeCode) {
231
+ errors.push("lookup extension is missing typeCode.");
232
+ }
233
+ if (ext.ownership !== "plugin_owned" && ext.ownership !== "plugin_extendable") {
234
+ errors.push(`lookup '${label}' has invalid ownership '${String(ext.ownership)}'.`);
235
+ }
236
+ if (!Array.isArray(ext.entries) || ext.entries.length === 0) {
237
+ errors.push(`lookup '${label}' must declare at least one entry.`);
238
+ continue;
239
+ }
240
+ for (const entry of ext.entries) {
241
+ if (!entry.code || !entry.value) {
242
+ errors.push(`lookup '${label}' has an entry missing code/value.`);
243
+ }
244
+ }
245
+ }
246
+ return makeResult("lookup-ownership", errors);
247
+ }
248
+ function checkDbNaming(manifest) {
249
+ const errors = [];
250
+ const dataAccess = manifest.dataAccess;
251
+ for (const table of dataAccess?.ownedTables ?? []) {
252
+ if (!OWNED_TABLE_PATTERN.test(table)) {
253
+ errors.push(`owned table '${table}' must be lowercase_snake_case (${OWNED_TABLE_PATTERN}).`);
254
+ }
255
+ }
256
+ const prefix = dataAccess?.ownedDataTablePrefix;
257
+ if (prefix !== void 0 && prefix !== "" && !OWNED_PREFIX_PATTERN.test(prefix)) {
258
+ errors.push(`ownedDataTablePrefix '${prefix}' must be lowercase_snake_case ending in '_' (${OWNED_PREFIX_PATTERN}).`);
259
+ }
260
+ return makeResult("db-naming", errors);
261
+ }
262
+ function runCertificationChecks(manifest) {
263
+ return [
264
+ checkManifestValid(manifest),
265
+ checkCapabilitiesVsTrustLevel(manifest),
266
+ checkCompatibilityShape(manifest),
267
+ checkLookupOwnership(manifest),
268
+ checkDbNaming(manifest)
269
+ ];
270
+ }
271
+ function definePluginCertification(config) {
272
+ if (!config.pluginId || config.pluginId.trim() === "") {
273
+ throw new Error("definePluginCertification: pluginId is required.");
274
+ }
275
+ return {
276
+ pluginId: config.pluginId,
277
+ kitVersion: CERTIFICATION_KIT_VERSION,
278
+ config,
279
+ checks: CERTIFICATION_CHECKS,
280
+ run(manifest) {
281
+ const results = runCertificationChecks(manifest);
282
+ return {
283
+ pluginId: config.pluginId,
284
+ kitVersion: CERTIFICATION_KIT_VERSION,
285
+ passed: results.every((r) => r.passed),
286
+ results
287
+ };
288
+ }
289
+ };
290
+ }
291
+ function mockMercureHub() {
292
+ const updates = [];
293
+ return {
294
+ updates,
295
+ publish(topic, data = null) {
296
+ updates.push({ topic, data });
297
+ },
298
+ publishedTopics() {
299
+ return [...new Set(updates.map((u) => u.topic))];
300
+ },
301
+ countForTopic(topic) {
302
+ return updates.filter((u) => u.topic === topic).length;
303
+ },
304
+ reset() {
305
+ updates.length = 0;
306
+ }
307
+ };
308
+ }
309
+ function seedFromLockFile(lockJson) {
310
+ const plugins = [];
311
+ if (lockJson && typeof lockJson === "object" && "plugins" in lockJson) {
312
+ const raw = lockJson.plugins;
313
+ if (raw && typeof raw === "object") {
314
+ for (const [pluginId, entry] of Object.entries(raw)) {
315
+ const version = entry && typeof entry === "object" && "version" in entry ? String(entry.version) : "0.0.0";
316
+ plugins.push({ pluginId, version });
317
+ }
318
+ }
319
+ }
320
+ return { plugins };
321
+ }
322
+ // Annotate the CommonJS export names for ESM import in node:
323
+ 0 && (module.exports = {
324
+ CERTIFICATION_CHECKS,
325
+ CERTIFICATION_KIT_VERSION,
326
+ checkCapabilitiesVsTrustLevel,
327
+ checkCompatibilityShape,
328
+ checkDbNaming,
329
+ checkLookupOwnership,
330
+ checkManifestValid,
331
+ definePluginCertification,
332
+ mockMercureHub,
333
+ runCertificationChecks,
334
+ seedFromLockFile
335
+ });