@underpostnet/cyberia 3.3.76 → 3.4.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.
Files changed (132) hide show
  1. package/.env.example +1 -0
  2. package/.github/workflows/coverall.cyberia.ci.yml +17 -3
  3. package/.github/workflows/cyberia-client.cd.yml +2 -1
  4. package/.github/workflows/cyberia-server.cd.yml +2 -1
  5. package/.github/workflows/docker-image.cyberia-client.ci.yml +1 -1
  6. package/.github/workflows/docker-image.cyberia-client.dev.ci.yml +1 -1
  7. package/.github/workflows/docker-image.cyberia-server.ci.yml +1 -1
  8. package/.github/workflows/docker-image.cyberia-server.dev.ci.yml +1 -1
  9. package/.github/workflows/docker-image.engine-cyberia.ci.yml +1 -1
  10. package/.github/workflows/docker-image.engine-cyberia.dev.ci.yml +1 -1
  11. package/.github/workflows/engine-cyberia.ci.yml +7 -1
  12. package/.github/workflows/ghpkg.ci.yml +19 -2
  13. package/.github/workflows/gitlab.ci.yml +8 -6
  14. package/.github/workflows/hardhat.ci.yml +4 -1
  15. package/.github/workflows/npmpkg.ci.yml +9 -5
  16. package/.github/workflows/publish.ci.yml +21 -12
  17. package/.github/workflows/publish.cyberia.ci.yml +25 -14
  18. package/.github/workflows/pwa-microservices-template-page.cd.yml +4 -2
  19. package/CHANGELOG.md +110 -262
  20. package/CLI-HELP.md +29 -2
  21. package/Dockerfile +1 -1
  22. package/Dockerfile.dev +1 -1
  23. package/Dockerfile.test +1 -1
  24. package/README.md +1 -1
  25. package/bin/build.js +67 -14
  26. package/bin/cyberia.js +4 -4
  27. package/bin/index.js +4 -4
  28. package/compose.env +1 -0
  29. package/conf.js +1 -1043
  30. package/deploy/cyberia-client/deploy.sh +13 -11
  31. package/deploy/cyberia-server/deploy.sh +13 -11
  32. package/deploy/dd-cyberia/sync-deploy.sh +7 -28
  33. package/deploy/lib/config.sh +1 -1
  34. package/deploy/lib/github-actions-logging.sh +3 -2
  35. package/deploy/lib/host.sh +1 -1
  36. package/deploy/pwa-microservices-template/deploy.sh +7 -1
  37. package/deployment.yaml +1 -1
  38. package/docker-compose.yml +7 -7
  39. package/docs/coverage/cyberia/api/cyberia-instance/cyberia-fallback-capture.js.html +1591 -0
  40. package/docs/coverage/cyberia/api/cyberia-instance/index.html +116 -0
  41. package/docs/coverage/cyberia/api/cyberia-server-defaults/cyberia-server-defaults.js.html +4138 -0
  42. package/docs/coverage/cyberia/api/cyberia-server-defaults/index.html +116 -0
  43. package/docs/coverage/cyberia/api/object-layer/index.html +116 -0
  44. package/docs/coverage/cyberia/api/object-layer/object-layer.model.js.html +1393 -0
  45. package/docs/coverage/cyberia/base.css +362 -0
  46. package/docs/coverage/cyberia/block-navigation.js +82 -0
  47. package/docs/coverage/cyberia/favicon.png +0 -0
  48. package/docs/coverage/cyberia/index.html +161 -0
  49. package/docs/coverage/cyberia/prettify.css +101 -0
  50. package/docs/coverage/cyberia/prettify.js +937 -0
  51. package/docs/coverage/cyberia/projects/cyberia/atlas-sprite-sheet-generator.js.html +1315 -0
  52. package/docs/coverage/cyberia/projects/cyberia/index.html +176 -0
  53. package/docs/coverage/cyberia/projects/cyberia/instance-backup.js.html +715 -0
  54. package/docs/coverage/cyberia/projects/cyberia/instance-data.js.html +2182 -0
  55. package/docs/coverage/cyberia/projects/cyberia/shape-generator.js.html +3265 -0
  56. package/docs/coverage/cyberia/projects/cyberia/stat-balance.js.html +328 -0
  57. package/docs/coverage/cyberia/sort-arrow-sprite.png +0 -0
  58. package/docs/coverage/cyberia/sorter.js +205 -0
  59. package/hardhat/package-lock.json +6 -6
  60. package/hardhat/package.json +2 -2
  61. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
  62. package/manifests/cronjobs/dd-cron/dd-cron-vultr.yaml +1 -1
  63. package/manifests/deployment/dd-cyberia-development/deployment.yaml +1 -1
  64. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  65. package/package.json +19 -17
  66. package/scripts/test-monitor.sh +1 -1
  67. package/src/api/file/file.router.js +7 -1
  68. package/src/cli/baremetal.js +1 -1
  69. package/src/cli/cluster.js +73 -18
  70. package/src/cli/deploy.js +211 -30
  71. package/src/cli/docker-compose.js +1 -1
  72. package/src/cli/index.js +36 -0
  73. package/src/cli/kubectl.js +4 -3
  74. package/src/cli/release.js +5 -1
  75. package/src/cli/repository.js +14 -11
  76. package/src/cli/run.js +10 -3
  77. package/src/cli/secrets.js +393 -200
  78. package/src/cli/socketsecurity.js +260 -0
  79. package/src/client/components/core/Badge.js +0 -1
  80. package/src/client/components/core/CssCore.js +11 -1
  81. package/src/client/components/core/Modal.js +189 -66
  82. package/src/client/components/core/SearchBox.js +0 -1
  83. package/src/client/components/core/ToolTip.js +15 -0
  84. package/src/client/components/cryptokoyn/AppShellCryptokoyn.js +0 -2
  85. package/src/client/components/cyberia-portal/RouterCyberiaPortal.js +0 -4
  86. package/src/client/components/default/AppShellDefault.js +1 -4
  87. package/src/client/components/itemledger/AppShellItemledger.js +0 -2
  88. package/src/client/components/underpost/AppShellUnderpost.js +12 -0
  89. package/src/client/components/underpost/CssUnderpost.js +15 -2
  90. package/src/client/public/cyberia-docs/CYBERIA-CLIENT.md +8 -0
  91. package/src/client/public/cyberia-docs/CYBERIA.md +1 -1
  92. package/src/client/public/cyberia-docs/OFF-CHAIN-ECONOMY.md +54 -56
  93. package/src/client/public/cyberia-docs/ROADMAP.md +1 -1
  94. package/src/client/public/cyberia-docs/UNDERPOST-PLATFORM.md +30 -29
  95. package/src/client/public/cyberia-docs/WHITE-PAPER.md +1 -1
  96. package/src/client/ssr/body/UnderpostDefaultSplashScreen.js +54 -25
  97. package/src/client/ssr/head/Css.js +12 -10
  98. package/src/client/ssr/views/Cyberia404.js +9 -13
  99. package/src/client/ssr/views/NotFound.js +75 -0
  100. package/src/client-builder/client-bundle.js +2 -2
  101. package/src/index.js +13 -1
  102. package/src/runtime/engine-cyberia/Dockerfile +1 -1
  103. package/src/runtime/engine-cyberia/Dockerfile.dev +1 -1
  104. package/src/runtime/engine-cyberia/Dockerfile.test +1 -1
  105. package/src/runtime/engine-cyberia/compose.env +1 -0
  106. package/src/runtime/engine-cyberia/docker-compose.yml +7 -7
  107. package/src/server/build/catalog.js +1 -0
  108. package/src/server/build/execution.js +19 -5
  109. package/src/server/build/package.js +166 -3
  110. package/src/server/build/testing.js +2 -1
  111. package/src/server/network/underpost-gateway.js +113 -14
  112. package/src/server/runtime/conf.js +57 -7
  113. package/src/server/runtime/config-scope.js +2 -0
  114. package/src/server/runtime/process.js +4 -3
  115. package/src/server/runtime/start.js +11 -2
  116. package/src/server/security/socketsecurity.js +1735 -0
  117. package/test/integration/infra/1-security/config-scope.test.js +3 -0
  118. package/test/integration/infra/1-security/socketsecurity.test.js +1041 -0
  119. package/test/integration/infra/1-security/sops-secret-store.test.js +201 -71
  120. package/test/integration/infra/4-ingress/underpost-ingress.test.js +1 -1
  121. package/test/unit/build-template.test.js +24 -0
  122. package/test/unit/catalog.test.js +13 -2
  123. package/test/unit/conf-resolution.test.js +41 -7
  124. package/test/unit/cyberia/instance-data.test.js +314 -0
  125. package/test/unit/deploy-legacy-gateway-sweep.test.js +63 -0
  126. package/test/unit/deploy-log-table.test.js +38 -0
  127. package/test/unit/execution-profiles.test.js +1 -0
  128. package/test/unit/gateway-pod-fetch.test.js +95 -0
  129. package/test/unit/letsencrypt-issuer.test.js +101 -0
  130. package/test/unit/package.test.js +118 -0
  131. package/test/unit/release-bump.test.js +3 -1
  132. package/test/unit/start-options.test.js +12 -0
@@ -135,7 +135,7 @@ services:
135
135
  # server starts but rejects connections until seeded). Serves REST/WS on 4005
136
136
  # and the engine gRPC data service on 50051.
137
137
  engine-cyberia-runtime:
138
- image: ${ENGINE_CYBERIA_IMAGE:-underpost/engine-cyberia-dev}:${ENGINE_CYBERIA_TAG:-v3.3.76}
138
+ image: ${ENGINE_CYBERIA_IMAGE:-underpost/engine-cyberia-dev}:${ENGINE_CYBERIA_TAG:-v3.4.0}
139
139
  container_name: dd-cyberia-engine
140
140
  command:
141
141
  - /bin/sh
@@ -190,7 +190,7 @@ services:
190
190
  # gateway on host port 8081, so one port can route every instance path.
191
191
 
192
192
  cyberia-server-runtime:
193
- image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.3.76}
193
+ image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.4.0}
194
194
  container_name: dd-cyberia-server
195
195
  environment:
196
196
  INSTANCE_CODE: amethyst-strata-expansion
@@ -228,7 +228,7 @@ services:
228
228
  restart: unless-stopped
229
229
 
230
230
  cyberia-server-forest:
231
- image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.3.76}
231
+ image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.4.0}
232
232
  container_name: dd-cyberia-server-forest
233
233
  environment:
234
234
  INSTANCE_CODE: FOREST
@@ -266,7 +266,7 @@ services:
266
266
  restart: unless-stopped
267
267
 
268
268
  cyberia-server-test:
269
- image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.3.76}
269
+ image: ${CYBERIA_SERVER_IMAGE:-underpost/cyberia-server-dev}:${CYBERIA_SERVER_TAG:-v3.4.0}
270
270
  container_name: dd-cyberia-server-test
271
271
  environment:
272
272
  INSTANCE_CODE: TEST
@@ -315,7 +315,7 @@ services:
315
315
  # cyberia-server-test -> cyberia-client-test
316
316
 
317
317
  cyberia-client-runtime:
318
- image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.3.76}
318
+ image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.4.0}
319
319
  container_name: dd-cyberia-client
320
320
  environment:
321
321
  CYBERIA_PORT: '8081'
@@ -340,7 +340,7 @@ services:
340
340
  restart: unless-stopped
341
341
 
342
342
  cyberia-client-forest:
343
- image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.3.76}
343
+ image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.4.0}
344
344
  container_name: dd-cyberia-client-forest
345
345
  environment:
346
346
  CYBERIA_PORT: '8081'
@@ -365,7 +365,7 @@ services:
365
365
  restart: unless-stopped
366
366
 
367
367
  cyberia-client-test:
368
- image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.3.76}
368
+ image: ${CYBERIA_CLIENT_IMAGE:-underpost/cyberia-client-dev}:${CYBERIA_CLIENT_TAG:-v3.4.0}
369
369
  container_name: dd-cyberia-client-test
370
370
  environment:
371
371
  CYBERIA_PORT: '8081'
@@ -71,6 +71,7 @@ const loadDeployCatalog = async (deployId) => {
71
71
  */
72
72
  const loadProductCatalogs = async () => {
73
73
  const catalogs = [];
74
+ if (!fs.existsSync('./src/projects')) return catalogs;
74
75
  for (const file of await fs.readdir('./src/projects')) {
75
76
  if (file === 'underpost') continue;
76
77
  const mod = await import(`../../projects/${file}/catalog-${file}.js`);
@@ -154,10 +154,23 @@ const HOST_WRITE_BINARIES = new Set([
154
154
  'haproxy',
155
155
  ]);
156
156
 
157
- // `gh` reaches a remote service and writes to it (`gh secret set`, `gh release create`), so it
158
- // is a network effect rather than local filesystem work — an unclassified binary would default
159
- // to `fs` and run under HERMETIC_BUILD.
160
- const NET_BINARIES = new Set(['curl', 'wget', 'ssh', 'scp', 'sftp', 'rsync', 'nc', 'ping', 'dig', 'nslookup', 'gh']);
157
+ // `gh` and `socket` reach a remote service and write to it (`gh secret set`, `socket scan create`),
158
+ // so they are a network effect rather than local filesystem work — an unclassified binary would
159
+ // default to `fs` and run under HERMETIC_BUILD.
160
+ const NET_BINARIES = new Set([
161
+ 'curl',
162
+ 'wget',
163
+ 'ssh',
164
+ 'scp',
165
+ 'sftp',
166
+ 'rsync',
167
+ 'nc',
168
+ 'ping',
169
+ 'dig',
170
+ 'nslookup',
171
+ 'gh',
172
+ 'socket',
173
+ ]);
161
174
 
162
175
  const CLUSTER_BINARIES = new Set(['kubectl', 'helm']);
163
176
 
@@ -200,7 +213,8 @@ const classifySegment = (segment) => {
200
213
  // Leading `VAR=value` assignments are not the command.
201
214
  let start = 0;
202
215
  while (start < bare.length && /^[A-Z_][A-Z0-9_]*=/i.test(bare[start])) start++;
203
- const binary = nodePath.basename(bare[start] ?? '');
216
+ // A quoted binary path (`'/x/.bin/socket' scan`) names the same binary as the bare one.
217
+ const binary = nodePath.basename(bare[start] ?? '').replace(/^['"]|['"]$/g, '');
204
218
  const rest = bare.slice(start);
205
219
 
206
220
  if (CLUSTER_BINARIES.has(binary)) {
@@ -6,12 +6,13 @@
6
6
  */
7
7
 
8
8
  import fs from 'fs-extra';
9
+ import { builtinModules } from 'node:module';
9
10
  import os from 'node:os';
10
11
  import nodePath from 'node:path';
11
12
  import { fileURLToPath } from 'node:url';
12
13
  import { loggerFactory } from '../ops/logger.js';
13
14
  import { shellArgumentFactory, shellExec } from '../runtime/process.js';
14
- import { loadDeployCatalog } from './catalog.js';
15
+ import { loadDeployCatalog, loadProductCatalogs } from './catalog.js';
15
16
 
16
17
  const logger = loggerFactory(import.meta);
17
18
  const ENGINE_PACKAGE_PATH = fileURLToPath(new URL('../../../', import.meta.url));
@@ -19,6 +20,31 @@ const STAGED_CLI_PACKAGE = 'underpost-cli.tgz';
19
20
  const DEPLOY_CONF_ROOT = './engine-private/conf';
20
21
  const DEPLOY_MANIFEST_INDENT = 4;
21
22
 
23
+ /**
24
+ * Modules a production install executes: the CLI, the servers, the client build, and the
25
+ * browser bundles the build compiles. What they import statically has to resolve from
26
+ * `dependencies`, because the runtime images install the package with `--omit=dev`.
27
+ * @constant {string[]}
28
+ * @memberof PackageBuilder
29
+ */
30
+ const RUNTIME_ENTRY_POINTS = [
31
+ 'bin/index.js',
32
+ 'src/server.js',
33
+ 'src/api.js',
34
+ 'src/proxy.js',
35
+ 'src/client.build.js',
36
+ 'src/client/*.index.js',
37
+ 'src/client/sw/*.js',
38
+ // Loaded by name from a deploy's configuration, so no static import reaches them.
39
+ 'src/api/*/*.js',
40
+ 'src/ws/*/*.js',
41
+ 'src/grpc/*/*.js',
42
+ 'src/projects/*/*.js',
43
+ ];
44
+ const BUILTINS = new Set(builtinModules);
45
+ // A dynamic import whose argument is not a string literal; esbuild would expand it into a glob.
46
+ const NON_LITERAL_IMPORT = /\bimport\((?!\s*(['"])[^'"\n]*\1\s*\))/g;
47
+
22
48
  /**
23
49
  * Packs an npm package into a build context under a stable file name.
24
50
  *
@@ -195,17 +221,23 @@ const buildProductPackageJson = ({
195
221
  * @param {object} params.packageJson - The repository's manifest.
196
222
  * @param {object} [params.catalog] - That product's catalog.
197
223
  * @param {string} [params.underpostVersion] - Engine CLI version to pin; the manifest's own otherwise.
224
+ * @param {string} [params.underpostPackageName] - The engine package the tarball depends on; `underpost` otherwise.
198
225
  * @returns {object} The manifest to publish.
199
226
  * @memberof PackageBuilder
200
227
  */
201
- const publishedProductPackageJson = ({ packageJson, catalog = {}, underpostVersion = '' } = {}) => {
228
+ const publishedProductPackageJson = ({
229
+ packageJson,
230
+ catalog = {},
231
+ underpostVersion = '',
232
+ underpostPackageName = 'underpost',
233
+ } = {}) => {
202
234
  if (!packageJson || typeof packageJson !== 'object')
203
235
  throw new TypeError('publishedProductPackageJson requires packageJson');
204
236
 
205
237
  const version = `${underpostVersion || packageJson.version || ''}`.replace(/^v/, '');
206
238
  if (!version) throw new TypeError('publishedProductPackageJson requires a version to pin the engine CLI at');
207
239
 
208
- const dependencies = { underpost: `^${version}`, ...(catalog.packageDependencies ?? {}) };
240
+ const dependencies = { [underpostPackageName]: `^${version}`, ...(catalog.packageDependencies ?? {}) };
209
241
  const devDependencies = productDevDependenciesFactory({
210
242
  engineDependencies: packageJson.dependencies,
211
243
  engineDevDependencies: packageJson.devDependencies,
@@ -485,22 +517,153 @@ const installDeployDependencies = async (deployId, catalog) => {
485
517
  return specs;
486
518
  };
487
519
 
520
+ /**
521
+ * The package a bare import specifier names; empty for relative, absolute and builtin ones.
522
+ * @param {string} specifier - Import specifier.
523
+ * @returns {string} Package name.
524
+ * @memberof PackageBuilder
525
+ */
526
+ const importPackageNameFactory = (specifier = '') => {
527
+ if (/^(\.|\/|node:|data:|[a-z]+:\/\/)/.test(specifier)) return '';
528
+ const segments = specifier.split('/');
529
+ const name = specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
530
+ return BUILTINS.has(name) ? '' : name;
531
+ };
532
+
533
+ /**
534
+ * Walks the import graph from the runtime entry points and collects the packages it reaches.
535
+ * esbuild parses every module, so an import-shaped line inside a string or a comment is not an
536
+ * import. A dynamic `import('name')` is recorded as lazy: it loads on one code path only, so it
537
+ * does not bind a production install the way a static import does. Non-code assets stay out of
538
+ * the graph, and a non-literal dynamic import is not expanded: esbuild fails on a glob with no
539
+ * match, and the modules such imports load are entry points already.
540
+ * @param {object} [params]
541
+ * @param {string} [params.root] - Package root.
542
+ * @param {string[]} [params.entryPoints] - Entry point paths or glob patterns, relative to root.
543
+ * @returns {Promise<{files: string[], packages: Record<string, string[]>, lazyPackages: Record<string, string[]>}>} Importers by package, relative to root.
544
+ * @memberof PackageBuilder
545
+ */
546
+ const runtimeImportGraphFactory = async ({ root = ENGINE_PACKAGE_PATH, entryPoints = RUNTIME_ENTRY_POINTS } = {}) => {
547
+ const esbuild = await import('esbuild');
548
+ const { metafile } = await esbuild.build({
549
+ absWorkingDir: nodePath.resolve(root),
550
+ entryPoints: entryPoints.flatMap((pattern) => fs.globSync(pattern, { cwd: root })),
551
+ bundle: true,
552
+ write: false,
553
+ metafile: true,
554
+ logLevel: 'silent',
555
+ platform: 'node',
556
+ format: 'esm',
557
+ packages: 'external',
558
+ outdir: nodePath.join(os.tmpdir(), 'underpost-runtime-graph'),
559
+ plugins: [
560
+ {
561
+ name: 'literal-dynamic-imports',
562
+ setup(build) {
563
+ build.onLoad({ filter: /\.[cm]?js$/ }, (args) => ({
564
+ contents: fs.readFileSync(args.path, 'utf8').replace(NON_LITERAL_IMPORT, 'import(__dynamic__||'),
565
+ loader: 'js',
566
+ }));
567
+ },
568
+ },
569
+ {
570
+ name: 'code-only',
571
+ setup(build) {
572
+ build.onResolve({ filter: /\.[^./\\]+$/ }, (args) =>
573
+ /\.(?:[cm]?js|json)$/.test(args.path) ? undefined : { path: args.path, external: true },
574
+ );
575
+ },
576
+ },
577
+ ],
578
+ });
579
+ const packages = {};
580
+ const lazyPackages = {};
581
+ for (const [file, input] of Object.entries(metafile.inputs))
582
+ for (const { path, kind, external } of input.imports) {
583
+ const name = external ? importPackageNameFactory(path) : '';
584
+ if (!name) continue;
585
+ const importers = ((kind === 'dynamic-import' ? lazyPackages : packages)[name] ??= []);
586
+ if (!importers.includes(file)) importers.push(file);
587
+ }
588
+
589
+ for (const name of Object.keys(lazyPackages)) if (packages[name]) delete lazyPackages[name];
590
+ const sorted = (registry) =>
591
+ Object.fromEntries(
592
+ Object.entries(registry)
593
+ .sort(([a], [b]) => a.localeCompare(b))
594
+ .map(([name, importers]) => [name, importers.sort()]),
595
+ );
596
+ return {
597
+ files: Object.keys(metafile.inputs).sort(),
598
+ packages: sorted(packages),
599
+ lazyPackages: sorted(lazyPackages),
600
+ };
601
+ };
602
+
603
+ /**
604
+ * Checks a manifest against the runtime import graph: every package the graph reaches
605
+ * statically must be declared in `dependencies`, or be pinned by a product catalog for the
606
+ * deploys that load its modules. A package reached only lazily is reported, not counted as a
607
+ * violation.
608
+ * @param {object} [params]
609
+ * @param {string} [params.root] - Package root.
610
+ * @param {object} [params.packageJson] - Manifest to check; read from root otherwise.
611
+ * @param {object[]} [params.catalogs] - Product catalogs; every one in the tree otherwise.
612
+ * @returns {Promise<{dependencies: number, devDependencies: number, runtime: string[], lazy: string[], misplaced: Array<{name: string, declaredIn: string, importers: string[]}>}>} Audit result.
613
+ * @memberof PackageBuilder
614
+ */
615
+ const auditRuntimeDependencies = async ({
616
+ root = ENGINE_PACKAGE_PATH,
617
+ packageJson = readManifest(nodePath.join(root, 'package.json')),
618
+ catalogs,
619
+ } = {}) => {
620
+ const { packages, lazyPackages } = await runtimeImportGraphFactory({ root });
621
+ const dependencies = packageJson.dependencies ?? {};
622
+ const devDependencies = packageJson.devDependencies ?? {};
623
+ const catalogDependencies = Object.assign(
624
+ {},
625
+ ...(catalogs ?? (await loadProductCatalogs())).map((catalog) => catalog.packageDependencies ?? {}),
626
+ );
627
+ const declaredIn = (name) =>
628
+ dependencies[name]
629
+ ? 'dependencies'
630
+ : catalogDependencies[name]
631
+ ? 'catalog'
632
+ : devDependencies[name]
633
+ ? 'devDependencies'
634
+ : 'none';
635
+ const misplaced = Object.entries(packages)
636
+ .map(([name, importers]) => ({ name, declaredIn: declaredIn(name), importers }))
637
+ .filter(({ declaredIn: origin }) => origin !== 'dependencies' && origin !== 'catalog');
638
+ return {
639
+ dependencies: Object.keys(dependencies).length,
640
+ devDependencies: Object.keys(devDependencies).length,
641
+ runtime: Object.keys(packages),
642
+ lazy: Object.keys(lazyPackages).map((name) => `${name} (${declaredIn(name)})`),
643
+ misplaced,
644
+ };
645
+ };
646
+
488
647
  export {
489
648
  DEPLOY_CONF_ROOT,
490
649
  DEPLOY_MANIFEST_INDENT,
650
+ RUNTIME_ENTRY_POINTS,
491
651
  STAGED_CLI_PACKAGE,
652
+ auditRuntimeDependencies,
492
653
  buildDeployPackageJson,
493
654
  buildProductPackageJson,
494
655
  deployDependencySpecsFactory,
495
656
  deployPackageNameFactory,
496
657
  deployPackagePathFactory,
497
658
  deployStartScriptFactory,
659
+ importPackageNameFactory,
498
660
  installDeployDependencies,
499
661
  packageRepositoryFactory,
500
662
  productDevDependenciesFactory,
501
663
  productPackageOptionsFactory,
502
664
  publishedProductPackageJson,
503
665
  renamePackage,
666
+ runtimeImportGraphFactory,
504
667
  setPackageRepository,
505
668
  stageCliPackage,
506
669
  stagePackageArchive,
@@ -128,8 +128,9 @@ const TEST_TIERS = [
128
128
  'src/server/ops/systemd.js',
129
129
  'src/server/security/container-storage.js',
130
130
  'src/server/security/selinux.js',
131
+ 'src/server/security/socketsecurity.js',
131
132
  ],
132
- description: 'SELinux policy, systemd units and the SOPS secret store.',
133
+ description: 'SELinux policy, systemd units, the SOPS secret store and the Socket supply-chain audit.',
133
134
  },
134
135
  {
135
136
  name: 'infra:2-network',
@@ -957,6 +957,104 @@ const placeInstanceStaticAssets = ({ instances, options, label }) => {
957
957
  return assertStaticAssets({ records, hostRoot, label });
958
958
  };
959
959
 
960
+ /**
961
+ * @method parseRawHttpResponse
962
+ * @description Splits a raw HTTP/1.x response into its status code and body. The body
963
+ * is everything after the first blank line, byte for byte, so it can be hashed against
964
+ * the document on disk.
965
+ * @param {string} raw - Response as read off the socket.
966
+ * @returns {{status: string, body: string}} Status code (empty when no status line) and body.
967
+ * @memberof UnderpostGateway
968
+ */
969
+ const parseRawHttpResponse = (raw = '') => {
970
+ const status = /^HTTP\/[0-9.]+\s+([0-9]{3})/.exec(raw)?.[1] || '';
971
+ if (!status) return { status: '', body: '' };
972
+ const separator = raw.search(/\r?\n\r?\n/);
973
+ if (separator < 0) return { status, body: '' };
974
+ return { status, body: raw.slice(separator).replace(/^\r?\n\r?\n/, '') };
975
+ };
976
+
977
+ /**
978
+ * @method gatewayPodFetch
979
+ * @description One request against the gateway from inside its own pod, returning the
980
+ * status and the body even when the status is an error.
981
+ *
982
+ * Written on the socket with `nc` rather than fetched with `wget`: the image ships
983
+ * busybox, whose `wget` discards the body of any non-2xx response and exits — so a
984
+ * fallback document, which is by definition delivered with an upstream-failure status,
985
+ * could never be read through it. The probe that did so failed every attempt on a
986
+ * correct edge and looked like a hang. HTTP/1.0 keeps the reply unchunked, so the body
987
+ * is the document verbatim. Where `nc` is absent the `wget` pair still yields the status.
988
+ * @param {object} params
989
+ * @param {string} params.namespace - Namespace the gateway runs in.
990
+ * @param {string} params.host - Host header to present.
991
+ * @param {string} [params.path] - Request path.
992
+ * @returns {{status: string, body: string}} What the gateway answered.
993
+ * @memberof UnderpostGateway
994
+ */
995
+ const gatewayPodFetch = ({ namespace, host, path = '/' }) => {
996
+ const exec = (script) =>
997
+ `${
998
+ shellExec(`kubectl exec -n ${namespace} deploy/${UNDERPOST_GATEWAY.name} -- sh -c "${script}"`, {
999
+ stdout: true,
1000
+ silent: true,
1001
+ silentOnError: true,
1002
+ disableLog: true,
1003
+ }) ?? ''
1004
+ }`;
1005
+ const request = path || '/';
1006
+ const raw = exec(
1007
+ `printf 'GET ${request} HTTP/1.0\\r\\nHost: ${host}\\r\\n\\r\\n' | nc -w 10 127.0.0.1 ${UNDERPOST_GATEWAY.port} 2>/dev/null || true`,
1008
+ );
1009
+ const parsed = parseRawHttpResponse(raw);
1010
+ if (parsed.status) return parsed;
1011
+ const url = `http://127.0.0.1${request}`;
1012
+ const headers = exec(`wget -S -O /dev/null -T 10 --header 'Host: ${host}' ${url} 2>&1 || true`);
1013
+ const status = [...headers.matchAll(/HTTP\/[0-9.]+\s+([0-9]{3})/g)].pop()?.[1] || '';
1014
+ const body = exec(`wget -q -O - -T 10 --header 'Host: ${host}' ${url} 2>/dev/null || true`);
1015
+ return { status, body };
1016
+ };
1017
+
1018
+ /**
1019
+ * @method gatewayFetch
1020
+ * @description One request against the gateway, returning the status and the body
1021
+ * even when the status is an error — the shape every fallback probe asserts on.
1022
+ *
1023
+ * Sent from this host with `curl` to the gateway Service first: the sync runs on the
1024
+ * node that holds the gateway's volume, so the ClusterIP is reachable, and curl keeps
1025
+ * the body of an error response. Only when that yields no status line does it fall back
1026
+ * to {@link UnderpostGateway.gatewayPodFetch}, which needs nothing on the host at all.
1027
+ * @param {object} params
1028
+ * @param {string} params.namespace - Namespace the gateway runs in.
1029
+ * @param {string} params.host - Host header to present.
1030
+ * @param {string} [params.path] - Request path.
1031
+ * @returns {{status: string, body: string, via: string}} What the gateway answered, and which way.
1032
+ * @memberof UnderpostGateway
1033
+ */
1034
+ const gatewayFetch = ({ namespace, host, path = '/' }) => {
1035
+ const clusterIp = `${
1036
+ shellExec(`kubectl get svc ${UNDERPOST_GATEWAY.serviceName} -n ${namespace} -o jsonpath='{.spec.clusterIP}'`, {
1037
+ stdout: true,
1038
+ silent: true,
1039
+ silentOnError: true,
1040
+ disableLog: true,
1041
+ }) ?? ''
1042
+ }`.trim();
1043
+ if (/^[0-9a-f.:]+$/i.test(clusterIp)) {
1044
+ const raw = `${
1045
+ shellExec(
1046
+ `curl -sS -i --noproxy '*' --max-time 10 -H 'Host: ${host}' http://${clusterIp}:${UNDERPOST_GATEWAY.port}${
1047
+ path || '/'
1048
+ } 2>/dev/null || true`,
1049
+ { stdout: true, silent: true, silentOnError: true, disableLog: true },
1050
+ ) ?? ''
1051
+ }`;
1052
+ const parsed = parseRawHttpResponse(raw);
1053
+ if (parsed.status) return { ...parsed, via: 'host' };
1054
+ }
1055
+ return { ...gatewayPodFetch({ namespace, host, path }), via: 'pod' };
1056
+ };
1057
+
960
1058
  /**
961
1059
  * @method gatewayFallbackProbeRunner
962
1060
  * @description Proves the edge answers each configured fallback with the exact
@@ -1018,26 +1116,24 @@ const gatewayFallbackProbeRunner = async ({ checks, options, label, gatewayStatu
1018
1116
  silent: true,
1019
1117
  silentOnError: true,
1020
1118
  }).trim();
1021
- } else {
1022
- const request = `http://127.0.0.1${check.path || '/'}`;
1023
- body = shellExec(
1024
- `kubectl exec -n ${namespace} deploy/${UNDERPOST_GATEWAY.name} -- sh -c ` +
1025
- `"wget -q -O - -T 10 --header 'Host: ${check.host}' ${request} 2>/dev/null || true"`,
1026
- { stdout: true, silent: true, silentOnError: true },
1027
- );
1028
- const headers = shellExec(
1029
- `kubectl exec -n ${namespace} deploy/${UNDERPOST_GATEWAY.name} -- sh -c ` +
1030
- `"wget -S -O /dev/null -T 10 --header 'Host: ${check.host}' ${request} 2>&1 || true"`,
1031
- { stdout: true, silent: true, silentOnError: true },
1032
- );
1033
- status = [...headers.matchAll(/HTTP\/[0-9.]+\s+([0-9]{3})/g)].pop()?.[1] || '';
1034
- }
1119
+ } else ({ status, body } = gatewayFetch({ namespace, host: check.host, path: check.path }));
1035
1120
  actualHash = crypto
1036
1121
  .createHash('sha256')
1037
1122
  .update(body || '')
1038
1123
  .digest('hex');
1039
1124
  passed = /^50[234]$/.test(status) && !!expectedHash && actualHash === expectedHash;
1040
1125
  if (passed) break;
1126
+ // The first miss is reported as it happens: a probe that polls for minutes with
1127
+ // nothing on the console reads as a hang, and what it saw is the whole diagnosis.
1128
+ if (attempts === 1)
1129
+ logger.warn(`[${label}] Fallback probe not yet satisfied; polling`, {
1130
+ host: check.host,
1131
+ path: check.path || '/',
1132
+ status: status || '(none)',
1133
+ bodyBytes: Buffer.byteLength(body || ''),
1134
+ bodyMatchesConfiguredAsset: actualHash === expectedHash,
1135
+ expectedAsset: expectedHash ? check.assetPath : '(missing on disk)',
1136
+ });
1041
1137
  if (attempts < 30) await timer(2000);
1042
1138
  }
1043
1139
  const result = {
@@ -1059,6 +1155,8 @@ export {
1059
1155
  UNDERPOST_GATEWAY,
1060
1156
  assertStaticAssets,
1061
1157
  gatewayFallbackProbeRunner,
1158
+ gatewayFetch,
1159
+ gatewayPodFetch,
1062
1160
  gatewayStaticAssetExists,
1063
1161
  hostInstanceRegistryPathFactory,
1064
1162
  hostServerConfFactory,
@@ -1071,6 +1169,7 @@ export {
1071
1169
  kubernetesUpstreamFactory,
1072
1170
  underpostGatewayManifestsFactory,
1073
1171
  nginxConfFactory,
1172
+ parseRawHttpResponse,
1074
1173
  seedDefaultStatusPage,
1075
1174
  staticLocationFactory,
1076
1175
  staticPathSegmentFactory,
@@ -3001,14 +3001,41 @@ const syncPrivateConf = (deployId, extraPaths = []) => {
3001
3001
  };
3002
3002
 
3003
3003
  /**
3004
- * Moves a deploy's public template sources into the engine working tree ahead of
3005
- * the build copy step. Idempotent and safe to rerun: each move is guarded by
3006
- * `existsSync`, so already-moved or absent sources are skipped rather than throwing.
3007
- * The `[src, dest]` pairs come from the deploy's product catalog (passed in), so
3008
- * this module stays product-agnostic.
3004
+ * Mirrors a deploy's public template sources from the engine working tree to the source
3005
+ * repo they came from. The engine ignores every one of these paths, so an edit made there
3006
+ * never reaches a diff; the source repo is where it is reviewed and committed. Each path
3007
+ * the engine holds is replaced wholesale there (removed, then copied) so the source repo's
3008
+ * `git status` reads as exactly the engine tree's state, deletions included. The engine
3009
+ * copies stay in place: this is a copy, not a move. A path the engine tree does not hold
3010
+ * is left untouched in the source repo rather than deleted.
3011
+ *
3012
+ * @method syncDeployIdSourcesBack
3013
+ * @param {Array<[string, string]>} [sourceMoves=[]] - Public `[src, dest]` pairs.
3014
+ * @returns {string[]} The source paths that were mirrored.
3015
+ * @memberof ServerConfBuilder
3016
+ */
3017
+ const syncDeployIdSourcesBack = (sourceMoves = []) => {
3018
+ const mirrored = [];
3019
+ for (const [src, dest] of sourceMoves) {
3020
+ if (!fs.existsSync(dest)) continue;
3021
+ fs.removeSync(src);
3022
+ fs.copySync(dest, src);
3023
+ mirrored.push(src);
3024
+ }
3025
+ return mirrored;
3026
+ };
3027
+
3028
+ /**
3029
+ * Brings a deploy's public template sources into line ahead of the build copy step. The
3030
+ * engine working tree is the working copy and the source repo its git view, so a path the
3031
+ * engine already holds is mirrored out to the repo ({@link syncDeployIdSourcesBack}) and
3032
+ * only a path the engine lacks is copied in. Nothing is moved: the repo's working tree
3033
+ * keeps every file, so a build never leaves it reading as wholesale deletions, and an
3034
+ * engine-side edit is never overwritten by the repo's copy. Safe to rerun: each step is
3035
+ * guarded by `existsSync`.
3009
3036
  *
3010
3037
  * @method syncDeployIdSources
3011
- * @param {Array<[string, string]>} [sourceMoves=[]] - Public `[src, dest]` move pairs.
3038
+ * @param {Array<[string, string]>} [sourceMoves=[]] - Public `[src, dest]` pairs.
3012
3039
  * @returns {boolean} `true` when any sources were declared, else `false`.
3013
3040
  * @memberof ServerConfBuilder
3014
3041
  */
@@ -3016,7 +3043,8 @@ const syncDeployIdSources = (sourceMoves = []) => {
3016
3043
  if (!sourceMoves.length) return false;
3017
3044
  for (const dir of ['src/api', 'src/client/components', 'src/client/public', 'src/client/services'])
3018
3045
  fs.mkdirSync(dir, { recursive: true });
3019
- for (const [src, dest] of sourceMoves) if (fs.existsSync(src)) fs.moveSync(src, dest, { overwrite: true });
3046
+ syncDeployIdSourcesBack(sourceMoves);
3047
+ for (const [src, dest] of sourceMoves) if (!fs.existsSync(dest) && fs.existsSync(src)) fs.copySync(src, dest);
3020
3048
  return true;
3021
3049
  };
3022
3050
 
@@ -3098,6 +3126,24 @@ const pruneTemplateWorkTree = (toPath, preservedEntries = []) => {
3098
3126
  }
3099
3127
  };
3100
3128
 
3129
+ /**
3130
+ * Marker in the engine `.gitignore` where the engine-only prototype rules start.
3131
+ * @constant {string}
3132
+ * @memberof ServerConfBuilder
3133
+ */
3134
+ const GITIGNORE_PROTOTYPE_BOUNDARY = '# Ignore ERP / CRM custom prototypes src';
3135
+
3136
+ /**
3137
+ * The `.gitignore` a generated repository carries: the engine rules before the prototype
3138
+ * boundary. Without it, `git add .` after an install commits `node_modules`.
3139
+ * @method templateGitignoreFactory
3140
+ * @param {string} [source='.gitignore'] - Engine `.gitignore` path.
3141
+ * @returns {string} File content.
3142
+ * @memberof ServerConfBuilder
3143
+ */
3144
+ const templateGitignoreFactory = (source = '.gitignore') =>
3145
+ fs.readFileSync(source, 'utf8').split(GITIGNORE_PROTOTYPE_BOUNDARY)[0];
3146
+
3101
3147
  /**
3102
3148
  * Rebuilds the standalone `pwa-microservices-template` from scratch out of the current
3103
3149
  * engine source tree.
@@ -3155,6 +3201,8 @@ const buildTemplate = async ({ srcPath = './', toPath = '../pwa-microservices-te
3155
3201
 
3156
3202
  fs.copySync(`./.vscode`, `${toPath}/.vscode`);
3157
3203
  fs.copySync(`./src/client/public/default`, `${toPath}/src/client/public/default`);
3204
+ // The walker filter above drops every `.git*` entry, `.gitignore` included.
3205
+ fs.writeFileSync(`${toPath}/.gitignore`, templateGitignoreFactory(`${srcPath}/.gitignore`), 'utf8');
3158
3206
 
3159
3207
  // Preserve the template's own README + package.json identity before merging engine metadata.
3160
3208
  for (const checkoutPath of ['README.md', 'package.json']) shellExec(`cd ${toPath} && git checkout ${checkoutPath}`);
@@ -3448,9 +3496,11 @@ export {
3448
3496
  waitForPort,
3449
3497
  syncPrivateConf,
3450
3498
  syncDeployIdSources,
3499
+ syncDeployIdSourcesBack,
3451
3500
  gitOriginRepositoryName,
3452
3501
  ensureTemplateCheckout,
3453
3502
  pruneTemplateWorkTree,
3503
+ templateGitignoreFactory,
3454
3504
  buildTemplate,
3455
3505
  updatePrivateTemplateRepo,
3456
3506
  updatePrivateEngineTestRepo,
@@ -60,6 +60,8 @@ const CONFIG_OWNERSHIP = Object.freeze([
60
60
  { match: /^(GITHUB_|DEFAULT_SSH_|FORWARD_PROXY_|DEFAULT_DEPLOY_)/, owner: 'host' },
61
61
  { match: /^(GF_SECURITY_|CLUSTER_MAILER_)/, owner: 'host' },
62
62
  { match: /^UNDERPOST_EVENT_TOKEN$/, owner: 'host' },
63
+ // The Socket audit runs on hosts and in CI, never in a workload.
64
+ { match: /^SOCKET_CLI_/, owner: 'host' },
63
65
 
64
66
  { match: /^(DB_|MARIADB_|VALKEY_)/, owner: 'app' },
65
67
  { match: /^(JWT_SECRET|ACCESS_EXPIRE_MINUTES|REFRESH_EXPIRE_MINUTES|PORT|DEPLOY_ID)$/, owner: 'app' },
@@ -414,14 +414,15 @@ const getTerminalPid = () => {
414
414
  };
415
415
  /**
416
416
  * Copies text content to the system clipboard using clipboardy.
417
- * Logs the copied content for confirmation.
417
+ * Logs only the copied length: the content is often a password or a command carrying one.
418
418
  * @memberof Process
419
419
  * @param {string} [data='🦄'] - The data to copy. Defaults to '🦄'.
420
420
  * @returns {void}
421
421
  */
422
422
  function pbcopy(data) {
423
- clipboard.writeSync(data || '🦄');
424
- logger.info(`copied to clipboard`, clipboard.readSync());
423
+ const content = data || '🦄';
424
+ clipboard.writeSync(content);
425
+ logger.info(`copied to clipboard`, { characters: `${content}`.length });
425
426
  }
426
427
  export {
427
428
  installRootFile,
@@ -333,10 +333,19 @@ class UnderpostStartUp {
333
333
  const result = await awaitDeployMonitor(true);
334
334
  if (result === true) {
335
335
  // Withdraw every domain's local traces once the deployment is serving. Three calls
336
- // rather than one cross-domain sweep: each domain owns what it put on disk.
336
+ // rather than one cross-domain sweep: each domain owns what it put on disk. Only the
337
+ // host domain is forced: its `--force` removes the ephemeral `engine-private` clone,
338
+ // which must not outlive the boot inside a container. For the other two, `--force`
339
+ // reaches into the cluster (the app Secret, secret purges) and is never wanted here.
337
340
  if (env === 'production' && Underpost.state.isInsideContainer())
338
341
  for (const domain of [Underpost.secret, Underpost.host, Underpost.app])
339
- domain.clean({ env, namespace: 'default', args: {}, dryRun: false, force: false });
342
+ domain.clean({
343
+ env,
344
+ namespace: 'default',
345
+ args: {},
346
+ dryRun: false,
347
+ force: domain === Underpost.host,
348
+ });
340
349
  setTimeout(() => {
341
350
  setRuntimeStatus(deployId, env, RUNTIME_STATUS.RUNNING);
342
351
  setStartContainerStatus(deployId, env);