@mosetta/build 0.0.35 → 0.0.37

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mosetta/build
2
2
 
3
+ ## 0.0.37
4
+
5
+ ### Patch Changes
6
+
7
+ - @mosetta/router@0.0.37
8
+ - @mosetta/runtime@0.0.37
9
+ - @mosetta/server@0.0.37
10
+ - @mosetta/server-action@0.0.37
11
+ - @mosetta/tar@0.0.37
12
+
13
+ ## 0.0.36
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+ - @mosetta/server-action@0.0.36
19
+ - @mosetta/runtime@0.0.36
20
+ - @mosetta/server@0.0.36
21
+ - @mosetta/router@0.0.36
22
+ - @mosetta/tar@0.0.36
23
+
3
24
  ## 0.0.35
4
25
 
5
26
  - Compile the identity, scoped content and private service contracts into distribution metadata.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosetta/build",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "license": "MIT",
5
5
  "description": "The core of the tile forge: builds a tile palette — its tile side artifacts, their dependency closure, the tile host descriptor. Environment-agnostic — the file system and the bundling engine are supplied from outside.",
6
6
  "type": "module",
@@ -28,11 +28,11 @@
28
28
  "scheduler": "*",
29
29
  "systemjs": "^6.15.1",
30
30
  "yaml": "^2.9.0",
31
- "@mosetta/router": "0.0.35",
32
- "@mosetta/server": "0.0.35",
33
- "@mosetta/server-action": "0.0.35",
34
- "@mosetta/runtime": "0.0.35",
35
- "@mosetta/tar": "0.0.35"
31
+ "@mosetta/router": "0.0.37",
32
+ "@mosetta/runtime": "0.0.37",
33
+ "@mosetta/server": "0.0.37",
34
+ "@mosetta/server-action": "0.0.37",
35
+ "@mosetta/tar": "0.0.37"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
package/src/build.mjs CHANGED
@@ -83,9 +83,12 @@ async function offersOf(jsCode, evaluate) {
83
83
  if (!res.ok) return null;
84
84
  const said = await res.json();
85
85
  if (!Array.isArray(said?.actions) || !Array.isArray(said?.handlers)) return null;
86
- // every action, with what it offers (a tool, an address) — the site's editors may bind any of them
86
+ // every action, with what it offers (a tool, an address, declared permissions) — the site's editors may bind any of them
87
87
  // to an address, those that offer themselves first
88
- return said.actions.length || said.handlers.length ? { actions: said.actions, handlers: said.handlers } : null;
88
+ const permissions = Array.isArray(said.permissions) && said.permissions.length ? said.permissions : null;
89
+ return said.actions.length || said.handlers.length || permissions
90
+ ? { actions: said.actions, handlers: said.handlers, ...(permissions ? { permissions } : {}) }
91
+ : null;
89
92
  } catch {
90
93
  return null;
91
94
  }
@@ -372,6 +375,7 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
372
375
  // title, description, icon, cover and where its source lives. The descriptor is the root's
373
376
  // mosetta.json; the description falls back to package.json's, the source to its `repository`
374
377
  // (url + directory). Files ship in the entity's folder under names of their content.
378
+ const distributionByNamespace = new Map();
375
379
  for (const r of builtRoots) {
376
380
  // the APP's own prefabs are its site's content (the picker's "prefabs of this site"), not a
377
381
  // distribution: the app counts only for blocks of its own
@@ -408,6 +412,7 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
408
412
  }
409
413
  out.set(`${PUB}/modules/${descriptor.id}/${descriptor.id}.json`, JSON.stringify(descriptor, null, 2));
410
414
  entityDescriptors.push(descriptor);
415
+ distributionByNamespace.set(r.namespace, { root: r, descriptor });
411
416
  }
412
417
 
413
418
  // 4) manifests + prefabs (namespaces.json is dead — namespaces derive from the catalog).
@@ -437,8 +442,6 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
437
442
  });
438
443
  }
439
444
 
440
- const entityCatalog = [...moduleResults.map((r) => r.descriptor), ...entityDescriptors];
441
- out.set(`${PUB}/modules.json`, JSON.stringify(entityCatalog, null, 2));
442
445
  const pages = discoverPagesIn(fileSystem, root, log);
443
446
  for (const pg of pages) out.set(`${PUB}/pages/${pg.name}.json`, JSON.stringify(pg.json, null, 2));
444
447
 
@@ -467,6 +470,7 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
467
470
  privateDescriptors.push(descriptor);
468
471
  };
469
472
  const serverMods = builtRoots.flatMap((r) => discoverServerModulesIn(fileSystem, r));
473
+ const actionPermissionsByNamespace = new Map();
470
474
  let serverCount = 0;
471
475
  for (const sm of serverMods) {
472
476
  try {
@@ -484,6 +488,11 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
484
488
  for (const [assetName, srcFile] of s.wasmAssets) {
485
489
  out.set(`private/modules/${s.full}/${assetName}`, fileSystem.readFile(srcFile));
486
490
  }
491
+ if (s.offers?.permissions?.length) {
492
+ const list = actionPermissionsByNamespace.get(sm.namespace) ?? [];
493
+ list.push(...s.offers.permissions);
494
+ actionPermissionsByNamespace.set(sm.namespace, list);
495
+ }
487
496
  recordPrivate(s.full, { namespace: sm.namespace, name: sm.name, type: 'server', version: sm.version },
488
497
  s.offers ? { offers: s.offers } : {}, [...s.wasmAssets.keys()]);
489
498
  record(sm, 'server', s.jsCode.length, 'private'
@@ -494,6 +503,22 @@ export async function build(root, { mode = 'development', log, fileSystem, resol
494
503
  + ` — skipped; needs @mosetta/server-action Web-API port`);
495
504
  }
496
505
  }
506
+ for (const [namespace, declared] of actionPermissionsByNamespace) {
507
+ let entry = distributionByNamespace.get(namespace);
508
+ if (!entry) {
509
+ const matchedRoot = builtRoots.find((r) => r.namespace === namespace);
510
+ if (!matchedRoot) continue;
511
+ const descriptor = distributionDescriptor(fileSystem, matchedRoot, () => null);
512
+ entityDescriptors.push(descriptor);
513
+ entry = { root: matchedRoot, descriptor };
514
+ distributionByNamespace.set(namespace, entry);
515
+ }
516
+ const merged = mergePermissionDefinitions(namespace, entry.descriptor.permissions, declared);
517
+ if (merged.length) entry.descriptor.permissions = merged;
518
+ out.set(`${PUB}/modules/${entry.descriptor.id}/${entry.descriptor.id}.json`, JSON.stringify(entry.descriptor, null, 2));
519
+ }
520
+ const entityCatalog = [...moduleResults.map((r) => r.descriptor), ...entityDescriptors];
521
+ out.set(`${PUB}/modules.json`, JSON.stringify(entityCatalog, null, 2));
497
522
  // no glue artifacts anymore: the UNIVERSAL glue is embedded in the runner and
498
523
  // composed with every isolate — monoliths carry their aspects themselves.
499
524
 
@@ -565,7 +590,7 @@ const SERVICE_GRANT_RE = /^(?:@(?:previews|media|code|repositories)|[a-z][a-z0-9
565
590
  /** an action of the palette named for a workbench: `<tile>.<action>` */
566
591
  const WORKBENCH_ACTION_RE = /^[a-z][A-Za-z0-9]{0,63}\.[A-Za-z][A-Za-z0-9_]{0,63}$/;
567
592
  /** the parts a palette may play in a workbench (@mosetta/content/workbench) */
568
- const WORKBENCH_ROLES = ['assistant', 'transcribe', 'tools', 'icon'];
593
+ const WORKBENCH_ROLES = ['assistant', 'transcribe', 'translate', 'tools', 'icon'];
569
594
 
570
595
  /**
571
596
  * A distribution's offer of itself as a service (mosetta.json `service: { grant: [...] }`): what it
@@ -605,12 +630,12 @@ export function workbenchOf(raw) {
605
630
  }
606
631
 
607
632
  /** Operations a palette declares under its own brand for a project's role catalogue. */
608
- export function permissionDefinitionsOf(brand, raw) {
633
+ export function permissionDefinitionsOf(brand, raw, source = 'mosetta.json') {
609
634
  if (raw === undefined) return [];
610
- if (!Array.isArray(raw) || raw.length > 200) throw new Error(`mosetta.json: ${brand} permissions must be an array of at most 200 operations`);
635
+ if (!Array.isArray(raw) || raw.length > 200) throw new Error(`${source}: ${brand} permissions must be an array of at most 200 operations`);
611
636
  const seen = new Set();
612
637
  return raw.map((permission, index) => {
613
- const at = `mosetta.json: ${brand} permissions[${index}]`;
638
+ const at = `${source}: ${brand} permissions[${index}]`;
614
639
  if (!permission || typeof permission !== 'object' || Array.isArray(permission)
615
640
  || Object.keys(permission).some((key) => !['name', 'title', 'about', 'target'].includes(key))) {
616
641
  throw new Error(`${at} requires name, title, about and target`);
@@ -627,6 +652,40 @@ export function permissionDefinitionsOf(brand, raw) {
627
652
  });
628
653
  }
629
654
 
655
+ /** Merge palette permissions declared in mosetta.json and on server actions/endpoints. */
656
+ export function mergePermissionDefinitions(brand, configured = [], fromActions = []) {
657
+ const merged = new Map();
658
+ for (const permission of permissionDefinitionsOf(brand, configured, 'mosetta.json')) {
659
+ merged.set(permission.name, permission);
660
+ }
661
+ const normalizedActions = fromActions.map((entry, index) => {
662
+ const at = `server actions: ${brand} permissions[${index}]`;
663
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)
664
+ || Object.keys(entry).some((key) => !['name', 'title', 'about', 'target'].includes(key))) {
665
+ throw new Error(`${at} requires name, title, about and target`);
666
+ }
667
+ const { name, title, about, target } = entry;
668
+ if (typeof name !== 'string' || name.length > 200 || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*$/.test(name)
669
+ || !name.startsWith(`${brand}.`)) throw new Error(`${at} name must be an explicit operation under ${brand}.`);
670
+ if (typeof title !== 'string' || !title.trim() || title.length > 160
671
+ || typeof about !== 'string' || !about.trim() || about.length > 2000) throw new Error(`${at} requires a title and description`);
672
+ if (target !== 'resource' && target !== 'project') throw new Error(`${at} target must be resource or project`);
673
+ return { name, title: title.trim(), about: about.trim(), target };
674
+ });
675
+ for (const permission of normalizedActions) {
676
+ const existing = merged.get(permission.name);
677
+ if (existing) {
678
+ if (existing.target !== permission.target || existing.title !== permission.title || existing.about !== permission.about) {
679
+ throw new Error(`server actions: ${brand} conflicts with existing permission ${permission.name}`);
680
+ }
681
+ continue;
682
+ }
683
+ if (merged.size >= 200) throw new Error(`${brand} permissions must have at most 200 operations`);
684
+ merged.set(permission.name, permission);
685
+ }
686
+ return [...merged.values()];
687
+ }
688
+
630
689
  /**
631
690
  * A distribution's catalog entity: what it calls itself, from its mosetta.json (title,
632
691
  * description, icon, cover, source) with package.json behind the description and the source.