@sixb/app 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ /** Public environment captured at app-server startup. Missing values are undefined. */
2
+ export declare const publicEnv: Readonly<Record<string, string | undefined>>;
3
+ //# sourceMappingURL=public-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-env.d.ts","sourceRoot":"","sources":["../src/public-env.ts"],"names":[],"mappings":"AAMA,uFAAuF;AACvF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAElE,CAAA"}
package/dist/runtime.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { AuthSessionAudience } from "@sixb/core";
2
2
  export interface CustomAppRuntimeConfig {
3
- readonly api: {
3
+ readonly publicEnv?: Readonly<Record<string, string | undefined>>;
4
+ readonly api?: {
4
5
  readonly baseUrl: string;
5
6
  };
6
7
  readonly auth: {
@@ -8,5 +9,6 @@ export interface CustomAppRuntimeConfig {
8
9
  readonly enabled: boolean;
9
10
  };
10
11
  }
12
+ export declare function collectPublicEnv(): Record<string, string>;
11
13
  export declare function renderCustomAppRuntimeScript(config: CustomAppRuntimeConfig): string;
12
14
  //# sourceMappingURL=runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,GAAG,EAAE;QACZ,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAA;QACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAC1B,CAAA;CACF;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAGnF"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;IACjE,QAAQ,CAAC,GAAG,CAAC,EAAE;QACb,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,QAAQ,CAAC,IAAI,EAAE;QACb,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAA;QACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAC1B,CAAA;CACF;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOzD;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAGnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/app",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Custom app toolkit for Sixb projects — route scanning, dev serving, and production builds",
5
5
  "keywords": [
6
6
  "sixb",
@@ -24,6 +24,11 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
+ "browser": {
28
+ "types": "./dist/browser.d.ts",
29
+ "bun": "./src/browser.ts",
30
+ "default": "./dist/browser.js"
31
+ },
27
32
  "bun": "./src/index.ts",
28
33
  "import": "./dist/index.js",
29
34
  "default": "./dist/index.js"
@@ -48,9 +53,9 @@
48
53
  "prepack": "bun run build"
49
54
  },
50
55
  "dependencies": {
51
- "@sixb/agent-ui": "^0.1.7",
52
- "@sixb/core": "^0.1.8",
53
- "@sixb/ui": "^0.1.1",
56
+ "@sixb/agent-ui": "^0.1.8",
57
+ "@sixb/core": "^0.1.11",
58
+ "@sixb/ui": "^0.1.2",
54
59
  "@tailwindcss/cli": "^4.2.2",
55
60
  "tailwindcss": "^4.1.18"
56
61
  },
@@ -70,7 +75,7 @@
70
75
  },
71
76
  "license": "MIT",
72
77
  "engines": {
73
- "bun": ">=1.3.0"
78
+ "bun": ">=1.4.2"
74
79
  },
75
80
  "publishConfig": {
76
81
  "access": "public"
@@ -80,5 +85,6 @@
80
85
  "src",
81
86
  "README.md",
82
87
  "LICENSE"
83
- ]
88
+ ],
89
+ "sideEffects": false
84
90
  }
package/src/browser.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type { AppMetadata } from "./metadata"
2
+ export { publicEnv } from "./public-env"
@@ -21,7 +21,7 @@ import {
21
21
  generateRouteManifest,
22
22
  } from "./codegen"
23
23
  import { devReloadResponse } from "./dev-reload"
24
- import { renderCustomAppRuntimeScript } from "./runtime"
24
+ import { collectPublicEnv, renderCustomAppRuntimeScript } from "./runtime"
25
25
  import { type PageRoute, routePatternKey, scanAppRoutes } from "./scanner"
26
26
  import { type CustomAppStylesheet, resolveCustomAppStylesheet } from "./styles"
27
27
  import { createTailwindCssCompiler, type TailwindCssCompiler } from "./tailwind"
@@ -332,6 +332,9 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
332
332
  },
333
333
 
334
334
  async dev(devOptions: CustomAppDevOptions = {}) {
335
+ const publicEnv = collectPublicEnv()
336
+ const withRuntime = (html: string) =>
337
+ injectRuntimeConfig(html, { apiBaseUrl, audience, authEnabled, publicEnv })
335
338
  const host = devOptions.host ?? "0.0.0.0"
336
339
  const port = devOptions.port ?? 3001
337
340
  const { htmlPath, manifestPath, sharedHtmlPath, sharedMainPath } = await prepareGeneratedApp()
@@ -363,9 +366,24 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
363
366
  "/__sixb/dev-reload.js": getHeadRoute(devReloadResponse),
364
367
  [customAppManifestRoute]: manifestRoute(manifestPath),
365
368
  [privateAppShellRoute]: htmlBundleRoute(bundle),
366
- ...sharedAppDevRoutes(async () => (await ensureSharedBuild()).html, apiBaseUrl),
367
- "/": spaHtmlRoute(() => internalOrigin, { shellRoute: privateAppShellRoute }),
368
- "/*": spaHtmlRoute(() => internalOrigin, { shellRoute: privateAppShellRoute }),
369
+ ...sharedAppDevRoutes(
370
+ async () =>
371
+ injectRuntimeConfig((await ensureSharedBuild()).html, {
372
+ apiBaseUrl,
373
+ audience: "app",
374
+ authEnabled: false,
375
+ publicEnv,
376
+ }),
377
+ apiBaseUrl
378
+ ),
379
+ "/": spaHtmlRoute(() => internalOrigin, {
380
+ shellRoute: privateAppShellRoute,
381
+ transformHtml: withRuntime,
382
+ }),
383
+ "/*": spaHtmlRoute(() => internalOrigin, {
384
+ shellRoute: privateAppShellRoute,
385
+ transformHtml: withRuntime,
386
+ }),
369
387
  },
370
388
  }) as Parameters<typeof Bun.serve>[0]
371
389
 
@@ -527,6 +545,7 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
527
545
  },
528
546
 
529
547
  async start(startOptions: CustomAppStartOptions = {}) {
548
+ const publicEnv = collectPublicEnv()
530
549
  const host = startOptions.host ?? "0.0.0.0"
531
550
  const port = startOptions.port ?? 3001
532
551
  const outdir = resolve(rootDir, startOptions.outdir ?? join(".sixb", "dist", "app"))
@@ -546,11 +565,13 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
546
565
  apiBaseUrl: startOptions.apiBaseUrl ?? apiBaseUrl,
547
566
  audience: startOptions.audience ?? audience,
548
567
  authEnabled: startOptions.authEnabled ?? authEnabled,
568
+ publicEnv,
549
569
  })
550
570
  const sharedIndexHtml = injectRuntimeConfig(await Bun.file(sharedIndexPath).text(), {
551
571
  apiBaseUrl: startOptions.apiBaseUrl ?? apiBaseUrl,
552
572
  audience: "app",
553
573
  authEnabled: false,
574
+ publicEnv,
554
575
  })
555
576
  const runtimeApiBaseUrl = startOptions.apiBaseUrl ?? apiBaseUrl
556
577
  const server = Bun.serve({
@@ -593,6 +614,9 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
593
614
 
594
615
  const directFile = Bun.file(resolvedPath)
595
616
  if (await directFile.exists()) {
617
+ if (resolvedPath === indexPath) {
618
+ return htmlResponse(req, indexHtml)
619
+ }
596
620
  return staticFileResponse(req, resolvedPath, staticAssetHeaders(url.pathname))
597
621
  }
598
622
 
@@ -602,6 +626,9 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
602
626
 
603
627
  const htmlFile = Bun.file(`${resolvedPath}.html`)
604
628
  if (await htmlFile.exists()) {
629
+ if (`${resolvedPath}.html` === indexPath) {
630
+ return htmlResponse(req, indexHtml)
631
+ }
605
632
  return fileResponse(req, htmlFile)
606
633
  }
607
634
 
@@ -887,23 +914,28 @@ function injectRuntimeConfig(
887
914
  readonly apiBaseUrl?: string
888
915
  readonly audience: AuthSessionAudience
889
916
  readonly authEnabled: boolean
917
+ readonly publicEnv: Record<string, string>
890
918
  }
891
919
  ): string {
892
- if (!config.apiBaseUrl) {
893
- return html
894
- }
895
-
920
+ const existingRuntimeScript = /<script>window\.__SIXB_RUNTIME__ = (.*?);<\/script>/
921
+ const existingConfig = html.match(existingRuntimeScript)?.[1]
896
922
  const script = renderCustomAppRuntimeScript({
897
- api: { baseUrl: config.apiBaseUrl },
898
923
  auth: { audience: config.audience, enabled: config.authEnabled },
924
+ ...(existingConfig ? JSON.parse(existingConfig) : {}),
925
+ ...(config.apiBaseUrl
926
+ ? {
927
+ api: { baseUrl: config.apiBaseUrl },
928
+ auth: { audience: config.audience, enabled: config.authEnabled },
929
+ }
930
+ : {}),
931
+ publicEnv: config.publicEnv,
899
932
  })
900
- const existingRuntimeScript = /<script>window\.__SIXB_RUNTIME__ = .*?;<\/script>/
901
933
  if (existingRuntimeScript.test(html)) {
902
- return html.replace(existingRuntimeScript, script)
934
+ return html.replace(existingRuntimeScript, () => script)
903
935
  }
904
936
 
905
- if (html.includes("</head>")) {
906
- return html.replace("</head>", ` ${script}\n </head>`)
937
+ if (/<head\b[^>]*>/i.test(html)) {
938
+ return html.replace(/<head\b[^>]*>/i, (head) => `${head}\n ${script}`)
907
939
  }
908
940
 
909
941
  return `${script}\n${html}`
@@ -1135,7 +1167,7 @@ function devServerInternalOrigin(host: string, port: number): string {
1135
1167
 
1136
1168
  function spaHtmlRoute(
1137
1169
  internalOrigin: () => string,
1138
- options: { readonly shellRoute?: string } = {}
1170
+ options: { readonly shellRoute?: string; readonly transformHtml?: (html: string) => string } = {}
1139
1171
  ): BunServeRoute {
1140
1172
  return getHeadRoute(async (request) => {
1141
1173
  const publicUrl = new URL(request.url)
@@ -1180,7 +1212,7 @@ function spaHtmlRoute(
1180
1212
  "</head>",
1181
1213
  '<script src="/__sixb/dev-reload.js"></script></head>'
1182
1214
  )
1183
- return new Response(html, {
1215
+ return new Response(options.transformHtml?.(html) ?? html, {
1184
1216
  status: bundleResponse.status,
1185
1217
  statusText: bundleResponse.statusText,
1186
1218
  headers: responseHeaders,
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export {
11
11
  } from "./createCustomApp"
12
12
  export { devReloadResponse } from "./dev-reload"
13
13
  export type { AppMetadata } from "./metadata"
14
+ export { publicEnv } from "./public-env"
14
15
  export {
15
16
  createTailwindCssCompiler,
16
17
  type TailwindCssCompiler,
@@ -0,0 +1,10 @@
1
+ const runtime =
2
+ typeof window === "undefined"
3
+ ? undefined
4
+ : (window as Window & { __SIXB_RUNTIME__?: { publicEnv?: Record<string, string> } })
5
+ .__SIXB_RUNTIME__
6
+
7
+ /** Public environment captured at app-server startup. Missing values are undefined. */
8
+ export const publicEnv: Readonly<Record<string, string | undefined>> = Object.freeze(
9
+ Object.assign(Object.create(null), runtime?.publicEnv)
10
+ )
package/src/runtime.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { AuthSessionAudience } from "@sixb/core"
2
2
 
3
3
  export interface CustomAppRuntimeConfig {
4
- readonly api: {
4
+ readonly publicEnv?: Readonly<Record<string, string | undefined>>
5
+ readonly api?: {
5
6
  readonly baseUrl: string
6
7
  }
7
8
  readonly auth: {
@@ -10,6 +11,15 @@ export interface CustomAppRuntimeConfig {
10
11
  }
11
12
  }
12
13
 
14
+ export function collectPublicEnv(): Record<string, string> {
15
+ return Object.fromEntries(
16
+ Object.entries(process.env).filter(
17
+ (entry): entry is [string, string] =>
18
+ entry[0].startsWith("SIXB_PUBLIC_") && entry[1] !== undefined
19
+ )
20
+ )
21
+ }
22
+
13
23
  export function renderCustomAppRuntimeScript(config: CustomAppRuntimeConfig): string {
14
24
  const safeConfig = JSON.stringify(config).replaceAll("<", "\\u003c")
15
25
  return `<script>window.__SIXB_RUNTIME__ = ${safeConfig};</script>`