@donghanh/config 0.1.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.
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@donghanh/config",
3
+ "version": "0.1.0",
4
+ "description": "defineConfig + loadConfig for donghanh.config.ts — single source of truth for operations, widgets, and server wiring",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/rezzahub/donghanh",
13
+ "directory": "packages/config"
14
+ }
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,90 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+
5
+ export interface CspConfig {
6
+ connectDomains?: string[];
7
+ resourceDomains?: string[];
8
+ frameDomains?: string[];
9
+ }
10
+
11
+ export interface ServerConfig {
12
+ /** Canonical HTTPS identifier for this MCP server. */
13
+ resource?: string;
14
+ /** OAuth authorization server issuer URLs. */
15
+ authorizationServers?: string[];
16
+ /** Default scopes. */
17
+ scopes?: string[];
18
+ /** Widget sandbox domain (required for Apps SDK submission). */
19
+ widgetDomain?: string;
20
+ /** Shared CSP applied to every widget. */
21
+ csp?: CspConfig;
22
+ /** LLM API key for chatRoutes. */
23
+ apiKey?: string;
24
+ /** LLM model for chatRoutes. */
25
+ model?: string;
26
+ /** System prompt for chatRoutes. Keep short. */
27
+ systemPrompt?: string;
28
+ }
29
+
30
+ export interface DongHanhConfig {
31
+ /** Glob pattern for operation files. */
32
+ operations?: string;
33
+ /** Named widget entries: name → entry file path. */
34
+ widgets?: Record<string, string>;
35
+ /** Server defaults consumed by gptRoutes / mcpRoutes / chatRoutes. */
36
+ server?: ServerConfig;
37
+ }
38
+
39
+ /** Typed identity function for `donghanh.config.ts`. */
40
+ export function defineConfig(config: DongHanhConfig): DongHanhConfig {
41
+ return config;
42
+ }
43
+
44
+ const CONFIG_NAMES = [
45
+ "donghanh.config.ts",
46
+ "donghanh.config.mjs",
47
+ "donghanh.config.js",
48
+ ];
49
+
50
+ export interface LoadedConfig {
51
+ config: DongHanhConfig;
52
+ path: string;
53
+ root: string;
54
+ }
55
+
56
+ /** Find `donghanh.config.*` starting at `cwd`, walking up. */
57
+ export function findConfig(cwd = process.cwd()): string | null {
58
+ let dir = resolve(cwd);
59
+ while (true) {
60
+ for (const name of CONFIG_NAMES) {
61
+ const candidate = resolve(dir, name);
62
+ if (existsSync(candidate)) return candidate;
63
+ }
64
+ const parent = resolve(dir, "..");
65
+ if (parent === dir) return null;
66
+ dir = parent;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Load `donghanh.config.ts` via dynamic import. Requires a runtime that can
72
+ * import TS directly (Bun, tsx, node --experimental-strip-types).
73
+ */
74
+ export async function loadConfig(
75
+ cwd = process.cwd(),
76
+ ): Promise<LoadedConfig | null> {
77
+ const path = findConfig(cwd);
78
+ if (!path) return null;
79
+ const mod = (await import(pathToFileURL(path).href)) as {
80
+ default?: DongHanhConfig;
81
+ config?: DongHanhConfig;
82
+ };
83
+ const config = mod.default ?? mod.config;
84
+ if (!config) {
85
+ throw new Error(
86
+ `${path} must default-export a DongHanhConfig (use defineConfig(...)).`,
87
+ );
88
+ }
89
+ return { config, path, root: resolve(path, "..") };
90
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["esnext"],
5
+ "types": ["node"],
6
+ "module": "esnext",
7
+ "moduleResolution": "bundler",
8
+ "strict": true,
9
+ "noEmit": true,
10
+ "esModuleInterop": true,
11
+ "isolatedModules": true,
12
+ "skipLibCheck": true
13
+ },
14
+ "include": ["src"]
15
+ }