@cervio/plugin-core 0.1.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/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @cervio/plugin-core
2
+
3
+ Shared Cervio plugin contracts: manifest parsing, ZIP safety, content hashing, semver assignment helpers, and `packPlugin()`.
4
+
5
+ Used by the Cervio host and by `@cervio/cli` so local `cervio validate` matches server upload checks.
6
+
7
+ ```bash
8
+ pnpm add @cervio/plugin-core
9
+ ```
10
+
11
+ ```ts
12
+ import { parseManifestObject, packPlugin, nextPatchVersion } from '@cervio/plugin-core'
13
+
14
+ const fields = parseManifestObject(manifestJson)
15
+ const packed = await packPlugin({ dir: '.' })
16
+ ```
17
+
18
+ See docs at `docs.cervio.app` (when deployed) and `docs/plugins/AUTHORING.md` in the Cervio repo.
19
+
20
+ **Versioning note:** this package version is independent of plugin release versions (assigned by the host) and of `@cervio/plugin-sdk` (tracks CervioUI API).
package/dist/index.cjs ADDED
@@ -0,0 +1,549 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var JSZip = require('jszip');
5
+ var crypto = require('crypto');
6
+ var fs = require('fs');
7
+ var path = require('path');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var JSZip__default = /*#__PURE__*/_interopDefault(JSZip);
12
+ var path__default = /*#__PURE__*/_interopDefault(path);
13
+
14
+ // src/types.ts
15
+ var PLUGIN_ARTIFACT_BUCKET = "plugin-artifacts";
16
+ var MAX_PLUGIN_ZIP_BYTES = 50 * 1024 * 1024;
17
+ var MAX_PLUGIN_ZIP_ENTRIES = 5e3;
18
+ var MAX_PLUGIN_UNCOMPRESSED_BYTES = 250 * 1024 * 1024;
19
+ var PLUGIN_KEY_RE = /^[a-z0-9][a-z0-9-_]{1,62}$/;
20
+ var PLUGIN_VERSION_SELECT = "id, plugin_id, version, changelog, artifact_path, artifact_entry_path, artifact_sha256, content_sha256, artifact_size_bytes, created_at";
21
+ var DEFAULT_PLUGIN_DECLARABLE_CAPABILITIES = ["calendar"];
22
+
23
+ // src/entity-requirements.ts
24
+ var ENTITY_NAME_RE = /^[a-z][a-z0-9_-]{0,62}$/i;
25
+ var FIELD_NAME_RE = /^[a-z][a-z0-9_]{0,62}$/i;
26
+ var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "*"]);
27
+ function asStringArray(raw, nameRe) {
28
+ if (!Array.isArray(raw)) return [];
29
+ const out = [];
30
+ const seen = /* @__PURE__ */ new Set();
31
+ for (const item of raw) {
32
+ if (typeof item !== "string") continue;
33
+ const v = item.trim();
34
+ if (!v || !nameRe.test(v) || seen.has(v)) continue;
35
+ seen.add(v);
36
+ out.push(v);
37
+ }
38
+ return out;
39
+ }
40
+ function parseAccess(raw) {
41
+ if (!Array.isArray(raw)) return ["read"];
42
+ const out = [];
43
+ for (const item of raw) {
44
+ if (item === "read" || item === "write") {
45
+ if (!out.includes(item)) out.push(item);
46
+ }
47
+ }
48
+ return out.length ? out : ["read"];
49
+ }
50
+ function parsePluginEntityRequirements(raw) {
51
+ if (!Array.isArray(raw)) return [];
52
+ const out = [];
53
+ const seen = /* @__PURE__ */ new Set();
54
+ for (const item of raw) {
55
+ if (!item || typeof item !== "object") continue;
56
+ const row = item;
57
+ const name = typeof row.name === "string" ? row.name.trim() : "";
58
+ if (!name || !ENTITY_NAME_RE.test(name) || seen.has(name.toLowerCase())) continue;
59
+ seen.add(name.toLowerCase());
60
+ out.push({
61
+ name,
62
+ fields: asStringArray(row.fields, FIELD_NAME_RE),
63
+ forms: asStringArray(row.forms, FIELD_NAME_RE),
64
+ access: parseAccess(row.access)
65
+ });
66
+ }
67
+ return out;
68
+ }
69
+ function parsePluginCervioApiRequirements(raw) {
70
+ if (!Array.isArray(raw)) return [];
71
+ const out = [];
72
+ const seen = /* @__PURE__ */ new Set();
73
+ for (const item of raw) {
74
+ if (!item || typeof item !== "object") continue;
75
+ const row = item;
76
+ const methodRaw = typeof row.method === "string" ? row.method.trim().toUpperCase() : "GET";
77
+ const method = HTTP_METHODS.has(methodRaw) ? methodRaw : "GET";
78
+ const path2 = typeof row.path_prefix === "string" ? row.path_prefix.trim() : typeof row.pathPrefix === "string" ? row.pathPrefix.trim() : "";
79
+ if (!path2 || !path2.startsWith("/")) continue;
80
+ const key = `${method}:${path2}`;
81
+ if (seen.has(key)) continue;
82
+ seen.add(key);
83
+ out.push({ method, path_prefix: path2 });
84
+ }
85
+ return out;
86
+ }
87
+
88
+ // src/connections.ts
89
+ var EXTERNAL_CONNECTION_ALLOWED_HOSTS = {
90
+ microsoft: ["graph.microsoft.com"],
91
+ google: ["googleapis.com", "www.googleapis.com"]
92
+ };
93
+ var EXTERNAL_CONNECTION_HTTP_METHODS = [
94
+ "GET",
95
+ "POST",
96
+ "PATCH",
97
+ "PUT",
98
+ "DELETE"
99
+ ];
100
+ var CONNECTION_ID_RE = /^[a-z0-9][a-z0-9-_]{0,62}$/;
101
+ var OAUTH_PROVIDER_KEY_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/;
102
+ var MAX_SCOPES = 32;
103
+ var MAX_ALLOWED_APIS = 24;
104
+ var MAX_SCOPE_LEN = 200;
105
+ var BLOCKED_HOST_SUFFIXES = [".localhost", ".local", ".internal", ".home", ".lan"];
106
+ function normalizeExactApiHost(raw) {
107
+ const host = raw.trim().toLowerCase().replace(/\.$/, "");
108
+ if (!host || host.length > 253 || host.includes("/") || host.includes(":") || host.includes("*") || host === "localhost" || BLOCKED_HOST_SUFFIXES.some((suffix) => host.endsWith(suffix))) {
109
+ return null;
110
+ }
111
+ if (!/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(
112
+ host
113
+ )) {
114
+ return null;
115
+ }
116
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) return null;
117
+ return host;
118
+ }
119
+ function isExternalConnectionProvider(v) {
120
+ return OAUTH_PROVIDER_KEY_RE.test(v);
121
+ }
122
+ function parseAllowedApi(raw, provider) {
123
+ if (!raw || typeof raw !== "object") return null;
124
+ const o = raw;
125
+ const host = typeof o.host === "string" ? o.host.trim().toLowerCase() : "";
126
+ const pathPrefix = typeof o.path_prefix === "string" ? o.path_prefix.trim() : typeof o.pathPrefix === "string" ? o.pathPrefix.trim() : "";
127
+ const methodsRaw = o.methods;
128
+ if (!host || !pathPrefix || !normalizeExactApiHost(host)) return null;
129
+ const builtinHosts = EXTERNAL_CONNECTION_ALLOWED_HOSTS[provider];
130
+ if (builtinHosts && !builtinHosts.includes(host)) return null;
131
+ if (!pathPrefix.startsWith("/") || pathPrefix.includes("..") || pathPrefix.includes("\\")) {
132
+ return null;
133
+ }
134
+ if (!Array.isArray(methodsRaw) || methodsRaw.length === 0) return null;
135
+ const methods = [];
136
+ for (const m of methodsRaw) {
137
+ if (typeof m !== "string") return null;
138
+ const up = m.trim().toUpperCase();
139
+ if (!EXTERNAL_CONNECTION_HTTP_METHODS.includes(up)) return null;
140
+ if (!methods.includes(up)) {
141
+ methods.push(up);
142
+ }
143
+ }
144
+ if (!methods.length) return null;
145
+ return { host, methods, path_prefix: pathPrefix };
146
+ }
147
+ function parsePluginConnections(raw) {
148
+ if (!Array.isArray(raw)) return [];
149
+ const out = [];
150
+ const seen = /* @__PURE__ */ new Set();
151
+ for (const item of raw) {
152
+ if (!item || typeof item !== "object") continue;
153
+ const o = item;
154
+ const id = typeof o.id === "string" ? o.id.trim().toLowerCase() : "";
155
+ if (!id || !CONNECTION_ID_RE.test(id) || seen.has(id)) continue;
156
+ const providerRaw = typeof o.provider === "string" ? o.provider.trim().toLowerCase() : "";
157
+ if (!isExternalConnectionProvider(providerRaw)) continue;
158
+ const scopesRaw = o.scopes;
159
+ if (!Array.isArray(scopesRaw) || scopesRaw.length === 0 || scopesRaw.length > MAX_SCOPES) continue;
160
+ const scopes = [];
161
+ for (const s of scopesRaw) {
162
+ if (typeof s !== "string") continue;
163
+ const t = s.trim();
164
+ if (!t || t.length > MAX_SCOPE_LEN) continue;
165
+ if (!scopes.includes(t)) scopes.push(t);
166
+ }
167
+ if (!scopes.length) continue;
168
+ const apisRaw = o.allowed_apis ?? o.allowedApis;
169
+ if (!Array.isArray(apisRaw) || apisRaw.length === 0 || apisRaw.length > MAX_ALLOWED_APIS) continue;
170
+ const allowed_apis = [];
171
+ for (const a of apisRaw) {
172
+ const rule = parseAllowedApi(a, providerRaw);
173
+ if (rule) allowed_apis.push(rule);
174
+ }
175
+ if (!allowed_apis.length) continue;
176
+ seen.add(id);
177
+ out.push({
178
+ id,
179
+ provider: providerRaw,
180
+ consent: "user",
181
+ scopes,
182
+ allowed_apis
183
+ });
184
+ }
185
+ return out;
186
+ }
187
+
188
+ // src/zip-safety.ts
189
+ function assertZipSafe(zip) {
190
+ const names = Object.keys(zip.files);
191
+ if (names.length > MAX_PLUGIN_ZIP_ENTRIES) {
192
+ return { ok: false, error: "zip_too_many_entries" };
193
+ }
194
+ let totalUncompressed = 0;
195
+ for (const name of names) {
196
+ if (name.includes("..") || name.includes("\\") || name.startsWith("/")) {
197
+ return { ok: false, error: "zip_unsafe_entry_path" };
198
+ }
199
+ const entry = zip.files[name];
200
+ totalUncompressed += entry._data?.uncompressedSize ?? 0;
201
+ if (totalUncompressed > MAX_PLUGIN_UNCOMPRESSED_BYTES) {
202
+ return { ok: false, error: "zip_uncompressed_too_large" };
203
+ }
204
+ }
205
+ return { ok: true, value: true };
206
+ }
207
+ function assertZipFile(file) {
208
+ const name = (file.name ?? "upload.zip").toLowerCase();
209
+ if (!name.endsWith(".zip")) return { ok: false, error: "invalid_file_extension" };
210
+ if (file.size <= 0) return { ok: false, error: "empty_file" };
211
+ if (file.size > MAX_PLUGIN_ZIP_BYTES) return { ok: false, error: "file_too_large" };
212
+ return { ok: true, value: true };
213
+ }
214
+
215
+ // src/semver.ts
216
+ var CORE_SEMVER_RE = /^(\d+)\.(\d+)\.(\d+)/;
217
+ function nextPatchVersion(latest) {
218
+ if (!latest || typeof latest !== "string") return "0.1.0";
219
+ const m = latest.trim().match(CORE_SEMVER_RE);
220
+ if (!m) return "0.1.0";
221
+ const major = Number(m[1]);
222
+ const minor = Number(m[2]);
223
+ const patch = Number(m[3]);
224
+ if (![major, minor, patch].every((n) => Number.isFinite(n) && n >= 0)) return "0.1.0";
225
+ return `${major}.${minor}.${patch + 1}`;
226
+ }
227
+ function compareSemverDesc(a, b) {
228
+ const pa = a.match(CORE_SEMVER_RE);
229
+ const pb = b.match(CORE_SEMVER_RE);
230
+ if (!pa && !pb) return 0;
231
+ if (!pa) return 1;
232
+ if (!pb) return -1;
233
+ for (let i = 1; i <= 3; i++) {
234
+ const da = Number(pa[i]) - Number(pb[i]);
235
+ if (da !== 0) return da > 0 ? -1 : 1;
236
+ }
237
+ return 0;
238
+ }
239
+ var pluginManifestZodSchema = zod.z.object({
240
+ plugin_key: zod.z.string().regex(/^[a-z0-9][a-z0-9-_]{1,62}$/).optional().describe("Stable plugin id. Prefer this over legacy `id`."),
241
+ id: zod.z.string().optional().describe("Legacy alias for plugin_key (slashes become dashes)."),
242
+ plugin_name: zod.z.string().optional(),
243
+ name: zod.z.string().optional().describe("Legacy alias for plugin_name."),
244
+ plugin_type: zod.z.enum(["task", "form", "task_form", "route"]).optional(),
245
+ kind: zod.z.string().optional().describe("Legacy alias for plugin_type (task_widget\u2192task, record_panel\u2192form)."),
246
+ version: zod.z.string().optional().describe("Ignored by Cervio \u2014 the host assigns release versions."),
247
+ required_connection_capabilities: zod.z.array(zod.z.string()).optional(),
248
+ requiredConnectionCapabilities: zod.z.array(zod.z.string()).optional(),
249
+ connections: zod.z.array(
250
+ zod.z.object({
251
+ id: zod.z.string(),
252
+ provider: zod.z.string(),
253
+ scopes: zod.z.array(zod.z.string()),
254
+ allowed_apis: zod.z.array(
255
+ zod.z.object({
256
+ host: zod.z.string(),
257
+ methods: zod.z.array(zod.z.string()),
258
+ path_prefix: zod.z.string().optional(),
259
+ pathPrefix: zod.z.string().optional()
260
+ })
261
+ ).optional(),
262
+ allowedApis: zod.z.array(zod.z.unknown()).optional()
263
+ })
264
+ ).optional(),
265
+ entities: zod.z.array(
266
+ zod.z.object({
267
+ name: zod.z.string(),
268
+ fields: zod.z.array(zod.z.string()).optional(),
269
+ forms: zod.z.array(zod.z.string()).optional(),
270
+ access: zod.z.array(zod.z.enum(["read", "write"])).optional()
271
+ })
272
+ ).optional(),
273
+ cervio_apis: zod.z.array(
274
+ zod.z.object({
275
+ method: zod.z.string().optional(),
276
+ path_prefix: zod.z.string().optional(),
277
+ pathPrefix: zod.z.string().optional()
278
+ })
279
+ ).optional(),
280
+ cervioApis: zod.z.array(zod.z.unknown()).optional()
281
+ }).passthrough();
282
+ function normalizePluginKey(raw) {
283
+ return raw.trim().toLowerCase().replace(/[\/\s]+/g, "-").replace(/[^a-z0-9-_]/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
284
+ }
285
+ function resolvePluginType(raw) {
286
+ const kindMap = {
287
+ route: "route",
288
+ task: "task",
289
+ form: "form",
290
+ task_form: "task_form",
291
+ task_widget: "task",
292
+ record_panel: "form"
293
+ };
294
+ const candidate = kindMap[raw] ?? raw;
295
+ return ["task", "form", "task_form", "route"].includes(candidate) ? candidate : null;
296
+ }
297
+ function parseRequiredCapabilities(raw, allowed) {
298
+ if (!Array.isArray(raw)) return [];
299
+ const allowedSet = new Set(allowed);
300
+ const out = [];
301
+ const seen = /* @__PURE__ */ new Set();
302
+ for (const item of raw) {
303
+ if (typeof item !== "string") continue;
304
+ const id = item.trim().toLowerCase();
305
+ if (!id || !allowedSet.has(id) || seen.has(id)) continue;
306
+ seen.add(id);
307
+ out.push(id);
308
+ }
309
+ return out;
310
+ }
311
+ function parseManifestObject(parsed, options) {
312
+ const allowedCapabilities = options?.allowedCapabilities ?? DEFAULT_PLUGIN_DECLARABLE_CAPABILITIES;
313
+ const pluginKeyRaw = typeof parsed.plugin_key === "string" ? parsed.plugin_key : typeof parsed.id === "string" ? parsed.id.split("/").filter(Boolean).join("-") : "";
314
+ const pluginKey = normalizePluginKey(pluginKeyRaw);
315
+ if (!pluginKey || !PLUGIN_KEY_RE.test(pluginKey)) {
316
+ return { ok: false, error: "manifest_plugin_key_invalid" };
317
+ }
318
+ const pluginName = typeof parsed.plugin_name === "string" && parsed.plugin_name.trim() ? parsed.plugin_name.trim() : typeof parsed.name === "string" && parsed.name.trim() ? parsed.name.trim() : null;
319
+ const pluginTypeRaw = typeof parsed.plugin_type === "string" ? parsed.plugin_type.trim() : typeof parsed.kind === "string" ? parsed.kind.trim() : "";
320
+ const pluginType = resolvePluginType(pluginTypeRaw);
321
+ const manifestVersion = typeof parsed.version === "string" && parsed.version.trim() ? parsed.version.trim() : null;
322
+ const requiredRaw = parsed.required_connection_capabilities ?? parsed.requiredConnectionCapabilities ?? [];
323
+ const requiredConnectionCapabilities = parseRequiredCapabilities(
324
+ requiredRaw,
325
+ allowedCapabilities
326
+ );
327
+ const connections = parsePluginConnections(parsed.connections);
328
+ const entities = parsePluginEntityRequirements(parsed.entities);
329
+ const cervioApis = parsePluginCervioApiRequirements(
330
+ parsed.cervio_apis ?? parsed.cervioApis ?? []
331
+ );
332
+ return {
333
+ ok: true,
334
+ value: {
335
+ pluginKey,
336
+ pluginName,
337
+ pluginType,
338
+ manifestVersion,
339
+ requiredConnectionCapabilities,
340
+ connections,
341
+ entities,
342
+ cervioApis
343
+ }
344
+ };
345
+ }
346
+ function manifestJsonForContentHash(raw) {
347
+ const clone = { ...raw };
348
+ delete clone.version;
349
+ return JSON.stringify(clone);
350
+ }
351
+ async function loadZipFromBuffer(buffer) {
352
+ try {
353
+ const zip = await JSZip__default.default.loadAsync(buffer);
354
+ const safe = assertZipSafe(zip);
355
+ if (!safe.ok) return safe;
356
+ return { ok: true, value: zip };
357
+ } catch {
358
+ return { ok: false, error: "zip_invalid" };
359
+ }
360
+ }
361
+ async function parseZipManifest(file, options) {
362
+ const buffer = await file.arrayBuffer();
363
+ const zipRes = await loadZipFromBuffer(buffer);
364
+ if (!zipRes.ok) return zipRes;
365
+ const zip = zipRes.value;
366
+ const manifestEntry = zip.file("manifest.json") ?? zip.file("manifest.example.json") ?? Object.values(zip.files).find(
367
+ (f) => f.name.endsWith("/manifest.json") || f.name.endsWith("/manifest.example.json")
368
+ );
369
+ if (!manifestEntry) return { ok: false, error: "manifest_not_found_in_zip" };
370
+ const jsonText = await manifestEntry.async("text");
371
+ let parsed;
372
+ try {
373
+ parsed = JSON.parse(jsonText);
374
+ } catch {
375
+ return { ok: false, error: "manifest_invalid_json" };
376
+ }
377
+ const fields = parseManifestObject(parsed, options);
378
+ if (!fields.ok) return fields;
379
+ const hasDistIndex = !!zip.file("dist/index.html");
380
+ if (!hasDistIndex) return { ok: false, error: "build_index_missing" };
381
+ const hasDistAssets = Object.keys(zip.files).some((name) => /^dist\/assets\/.+/.test(name));
382
+ if (!hasDistAssets) return { ok: false, error: "build_assets_missing" };
383
+ return {
384
+ ok: true,
385
+ value: {
386
+ ...fields.value,
387
+ artifactEntryPath: "dist/index.html",
388
+ rawManifest: parsed,
389
+ manifestEntryName: manifestEntry.name
390
+ }
391
+ };
392
+ }
393
+ async function computePluginContentSha256(zip, rawManifest) {
394
+ try {
395
+ const hash = crypto.createHash("sha256");
396
+ hash.update("manifest\0");
397
+ hash.update(manifestJsonForContentHash(rawManifest));
398
+ hash.update("\0");
399
+ const distPaths = Object.keys(zip.files).filter((name) => {
400
+ const entry = zip.files[name];
401
+ if (!entry || entry.dir) return false;
402
+ const normalized = name.replace(/^\.\//, "");
403
+ return normalized === "dist" || normalized.startsWith("dist/");
404
+ }).map((name) => name.replace(/^\.\//, "")).sort((a, b) => a.localeCompare(b));
405
+ for (const path2 of distPaths) {
406
+ const entry = zip.file(path2);
407
+ if (!entry || entry.dir) continue;
408
+ const bytes = await entry.async("uint8array");
409
+ hash.update("file\0");
410
+ hash.update(path2);
411
+ hash.update("\0");
412
+ hash.update(bytes);
413
+ hash.update("\0");
414
+ }
415
+ return { ok: true, value: hash.digest("hex") };
416
+ } catch {
417
+ return { ok: false, error: "content_hash_failed" };
418
+ }
419
+ }
420
+ function sha256Hex(buffer) {
421
+ return crypto.createHash("sha256").update(buffer).digest("hex");
422
+ }
423
+ async function collectFiles(dir, base = "") {
424
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
425
+ const out = [];
426
+ for (const entry of entries) {
427
+ const abs = path__default.default.join(dir, entry.name);
428
+ const rel = base ? `${base}/${entry.name}` : entry.name;
429
+ if (entry.isDirectory()) {
430
+ out.push(...await collectFiles(abs, rel));
431
+ } else if (entry.isFile()) {
432
+ out.push({ rel: rel.replace(/\\/g, "/"), abs });
433
+ }
434
+ }
435
+ return out;
436
+ }
437
+ async function packPlugin(opts) {
438
+ const root = path__default.default.resolve(opts.dir);
439
+ const manifestPath = path__default.default.join(root, "manifest.json");
440
+ let manifestRaw;
441
+ try {
442
+ const text = await fs.promises.readFile(manifestPath, "utf8");
443
+ manifestRaw = JSON.parse(text);
444
+ } catch {
445
+ return { ok: false, error: "manifest_not_found_in_zip" };
446
+ }
447
+ const fields = parseManifestObject(manifestRaw, opts.options);
448
+ if (!fields.ok) return fields;
449
+ const distIndex = path__default.default.join(root, "dist", "index.html");
450
+ try {
451
+ await fs.promises.access(distIndex);
452
+ } catch {
453
+ return { ok: false, error: "build_index_missing" };
454
+ }
455
+ const zip = new JSZip__default.default();
456
+ const files = await collectFiles(root);
457
+ let hasAssets = false;
458
+ for (const file of files) {
459
+ if (file.rel.startsWith(".cervio/") || file.rel === "node_modules" || file.rel.startsWith("node_modules/")) {
460
+ continue;
461
+ }
462
+ if (file.rel.startsWith("dist/assets/") && file.rel !== "dist/assets/") {
463
+ hasAssets = true;
464
+ }
465
+ const data = await fs.promises.readFile(file.abs);
466
+ zip.file(file.rel, data);
467
+ }
468
+ if (!hasAssets) return { ok: false, error: "build_assets_missing" };
469
+ const safe = assertZipSafe(zip);
470
+ if (!safe.ok) return safe;
471
+ const buffer = Buffer.from(await zip.generateAsync({ type: "uint8array", compression: "DEFLATE" }));
472
+ const fileCheck = assertZipFile({ name: `${fields.value.pluginKey}.zip`, size: buffer.length });
473
+ if (!fileCheck.ok) return fileCheck;
474
+ const loaded = await loadZipFromBuffer(buffer);
475
+ if (!loaded.ok) return loaded;
476
+ const hash = await computePluginContentSha256(loaded.value, manifestRaw);
477
+ if (!hash.ok) return hash;
478
+ return {
479
+ ok: true,
480
+ value: {
481
+ buffer,
482
+ pluginKey: fields.value.pluginKey,
483
+ contentSha256: hash.value,
484
+ sizeBytes: buffer.length
485
+ }
486
+ };
487
+ }
488
+ async function validatePluginDir(dir, options) {
489
+ const packed = await packPlugin({ dir, options });
490
+ if (!packed.ok) return packed;
491
+ const blob = new Blob([packed.value.buffer], { type: "application/zip" });
492
+ const parsed = await parseZipManifest(blob, options);
493
+ if (!parsed.ok) return parsed;
494
+ return {
495
+ ok: true,
496
+ value: {
497
+ pluginKey: packed.value.pluginKey,
498
+ contentSha256: packed.value.contentSha256
499
+ }
500
+ };
501
+ }
502
+ async function validatePluginZipBuffer(buffer, options) {
503
+ const fileCheck = assertZipFile({ name: "plugin.zip", size: buffer.length });
504
+ if (!fileCheck.ok) return fileCheck;
505
+ const blob = new Blob([buffer], { type: "application/zip" });
506
+ const parsed = await parseZipManifest(blob, options);
507
+ if (!parsed.ok) return parsed;
508
+ const zipRes = await loadZipFromBuffer(buffer);
509
+ if (!zipRes.ok) return zipRes;
510
+ const hash = await computePluginContentSha256(zipRes.value, parsed.value.rawManifest);
511
+ if (!hash.ok) return hash;
512
+ return {
513
+ ok: true,
514
+ value: { pluginKey: parsed.value.pluginKey, contentSha256: hash.value }
515
+ };
516
+ }
517
+
518
+ exports.DEFAULT_PLUGIN_DECLARABLE_CAPABILITIES = DEFAULT_PLUGIN_DECLARABLE_CAPABILITIES;
519
+ exports.EXTERNAL_CONNECTION_ALLOWED_HOSTS = EXTERNAL_CONNECTION_ALLOWED_HOSTS;
520
+ exports.EXTERNAL_CONNECTION_HTTP_METHODS = EXTERNAL_CONNECTION_HTTP_METHODS;
521
+ exports.MAX_PLUGIN_UNCOMPRESSED_BYTES = MAX_PLUGIN_UNCOMPRESSED_BYTES;
522
+ exports.MAX_PLUGIN_ZIP_BYTES = MAX_PLUGIN_ZIP_BYTES;
523
+ exports.MAX_PLUGIN_ZIP_ENTRIES = MAX_PLUGIN_ZIP_ENTRIES;
524
+ exports.OAUTH_PROVIDER_KEY_RE = OAUTH_PROVIDER_KEY_RE;
525
+ exports.PLUGIN_ARTIFACT_BUCKET = PLUGIN_ARTIFACT_BUCKET;
526
+ exports.PLUGIN_KEY_RE = PLUGIN_KEY_RE;
527
+ exports.PLUGIN_VERSION_SELECT = PLUGIN_VERSION_SELECT;
528
+ exports.assertZipFile = assertZipFile;
529
+ exports.assertZipSafe = assertZipSafe;
530
+ exports.compareSemverDesc = compareSemverDesc;
531
+ exports.computePluginContentSha256 = computePluginContentSha256;
532
+ exports.isExternalConnectionProvider = isExternalConnectionProvider;
533
+ exports.loadZipFromBuffer = loadZipFromBuffer;
534
+ exports.manifestJsonForContentHash = manifestJsonForContentHash;
535
+ exports.nextPatchVersion = nextPatchVersion;
536
+ exports.normalizeExactApiHost = normalizeExactApiHost;
537
+ exports.normalizePluginKey = normalizePluginKey;
538
+ exports.packPlugin = packPlugin;
539
+ exports.parseManifestObject = parseManifestObject;
540
+ exports.parsePluginCervioApiRequirements = parsePluginCervioApiRequirements;
541
+ exports.parsePluginConnections = parsePluginConnections;
542
+ exports.parsePluginEntityRequirements = parsePluginEntityRequirements;
543
+ exports.parseZipManifest = parseZipManifest;
544
+ exports.pluginManifestZodSchema = pluginManifestZodSchema;
545
+ exports.sha256Hex = sha256Hex;
546
+ exports.validatePluginDir = validatePluginDir;
547
+ exports.validatePluginZipBuffer = validatePluginZipBuffer;
548
+ //# sourceMappingURL=index.cjs.map
549
+ //# sourceMappingURL=index.cjs.map