@syncular/server-hono 0.0.6-83 → 0.0.6-84

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server-hono",
3
- "version": "0.0.6-83",
3
+ "version": "0.0.6-84",
4
4
  "description": "Hono adapter for the Syncular server with OpenAPI support",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -62,17 +62,17 @@
62
62
  "@hono/standard-validator": "^0.2.2",
63
63
  "@standard-community/standard-json": "^0.3.5",
64
64
  "@standard-community/standard-openapi": "^0.2.9",
65
- "@syncular/console": "0.0.6-83",
66
- "@syncular/core": "0.0.6-83",
67
- "@syncular/server": "0.0.6-83",
65
+ "@syncular/console": "0.0.6-84",
66
+ "@syncular/core": "0.0.6-84",
67
+ "@syncular/server": "0.0.6-84",
68
68
  "@types/json-schema": "^7.0.15",
69
69
  "hono-openapi": "^1.2.0",
70
70
  "openapi-types": "^12.1.3"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@syncular/config": "0.0.0",
74
- "@syncular/dialect-pglite": "0.0.6-83",
75
- "@syncular/server-dialect-postgres": "0.0.6-83",
74
+ "@syncular/dialect-pglite": "0.0.6-84",
75
+ "@syncular/server-dialect-postgres": "0.0.6-84",
76
76
  "kysely": "*",
77
77
  "zod": "*"
78
78
  },
@@ -0,0 +1,114 @@
1
+ import { afterEach, describe, expect, it } from 'bun:test';
2
+ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import path from 'node:path';
5
+ import {
6
+ CONSOLE_BASEPATH_META,
7
+ CONSOLE_SERVER_URL_META,
8
+ CONSOLE_TOKEN_META,
9
+ } from '@syncular/console/runtime-config';
10
+ import { Hono } from 'hono';
11
+ import { mountConsoleUi } from '../console/ui';
12
+
13
+ const tempDirs: string[] = [];
14
+
15
+ async function createStaticFixture(): Promise<string> {
16
+ const staticDir = await mkdtemp(path.join(tmpdir(), 'syncular-console-ui-'));
17
+ tempDirs.push(staticDir);
18
+
19
+ await mkdir(path.join(staticDir, 'assets'), { recursive: true });
20
+ await writeFile(
21
+ path.join(staticDir, 'index.html'),
22
+ `<!doctype html>
23
+ <html>
24
+ <head>
25
+ <meta name="${CONSOLE_BASEPATH_META}" content="" />
26
+ <meta name="${CONSOLE_SERVER_URL_META}" content="" />
27
+ <meta name="${CONSOLE_TOKEN_META}" content="" />
28
+ <link rel="stylesheet" href="/assets/console.css" />
29
+ </head>
30
+ <body>
31
+ <script type="module" src="/assets/main.js"></script>
32
+ </body>
33
+ </html>`
34
+ );
35
+ await writeFile(
36
+ path.join(staticDir, 'assets', 'main.js'),
37
+ 'console.log(1);\n'
38
+ );
39
+ await writeFile(path.join(staticDir, 'assets', 'console.css'), 'body{}\n');
40
+
41
+ return staticDir;
42
+ }
43
+
44
+ afterEach(async () => {
45
+ await Promise.all(
46
+ tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true }))
47
+ );
48
+ });
49
+
50
+ describe('mountConsoleUi', () => {
51
+ it('serves console UI with default prefill derived from mount/api paths', async () => {
52
+ const staticDir = await createStaticFixture();
53
+ const app = new Hono();
54
+
55
+ mountConsoleUi(app, {
56
+ mountPath: 'console',
57
+ apiBasePath: 'api',
58
+ staticDir,
59
+ });
60
+
61
+ const response = await app.request('http://example.test/console');
62
+ const html = await response.text();
63
+
64
+ expect(response.status).toBe(200);
65
+ expect(html).toContain(
66
+ `<meta name="${CONSOLE_BASEPATH_META}" content="/console" />`
67
+ );
68
+ expect(html).toContain(
69
+ `<meta name="${CONSOLE_SERVER_URL_META}" content="http://example.test/api" />`
70
+ );
71
+ expect(html).toContain(`<meta name="${CONSOLE_TOKEN_META}" content="" />`);
72
+ expect(html).toContain('href="/console/assets/console.css"');
73
+ expect(html).toContain('src="/console/assets/main.js"');
74
+
75
+ const asset = await app.request(
76
+ 'http://example.test/console/assets/main.js'
77
+ );
78
+ expect(asset.status).toBe(200);
79
+ expect(await asset.text()).toContain('console.log(1);');
80
+ });
81
+
82
+ it('merges resolvePrefill and allows resolveToken to override token', async () => {
83
+ const staticDir = await createStaticFixture();
84
+ const app = new Hono();
85
+
86
+ mountConsoleUi(app, {
87
+ mountPath: '/ops-console',
88
+ apiBasePath: '/api/internal',
89
+ staticDir,
90
+ resolvePrefill: async () => ({
91
+ basePath: '/prefilled',
92
+ serverUrl: 'https://prefill.example/api',
93
+ token: 'prefill-token',
94
+ }),
95
+ resolveToken: async () => 'resolver-token',
96
+ });
97
+
98
+ const response = await app.request('http://localhost/ops-console');
99
+ const html = await response.text();
100
+
101
+ expect(response.status).toBe(200);
102
+ expect(html).toContain(
103
+ `<meta name="${CONSOLE_BASEPATH_META}" content="/prefilled" />`
104
+ );
105
+ expect(html).toContain(
106
+ `<meta name="${CONSOLE_SERVER_URL_META}" content="https://prefill.example/api" />`
107
+ );
108
+ expect(html).toContain(
109
+ `<meta name="${CONSOLE_TOKEN_META}" content="resolver-token" />`
110
+ );
111
+ expect(html).toContain('href="/prefilled/assets/console.css"');
112
+ expect(html).toContain('src="/prefilled/assets/main.js"');
113
+ });
114
+ });