@teamscala/service-boot 0.23.344 → 0.23.346

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 (138) hide show
  1. package/package.json +1064 -1093
  2. package/src/two-phase-boot.ts +55 -2
  3. package/src/two-phase-health-gate-client-only.test.ts +77 -0
  4. package/src/two-phase-health-gate.test.ts +13 -2
  5. package/src/agreement-gate.d.ts +0 -19
  6. package/src/asset-cache-key.d.ts +0 -11
  7. package/src/asset-optimize.d.ts +0 -17
  8. package/src/asset-proxy.d.ts +0 -11
  9. package/src/asset-social-card.d.ts +0 -17
  10. package/src/attach-agreement-magic.d.ts +0 -20
  11. package/src/attach-portal-members.d.ts +0 -23
  12. package/src/attach-proposal-accept.d.ts +0 -26
  13. package/src/attach-proposal-magic.d.ts +0 -18
  14. package/src/attach-transfers-upload.d.ts +0 -27
  15. package/src/auth-gate.d.ts +0 -29
  16. package/src/bind-page-handler.d.ts +0 -18
  17. package/src/build-client-assets/input-hashing.d.ts +0 -25
  18. package/src/build-client-assets/source-candidates.d.ts +0 -27
  19. package/src/build-client-assets.d.ts +0 -50
  20. package/src/compose-page-title.d.ts +0 -41
  21. package/src/content-gate/access.d.ts +0 -15
  22. package/src/content-gate/config-types.d.ts +0 -99
  23. package/src/content-gate/gate.d.ts +0 -13
  24. package/src/content-gate/parse-cookie.d.ts +0 -9
  25. package/src/content-gate/token.d.ts +0 -48
  26. package/src/content-page-floor.d.ts +0 -39
  27. package/src/discover-blocks.d.ts +0 -28
  28. package/src/expand-roster.d.ts +0 -34
  29. package/src/fn-routers/agreement-completion-email.d.ts +0 -14
  30. package/src/fn-routers/agreement-send-router.d.ts +0 -82
  31. package/src/fn-routers/ai-health-router.d.ts +0 -35
  32. package/src/fn-routers/auth-router.d.ts +0 -47
  33. package/src/fn-routers/cache-admin-router.d.ts +0 -57
  34. package/src/fn-routers/chat-session-router.d.ts +0 -219
  35. package/src/fn-routers/email-defaults.d.ts +0 -1
  36. package/src/fn-routers/email-link-ttl.d.ts +0 -1
  37. package/src/fn-routers/index.d.ts +0 -18
  38. package/src/fn-routers/orchestrator-registration-router.d.ts +0 -60
  39. package/src/fn-routers/orchestrator-registration-router.ts +0 -77
  40. package/src/fn-routers/orchestrator-registration.live.test.ts +0 -70
  41. package/src/fn-routers/orchestrator-registration.test.ts +0 -23
  42. package/src/fn-routers/panel-data-router.d.ts +0 -19
  43. package/src/fn-routers/persist-chat-messages.d.ts +0 -36
  44. package/src/fn-routers/plans-router.d.ts +0 -25
  45. package/src/fn-routers/proposal-send-router.d.ts +0 -58
  46. package/src/fn-routers/public-agreement-router.d.ts +0 -289
  47. package/src/fn-routers/public-assessment-router.d.ts +0 -68
  48. package/src/fn-routers/public-gpt-session-router.d.ts +0 -143
  49. package/src/fn-routers/sign-in-flow-router.d.ts +0 -107
  50. package/src/fn-routers/task-sync-assign.d.ts +0 -307
  51. package/src/fn-routers/task-sync-brief.d.ts +0 -98
  52. package/src/fn-routers/task-sync-close.d.ts +0 -41
  53. package/src/fn-routers/task-sync-dispatch.d.ts +0 -47
  54. package/src/fn-routers/task-sync-dispatch.ts +0 -81
  55. package/src/fn-routers/task-sync-lane.d.ts +0 -49
  56. package/src/fn-routers/task-sync-lane.ts +0 -114
  57. package/src/fn-routers/task-sync-projection.d.ts +0 -144
  58. package/src/fn-routers/task-sync-rename.d.ts +0 -91
  59. package/src/fn-routers/task-sync-router.d.ts +0 -455
  60. package/src/fn-routers/task-sync-router.ts +0 -1075
  61. package/src/fn-routers/tasks-router.d.ts +0 -25
  62. package/src/fn-routers/user-preferences-router.d.ts +0 -77
  63. package/src/fn-routers/work-items-router.d.ts +0 -102
  64. package/src/gate-ttls.d.ts +0 -6
  65. package/src/gpt-gate.d.ts +0 -25
  66. package/src/handlers/bun-stable-watch.d.ts +0 -1
  67. package/src/handlers/pane-outbox-drain.d.ts +0 -1
  68. package/src/handlers/projects-digest.d.ts +0 -26
  69. package/src/handlers/prune-stale-data.d.ts +0 -30
  70. package/src/handlers/registry-stale-inactive-sweep.d.ts +0 -1
  71. package/src/handlers/scala-tools-currency-watch.d.ts +0 -1
  72. package/src/handlers/singleton-tools-currency-watch.d.ts +0 -1
  73. package/src/handlers/sweep-event-log.d.ts +0 -1
  74. package/src/handlers/sweep-host-cache.d.ts +0 -24
  75. package/src/handlers/upstream-issue-sync.d.ts +0 -1
  76. package/src/handlers/whatsapp-liveness-logic.d.ts +0 -34
  77. package/src/handlers/whatsapp-liveness.d.ts +0 -4
  78. package/src/hono-error-handler.d.ts +0 -25
  79. package/src/install-harness.d.ts +0 -45
  80. package/src/install-logging.d.ts +0 -34
  81. package/src/load-service-install-row.d.ts +0 -24
  82. package/src/load-service-prisma-client.d.ts +0 -18
  83. package/src/mount-orpc-router.d.ts +0 -15
  84. package/src/mount-server-packages.d.ts +0 -29
  85. package/src/mount.d.ts +0 -9
  86. package/src/mutable-app-ref.d.ts +0 -44
  87. package/src/page-route-shell-types.d.ts +0 -12
  88. package/src/page-server-orpc/audit-revert-router.d.ts +0 -37
  89. package/src/page-server-orpc/hub-mcp-client.d.ts +0 -12
  90. package/src/page-server-orpc/portal-diagnostics-router.d.ts +0 -49
  91. package/src/page-server-orpc/puck-pages-router.d.ts +0 -58
  92. package/src/page-server-orpc/server-client.d.ts +0 -16
  93. package/src/page-server-orpc/templates-router.d.ts +0 -34
  94. package/src/page-server-orpc/user-preferences-router.d.ts +0 -79
  95. package/src/pg-boss-handler-registry.d.ts +0 -27
  96. package/src/pg-boss-mount.d.ts +0 -42
  97. package/src/proposal-authorized-emails.d.ts +0 -28
  98. package/src/proposal-chat-inject.d.ts +0 -17
  99. package/src/proposal-gate.d.ts +0 -18
  100. package/src/read-html-template.d.ts +0 -38
  101. package/src/read-viewport-from-request.d.ts +0 -18
  102. package/src/readiness-gate.d.ts +0 -16
  103. package/src/register-api-routes.d.ts +0 -18
  104. package/src/register-crash-handlers.d.ts +0 -15
  105. package/src/register-page-routes.d.ts +0 -27
  106. package/src/register-page-server-client.d.ts +0 -11
  107. package/src/register-registry-page-route/ai-chat-prefetch.d.ts +0 -13
  108. package/src/register-registry-page-route/graph-cache.d.ts +0 -30
  109. package/src/register-registry-page-route/meta-title.d.ts +0 -2
  110. package/src/register-registry-page-route/proposal-approval-email-token.d.ts +0 -14
  111. package/src/register-registry-page-route/proposal-brand-stamping.d.ts +0 -28
  112. package/src/register-registry-page-route/resolve-page-data.d.ts +0 -1
  113. package/src/register-registry-page-route.d.ts +0 -27
  114. package/src/register-static-assets.d.ts +0 -13
  115. package/src/register-ws-routes.d.ts +0 -28
  116. package/src/resolve-app-base-url.d.ts +0 -13
  117. package/src/resolve-brand-favicon.d.ts +0 -28
  118. package/src/resolve-from-loader-config.d.ts +0 -32
  119. package/src/resolve-service-context.d.ts +0 -17
  120. package/src/resolve-service-port.d.ts +0 -75
  121. package/src/resolve-theme-mode.d.ts +0 -42
  122. package/src/resolvers/fetch-org-brand.d.ts +0 -2
  123. package/src/resolvers/portal-route-paths.d.ts +0 -39
  124. package/src/resolvers/website-by-host-map.d.ts +0 -12
  125. package/src/resource-chat-inject.d.ts +0 -46
  126. package/src/resource-not-found.d.ts +0 -60
  127. package/src/run-boot-hook-list.d.ts +0 -19
  128. package/src/run-boot-hooks.d.ts +0 -31
  129. package/src/scala-tools-currency-watchdog.d.ts +0 -10
  130. package/src/security-headers.d.ts +0 -12
  131. package/src/serve/serve.d.ts +0 -46
  132. package/src/serve/stamp-transport-identity.d.ts +0 -39
  133. package/src/server-error-page.d.ts +0 -29
  134. package/src/start-scheduled-jobs.d.ts +0 -18
  135. package/src/two-phase-boot.d.ts +0 -136
  136. package/src/types.d.ts +0 -46
  137. package/src/ui-service.d.ts +0 -46
  138. package/src/ws-boot-self-test.d.ts +0 -19
@@ -64,13 +64,60 @@ let realPageHandler: CreatePageHandler | null = null;
64
64
  let fullAppReady = false;
65
65
 
66
66
  /**
67
- * Set the real page handler (called when Phase 2 completes).
67
+ * Set the real page handler (called when Phase 2 completes on an SSR service).
68
+ *
69
+ * Registering the SSR handler implies the full app is built, so this also flips
70
+ * readiness — but the reverse does NOT hold, which is why `markFullAppReady`
71
+ * exists separately. See its note.
68
72
  */
69
73
  export function setPageHandler(handler: CreatePageHandler): void {
70
74
  realPageHandler = handler;
75
+ markFullAppReady();
76
+ }
77
+
78
+ /**
79
+ * Flip readiness once phase 2 has built the full app.
80
+ *
81
+ * SEPARATE FROM `setPageHandler` BECAUSE THE TWO FACTS CAME APART. Readiness
82
+ * means "phase 2 finished"; the page handler means "this service renders pages
83
+ * server-side". Every service was SSR, so one flag honestly carried both — until
84
+ * `render_mode=client` (`granular runtime`) made a service that completes phase 2
85
+ * and never registers an SSR handler.
86
+ *
87
+ * Leaving readiness inside `setPageHandler` made such a service PERMANENTLY
88
+ * un-ready: `/health` answered `{"status":"starting"}` forever while the process
89
+ * was healthy and serving. That is the failure `readiness-gated-boot` is written
90
+ * against — a service must be "binary: fully-ready or cleanly-unavailable", and
91
+ * a never-ready health signal makes the activator's wake gate and every
92
+ * health-gated router treat a working service as down.
93
+ *
94
+ * Measured 2026-08-07 on scala-agents-ui: boot completed in 5023ms, "Full app
95
+ * built: 50 block(s)" logged, `GET /` correctly 302'd to sign-in, and `/health`
96
+ * still reported starting — while three untouched UI services reported ok.
97
+ */
98
+ export function markFullAppReady(): void {
71
99
  fullAppReady = true;
72
100
  }
73
101
 
102
+ /**
103
+ * Reset both phase-2 flags. TEST-ONLY.
104
+ *
105
+ * `fullAppReady` is module state that only ever transitions false -> true in
106
+ * production, and Bun shares a module instance across every test file in a run —
107
+ * so the SSR readiness test and the client-only readiness test contaminate each
108
+ * other purely by file order. Splitting them across files does NOT isolate them;
109
+ * it only hides the coupling until CI runs them together.
110
+ *
111
+ * A test that passes alone and fails in a suite is worse than no test, so the
112
+ * reset is exported rather than left as an ordering convention nobody can see.
113
+ * Never called from production code — `setPageHandler`/`markFullAppReady` are
114
+ * the only writers on the boot path.
115
+ */
116
+ export function __resetPhase2StateForTest(): void {
117
+ realPageHandler = null;
118
+ fullAppReady = false;
119
+ }
120
+
74
121
  /**
75
122
  * Get the current page handler state.
76
123
  */
@@ -382,7 +429,8 @@ export async function buildMinimalApp(
382
429
  // (the same pulsating-logo holding page scale-to-zero uses) —
383
430
  // never bare plain text (loading-via-logo-loading).
384
431
  if (!fullAppReady || !realPageHandler) {
385
- return new Response(buildWakingPageHtml({}), {
432
+ const logo = await resolveErrorPageLogo(serviceSlug);
433
+ return new Response(buildWakingPageHtml({ logoUrl: logo }), {
386
434
  status: 503,
387
435
  headers: {
388
436
  "content-type": "text/html; charset=utf-8",
@@ -514,6 +562,11 @@ export async function buildFullApp(
514
562
  `[two-phase-boot:${serviceSlug}] Real page handler registered - page routes now delegate to full app`,
515
563
  );
516
564
  } else {
565
+ // The full app IS built — this service simply never renders server-side,
566
+ // so readiness is flipped directly rather than as a side effect of
567
+ // registering an SSR handler that will never exist. Without this a
568
+ // client-only service is permanently un-ready (see markFullAppReady).
569
+ markFullAppReady();
517
570
  log.info(
518
571
  `[two-phase-boot:${serviceSlug}] Client-only mode (render_mode=client) — no SSR page handler registered`,
519
572
  );
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @system service-boot
3
+ * @status handwritten
4
+ * @edit edit directly
5
+ *
6
+ * A CLIENT-ONLY service (`render_mode=client`) must reach ready, even though it
7
+ * never registers an SSR page handler.
8
+ *
9
+ * Separate file from `two-phase-health-gate.test.ts` on purpose: `fullAppReady`
10
+ * is module state that only transitions false -> true and has no reset hook, so
11
+ * the two ready-paths cannot both be exercised in one module instance. A reset
12
+ * hook would exist only for tests.
13
+ *
14
+ * THE REGRESSION THIS LOCKS (measured 2026-08-07 on scala-agents-ui). Readiness
15
+ * used to be flipped INSIDE `setPageHandler`, which was honest while every
16
+ * service was SSR. `render_mode=client` made a service that completes phase 2
17
+ * and never calls it, so `/health` answered `{"status":"starting"}` FOREVER
18
+ * while the process was healthy and serving — boot completed in 5023ms, "Full
19
+ * app built: 50 block(s)" logged, `GET /` correctly 302'd to sign-in, and three
20
+ * untouched UI services reported ok beside it.
21
+ *
22
+ * That is precisely what `readiness-gated-boot` forbids ("binary: fully-ready or
23
+ * cleanly-unavailable"): a permanently-un-ready health signal makes the
24
+ * activator's wake gate and every health-gated router treat a working service as
25
+ * down. Exercised through a real Hono request against the REAL exported handler
26
+ * (`proxy-is-not-behaviour`) — a source grep would prove the call exists, never
27
+ * that the endpoint answers 200.
28
+ */
29
+
30
+ import { beforeAll, describe, expect, test } from "bun:test";
31
+ import { Hono } from "hono";
32
+ import {
33
+ __resetPhase2StateForTest,
34
+ getPageHandlerState,
35
+ healthHandler,
36
+ markFullAppReady,
37
+ } from "./two-phase-boot.ts";
38
+
39
+ /** Mount the real handler exactly as buildMinimalApp does. */
40
+ const app = new Hono().get("/health", healthHandler);
41
+
42
+ describe("/health for a client-only service", () => {
43
+ // Bun shares one module instance across every test file in a run, so the SSR
44
+ // readiness test's setPageHandler leaks into this file when both run together.
45
+ // Without this reset the suite passes file-by-file and fails in CI.
46
+ beforeAll(() => {
47
+ __resetPhase2StateForTest();
48
+ });
49
+
50
+ test("before phase 2 completes it reports 503, not ready", async () => {
51
+ expect(getPageHandlerState().ready).toBe(false);
52
+
53
+ const res = await app.request("/health");
54
+
55
+ expect(res.status).toBe(503);
56
+ expect(await res.json()).toEqual({ status: "starting" });
57
+ });
58
+
59
+ test("reaches ready without an SSR page handler", async () => {
60
+ // The real client-only phase-2 path: buildFullApp finishes and marks the
61
+ // app ready WITHOUT setPageHandler, because there is no SSR handler.
62
+ markFullAppReady();
63
+
64
+ const state = getPageHandlerState();
65
+ expect(state.ready).toBe(true);
66
+ // The discriminator: ready is true while hasHandler stays false. Asserting
67
+ // both is what separates this from the SSR path — a fix that flipped ready
68
+ // by registering a dummy handler would pass `ready` and fail here.
69
+ expect(state.hasHandler).toBe(false);
70
+
71
+ const res = await app.request("/health");
72
+
73
+ expect(res.status).toBe(200);
74
+ expect(res.ok).toBe(true);
75
+ expect(await res.json()).toEqual({ status: "ok" });
76
+ });
77
+ });
@@ -27,9 +27,14 @@
27
27
  * 137ms warm), which is why one app looked healthy and the others did not.
28
28
  */
29
29
 
30
- import { describe, expect, test } from "bun:test";
30
+ import { beforeAll, describe, expect, test } from "bun:test";
31
31
  import { Hono } from "hono";
32
- import { healthHandler, setPageHandler, getPageHandlerState } from "./two-phase-boot.ts";
32
+ import {
33
+ __resetPhase2StateForTest,
34
+ getPageHandlerState,
35
+ healthHandler,
36
+ setPageHandler,
37
+ } from "./two-phase-boot.ts";
33
38
 
34
39
  /** Mount the real handler exactly as buildMinimalApp does. */
35
40
  const app = new Hono().get("/health", healthHandler);
@@ -41,6 +46,12 @@ const app = new Hono().get("/health", healthHandler);
41
46
  * hook and adding one would exist only for tests.
42
47
  */
43
48
  describe("/health is gated on page-serving readiness", () => {
49
+ // Bun shares one module instance across test files, so a sibling file that
50
+ // marks the app ready would otherwise decide this file's first assertion.
51
+ beforeAll(() => {
52
+ __resetPhase2StateForTest();
53
+ });
54
+
44
55
  test("before the phase-2 swap it reports 503, not ready", async () => {
45
56
  expect(getPageHandlerState().ready).toBe(false);
46
57
 
@@ -1,19 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The AGREEMENT content gate, expressed as config for the content-gate primitive
7
- * (content-gate/). The agreement-specific bits: which resource (the placed
8
- * SignIn gate block's id), who's authorized (the signer roster), what to seed
9
- * (the verified signer's signing session into every SignatureField), and how to
10
- * withhold (strip the gate region to gate-only + strip {{agreement.*}} chrome).
11
- * The engine handles cookie/token/verify/orchestration.
12
- *
13
- * The signing logic (buildSigningSession, seedSigningBlocks, roster expansion,
14
- * placeholder strip) is preserved verbatim from the former gate-agreement-
15
- * content.ts — only the cookie/token orchestration moved into the shared engine.
16
- */
17
- import type { AccessConfig, ContentGateConfig } from "./content-gate/config-types.ts";
18
- export declare const agreementGateConfig: ContentGateConfig;
19
- export declare const agreementAccessConfig: AccessConfig;
@@ -1,11 +0,0 @@
1
- /**
2
- * @system server-handlers
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * ETag derivation for the asset proxy that incorporates the negotiated
7
- * image format so per-Accept variants cache independently.
8
- */
9
- export type TargetFormat = "webp" | "avif" | "jpeg" | "png" | "gif" | "svg" | "ico" | "original";
10
- export declare function negotiateFormat(acceptHeader: string | null, storedContentType: string): TargetFormat;
11
- export declare function buildEtag(baseEtag: string, format: TargetFormat): string;
@@ -1,17 +0,0 @@
1
- /**
2
- * @system server-handlers
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * On-the-fly image optimisation for the asset proxy. Converts stored
7
- * PNG/JPEG to WebP or AVIF when the browser signals support, using
8
- * @teamscala/image-optimizer's compressImage primitive. Returns null
9
- * on failure so the caller can fall back to the original stream.
10
- */
11
- import type { TargetFormat } from "./asset-cache-key.ts";
12
- export interface OptimizeResult {
13
- data: Buffer;
14
- format: string;
15
- processedSize: number;
16
- }
17
- export declare function optimizeImage(buffer: Buffer, targetFormat: TargetFormat): Promise<OptimizeResult | null>;
@@ -1,11 +0,0 @@
1
- /**
2
- * @system server-handlers
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Same-origin S3 asset proxy with on-the-fly image optimisation.
7
- * Streams objects from the configured S3 bucket, converting PNG/JPEG
8
- * to WebP/AVIF when the browser declares support via Accept header.
9
- * Returns 404 for missing keys, 502 for S3 failures. Never redirects.
10
- */
11
- export declare function handleAssetProxy(req: Request): Promise<Response>;
@@ -1,17 +0,0 @@
1
- /**
2
- * @system server-handlers
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Dynamic-import wrapper around image-optimizer's in-process sharp
7
- * social-card op. Mirrors asset-optimize.ts's optional-dependency shape:
8
- * services without image-optimizer installed transparently get null and
9
- * fall back to the raw asset stream. In-process (not HTTP) because the
10
- * og:image transform is a cold path per shared link — no auth handshake,
11
- * no per-consumer service config.
12
- */
13
- export interface SocialCardOutcome {
14
- data: Buffer;
15
- processedSize: number;
16
- }
17
- export declare function renderSocialCard(buffer: Buffer): Promise<SocialCardOutcome | null>;
@@ -1,20 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The agreement MAGIC-LINK endpoint. A recipient who clicks an emailed
7
- * "Review & sign" link — which carries a pre-authorised, signed ag_token for
8
- * THEIR party — lands here: the token is verified for the agreement, the
9
- * ag_token cookie is set on the shared parent domain, and the browser is
10
- * 302-redirected straight into the signing page. No email-entry gate, no OTP —
11
- * "came from our email" IS the proof of identity, exactly like the
12
- * proposal-accept hand-off (attach-proposal-accept.ts).
13
- *
14
- * The token is the same HMAC ag_token the gate verifies (30-min TTL, scoped to
15
- * {agreementId, email}); an invalid/expired/forged token sets no cookie and the
16
- * destination page simply shows the normal email gate. GET so it is a plain
17
- * clickable link in an email.
18
- */
19
- import type { Hono } from "hono";
20
- export declare function attachAgreementMagic(app: Hono, serviceSlug: string): Promise<void>;
@@ -1,23 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Portal-secured member directory endpoint. Resolves members of an org via a
7
- * parameterized raw join over better_auth_member + "user" — NOT the typed
8
- * `member` ORPC model, which is deliberately omitted from the portal's
9
- * service_schema (security: the raw table is not exposed as a typed CRUD
10
- * surface). Mirrors the agreement-gate.ts:109-150 precedent.
11
- *
12
- * The portal's auth middleware (better-auth-cookie) gates the endpoint — only
13
- * authenticated users can call it. The orgId comes from the caller's context
14
- * (the portal resolves it from the session + passes it).
15
- *
16
- * Endpoint: GET /api/portal/members?orgId=<uuid>
17
- * - orgId omitted: super-admin all-orgs mode (returns every member across
18
- * all orgs, strictly gated to super-admin via getSession; used by the
19
- * "View As" impersonation dropdown).
20
- * Response: { members: Array<{ id, user_id, organization_id, role, email, name, image }> }
21
- */
22
- import type { Hono } from "hono";
23
- export declare function attachPortalMembers(app: Hono): Promise<void>;
@@ -1,26 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The proposal ACCEPT endpoint. A viewer who has passed the proposal gate (holds
7
- * a valid prop_token) POSTs {proposalId} here to accept; the server generates a
8
- * signing document from the proposal (createAgreementFromProposal) and
9
- * 302-redirects them straight into signing it on the sign site. This replaces
10
- * the old mailto CTA. Mounted BEFORE the auth gate so it is publicly reachable —
11
- * the prop_token (not a login) is the proof of identity, exactly like the
12
- * content-gate access endpoint.
13
- *
14
- * Single sign-on across the journey: the viewer already proved their email at
15
- * the proposal gate (prop_token), so we MUST NOT make them re-enter it on the
16
- * sign site. Before redirecting, we mint the agreement's ag_token for that same
17
- * verified email and set it on the SHARED parent domain (Domain=.scala.business)
18
- * so the browser carries it from proposals.scala.business to sign.scala.business
19
- * — the agreement gate then auto-reveals + seeds the signing session with zero
20
- * extra prompts. This requires both hosts to resolve the SAME token secret
21
- * (AUTH_SECRET→ENCRYPTION_KEY→DATABASE_URL): scala-sign must carry ENCRYPTION_KEY
22
- * (also required to decrypt the org's Stripe key on full sign), so both hosts
23
- * land on ENCRYPTION_KEY and the carried token verifies.
24
- */
25
- import type { Hono } from "hono";
26
- export declare function attachProposalAccept(app: Hono, serviceSlug: string): Promise<void>;
@@ -1,18 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The proposal MAGIC-LINK endpoint — the proposal twin of attach-agreement-magic.
7
- * A recipient who clicks an emailed "View your proposal" link (carrying a signed,
8
- * per-recipient prop_token) lands here: the token is verified for the proposal,
9
- * the prop_token cookie is set, and the browser is 302-redirected straight into
10
- * the proposal page. No email-entry gate, no OTP. An invalid/expired token sets
11
- * no cookie and the page falls through to the normal email gate.
12
- *
13
- * The prop_token is host-scoped (proposals are served on the proposals host only),
14
- * unlike the agreement ag_token which spans .scala.business for the proposal→sign
15
- * hand-off. GET so it is a plain clickable link in an email.
16
- */
17
- import type { Hono } from "hono";
18
- export declare function attachProposalMagic(app: Hono, serviceSlug: string): Promise<void>;
@@ -1,27 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Authenticated asset upload — POST /api/transfers/upload. Restores the
7
- * handler deleted with @teamscala/server-files (commit ca5643ef); avatar/logo
8
- * upload had 404'd on every service since. Writes to S3 via
9
- * @teamscala/object-storage/create/write-ops and returns the STORED-form URL
10
- * (`/api/files/<key>`) the client persists into avatar_url/logo_url — the
11
- * display path rewrites it to the public `/api/assets/<encoded-key>` proxy
12
- * via `toAssetPath` (@teamscala/formatters/asset-url). Self-authenticates
13
- * (getSession) so it mounts BEFORE the auth gate.
14
- *
15
- * Key scheme is USER-scoped (`users/<userId>/<type>/<file>-<ts>.<ext>`) per
16
- * the operator ruling: a profile picture belongs to the individual, not any
17
- * org (the prior handler's org-scoped `<orgId>/avatars/...` encoded the
18
- * uploading org into a personal asset). Spec + history:
19
- * `reference/asset-upload-system.md`.
20
- *
21
- * `thumbUrl` mirrors `url` — the full image is served for both; a separate
22
- * generated thumbnail is a future refinement (the prior handler generated
23
- * one, but the image-resize dependency is not wired here yet and a missing
24
- * thumb must not block the upload restoring).
25
- */
26
- import type { Hono } from "hono";
27
- export declare function attachTransfersUpload(app: Hono): Promise<void>;
@@ -1,29 +0,0 @@
1
- /**
2
- * @system server-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Auth middleware factory. Three modes, same BetterAuth email-OTP mechanism:
7
- *
8
- * service_install.auth values:
9
- * - omitted | "none" → no gate, no handler (scala-public, scala-sign)
10
- * - "better-auth-cookie" → full session auth: mount handler + session gate
11
- * - "email-otp-only" → mount handler (OTP send/verify), no session gate
12
- *
13
- * The sign-in block determines the UX per mode:
14
- * - "full" → email → OTP → session → portal selection (portal, agents, docs, gpt)
15
- * - "email-gate" → email → OTP → verify-only, no session (forms, proposals, quiz)
16
- * - "capture-only" → email field only, no OTP (sign)
17
- *
18
- * There is NO localhost bypass: 127.0.0.1 is gated identically to the tunnel
19
- * (no session → /sign-in). Tools needing an authed view sign in
20
- * (getSuperAdminSessionCookie); the dev OTP is DB-readable.
21
- *
22
- * When SCALA_OTP_URL is set, /api/auth/* forwards to the centralised
23
- * scala-otp service (per otp-centralised-via-otp-service). Otherwise
24
- * the local better-auth handler is used (dev-host fallback).
25
- */
26
- import type { ServiceInstallConfig } from "@teamscala/db/registry/loader/load-service-install-row";
27
- import type { Hono } from "hono";
28
- export declare function isStaticAssetPath(pathname: string): boolean;
29
- export declare function attachAuthGate(app: Hono, config: ServiceInstallConfig, serviceSlug: string): Promise<void>;
@@ -1,18 +0,0 @@
1
- /**
2
- * @system ui-service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Calls a createPageHandler() handler with the per-request extras the
7
- * SSR pipeline needs: the resolved userId/orgId (from localhost-bypass
8
- * or better-auth-cookie), and the htmlTemplate. Shared by the regions
9
- * and page_slug shell variants.
10
- */
11
- import type { Context } from "hono";
12
- type PageHandler = (req: Request, extras: Record<string, unknown>) => Promise<{
13
- body: unknown;
14
- status: number;
15
- headers: HeadersInit;
16
- }>;
17
- export declare function bindPageHandler(c: Context, handler: PageHandler, authMode: string, serviceSlug: string, label: string, resourceOrgId?: string): Promise<Response>;
18
- export {};
@@ -1,25 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Input hashing for the client-asset build fingerprint.
7
- *
8
- * Split out of build-client-assets.ts, which had grown to 1221 lines holding
9
- * six distinct concerns (lock + status, manifest, hydrate bundle, source maps,
10
- * stylesheet/tailwind, and this). `single-purpose-file` did not catch it: that
11
- * rule flags a file whose top-level exports share no common name root, which
12
- * measures export-NAME cohesion rather than how many concerns a file holds — so
13
- * a large file with few tidily-named exports stays invisible to it.
14
- *
15
- * This module owns ONE concern: turning the build's real inputs into a stable
16
- * hash. `computeInputFingerprint` (still in the parent, and still the only
17
- * exported entry point) composes the two functions exported here; everything
18
- * else is module-private because nothing outside needs it.
19
- *
20
- * Byte-for-byte move — imports adjusted, nothing else. No renames, no type
21
- * changes (`migrations-copy-not-rewrite`).
22
- */
23
- import { createHash } from "node:crypto";
24
- export declare function hashResolvedPackageStylesheets(cwd: string, h: ReturnType<typeof createHash>): Promise<void>;
25
- export declare function hashTeamgbgJsGraph(cwd: string, h: ReturnType<typeof createHash>): Promise<void>;
@@ -1,27 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Tailwind source-candidate scanning for the client CSS build.
7
- *
8
- * Split out of build-client-assets.ts (1221 lines, six concerns). Owns ONE
9
- * concern: turning the resolved `@source` directories into the candidate token
10
- * set Tailwind's `build()` consumes.
11
- *
12
- * Why it exists at all, preserved from the original: Tailwind v4's low-level
13
- * `compile()` does NOT scan content, and @tailwindcss/oxide's native Scanner is
14
- * not a dependency of the bare `tailwindcss` lib — only of the integration
15
- * packages. So the tokens are extracted here. Over-extraction is safe, because
16
- * `build()` ignores any token that is not a valid utility. Dropping this scan is
17
- * what shipped an unstyled page to the operator's tablet on 2026-06-13; it is
18
- * enforced by `css-build-scans-source-candidates`.
19
- *
20
- * Byte-for-byte move — imports adjusted, nothing else.
21
- */
22
- import { getAppLogger } from "@teamscala/logger/app-loggers";
23
- export declare function scanSourceCandidates(sources: Array<{
24
- base: string;
25
- pattern: string;
26
- negated?: boolean;
27
- }>, log: ReturnType<typeof getAppLogger>): Promise<string[]>;
@@ -1,50 +0,0 @@
1
- /**
2
- * @system server-handlers
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * Builds the per-service client bundle and stylesheet into `dist/client/`
7
- * at UI-service boot time. Outputs are content-hashed so deployments
8
- * naturally cache-bust:
9
- *
10
- * src/entry-client.ts ──bun build──> dist/client/hydrate-<hash>.js
11
- * src/app.css ──tailwindcss──> dist/client/styles-<hash>.css
12
- * (and) dist/client/asset-manifest.json
13
- *
14
- * The HTML template references `{{stylesPath}}` / `{{hydratePath}}` —
15
- * read-html-template.ts substitutes from the manifest at template-read
16
- * time. Bytes-level changes → new hash → new URL → browser refetch.
17
- * Without this, `cache-control: immutable` on a fixed filename means
18
- * returning visitors keep their stale copy forever.
19
- *
20
- * Content-fingerprint cache: the CLIENT-BUNDLE DEPENDENCY CLOSURE (source
21
- * entrypoints + every @teamscala/* module/stylesheet the bundle reaches + the
22
- * resolved versions of the third-party deps the closure imports) is hashed by
23
- * CONTENT and stored in the manifest; the rebuild is skipped only when the
24
- * current closure hashes to the same fingerprint (cache-key-hashes-source-
25
- * inputs-only — never mtime; see computeInputFingerprint for why mtime silently
26
- * served stale bundles on Railway). bun.lock is deliberately NOT hashed — it
27
- * encodes every @teamscala/* version including backend packages outside this
28
- * service's client bundle, so folding it in would rebuild on every publish
29
- * (the publish→rebuild storm; `no-uncontrolled-repetition-or-cascade`). First
30
- * pm2 restart after a real closure change pays the full build cost; unchanged
31
- * restarts skip. Stale hashed outputs from a prior build are removed in the
32
- * same pass so dist/client/ doesn't accumulate dead files.
33
- */
34
- /**
35
- * Read ONLY the tombstone state of the current manifest — the runtime
36
- * (read-html-template, ui-service) calls this to decide whether to surface a
37
- * build-failure signal. Returns null when the manifest is fresh (no
38
- * `buildFailed`). Decoupled from the full AssetManifest read so the runtime
39
- * never depends on the build internals.
40
- */
41
- export declare function readClientBuildStatus(cwd?: string): Promise<{
42
- failed: true;
43
- reason?: string;
44
- at?: string;
45
- } | {
46
- failed: false;
47
- }>;
48
- export declare function stripRemoteImports(css: string): string;
49
- export declare function computeInputFingerprint(cwd: string): Promise<string>;
50
- export declare function buildClientAssets(serviceSlug: string): Promise<void>;
@@ -1,41 +0,0 @@
1
- /**
2
- * @system ui-service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The single canonical page-title composer. Every SSR page handler routes
7
- * through this (portal/region-shell, public shell, single-page resource). A
8
- * page title is DERIVED from data that already exists — the website name +
9
- * the page/entity name — with `builda_pages.meta_title` as an explicit
10
- * per-page OVERRIDE only, never the primary source.
11
- *
12
- * Mirrors the brand-is-org-owned-full-scheme precedent: a value that should
13
- * be DERIVED was instead hand-set per row, and when unset it silently fell
14
- * back to something wrong. For themes the wrong fallback was the generic
15
- * light palette; for titles it was the bare org name — the `default`
16
- * page_meta_template `titleTemplate: "{org.name}"` produced "GBG Indo" with
17
- * no site or page context, and per-row `meta_title` carried stale product
18
- * literals like "Dashboard | scala Hub". The fix is identical in shape:
19
- * derive by default, override explicitly.
20
- *
21
- * Canonical format: `<website.name>: <subject>` (subject = entity title or
22
- * page name), site-first so a browser tab reads the surface then the page.
23
- * A resource surface (forms/quiz/gpt) may supply a curated `templateTitle`
24
- * (e.g. "{agent.name} — {org.name}"); it wins over the default derivation
25
- * but NOT over an explicit per-page override. The composer NEVER returns a
26
- * bare org name — that is the regression this closes, and the
27
- * `page-title-not-bare-org` guard backstops it at the template layer.
28
- */
29
- export interface TitleContext {
30
- /** Per-page override (builda_pages.meta_title). Wins outright when set. */
31
- pageMetaTitle?: string | null;
32
- /** Resolved resource-template string (forms/quiz/gpt). Curated per-surface shape. */
33
- templateTitle?: string | null;
34
- /** builda_websites.name — the surface, the primary site context. */
35
- websiteName?: string | null;
36
- /** builda_pages.name — the page (e.g. "Dashboard"). */
37
- pageName?: string | null;
38
- /** Resource entity title (proposal/form/quiz/agent name) — preferred subject. */
39
- entityTitle?: string | null;
40
- }
41
- export declare function composePageTitle(ctx: TitleContext): string;
@@ -1,15 +0,0 @@
1
- /**
2
- * @system service-boot
3
- * @status handwritten
4
- * @edit edit directly
5
- *
6
- * The content-gate ACCESS endpoint mounter. One generic POST handler for every
7
- * gate: a plain <form> posts {<recordIdField>, email}; on a match against the
8
- * resource's authorized set it sets the signed access cookie and redirects back,
9
- * so the page loader's gate then releases the content. No bespoke endpoint per
10
- * type — each gate is one AccessConfig. Mounted BEFORE the auth gate so it is
11
- * publicly reachable.
12
- */
13
- import type { Hono } from "hono";
14
- import type { AccessConfig } from "./config-types.ts";
15
- export declare function attachContentGateAccess(app: Hono, serviceSlug: string, config: AccessConfig): Promise<void>;