@ubean/routes 0.5.1 → 0.6.0-beta.1

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/dist/index.d.ts CHANGED
@@ -697,9 +697,25 @@ interface OpenAPIGenerationOptions {
697
697
  description?: string;
698
698
  baseURL?: string;
699
699
  }
700
- export declare function registerOpenAPIRoutes(app: Hono<UbeanEnv$1>, options?: OpenAPIGenerationOptions & {
700
+ /**
701
+ * Scalar 文档页加载脚本的来源(jsdelivr)。
702
+ *
703
+ * 页面自己写死了这个 `<script src>`,因此它的来源也必须能被 CSP 声明 —— 由调用方(`@ubean/app`)
704
+ * 从生效的 CSP 上追加该来源后,作为 {@link ScalarDocumentationOptions.contentSecurityPolicy}
705
+ * 回传,避免「框架内置页面被框架自己的默认 CSP 拦掉」(2026-09-17 实测:默认 `script-src 'self'`
706
+ * 让 DevTools 的 API Docs 面板整页空白)。
707
+ */
708
+ export declare const SCALAR_SCRIPT_ORIGIN = "https://cdn.jsdelivr.net";
709
+ interface ScalarDocumentationOptions {
701
710
  scalarPath?: string;
702
711
  openAPIPath?: string;
703
- }): void;
712
+ /**
713
+ * Scalar 页面专用 CSP(来自调用方对生效 CSP 追加 {@link SCALAR_SCRIPT_ORIGIN} 的结果)。
714
+ *
715
+ * 省略(CSP 被关闭时)则不设头 —— 不会给「用户主动关掉 CSP」的应用重新加上 CSP。
716
+ */
717
+ contentSecurityPolicy?: string;
718
+ }
719
+ export declare function registerOpenAPIRoutes(app: Hono<UbeanEnv$1>, options?: OpenAPIGenerationOptions & ScalarDocumentationOptions): void;
704
720
  //#endregion
705
- export { ACTION_BRAND, type ActionContext, type ActionContextStorage, ActionError, type ActionFailure, type ActionHandler, type ActionId, type ActionResult, type ActionSchema, type CompiledLayout, type CompiledMiddleware, type CompiledPage, type CompiledRoute, type CompiledRouteRule, type ComposedHandler, type DefineActionOptions, type GenericSchema, type Input, type InternalFetchOptions, type IsrCacheEntry, type IsrCacheEntryInternal, type IsrCacheStore, type IsrRule, type IsrServeOptions, type OpenAPIGenerationOptions, type RegisterOptions, type ResolveSelectSsrInput, type ResolvedSelectSsr, type RouteMeta, type RouteRegistrar, type RouteRule, type RouteRulesMiddlewareOptions, type SelectSsrMode, type SelectSsrValue, type ServerAction, type Span, type SpanAttributes, type SpanContext, type SpanEndOptions, type SpanEvent, type SpanOptions, type SpanStatus, type UbeanBindings, type UbeanContext, type UbeanEnv, type UbeanHandler, type UbeanMiddleware, type UbeanVariables, fail, invokeServerFn, isActionFailure, isServerAction, unwrapActionResult, unwrapServerFnResult };
721
+ export { ACTION_BRAND, type ActionContext, type ActionContextStorage, ActionError, type ActionFailure, type ActionHandler, type ActionId, type ActionResult, type ActionSchema, type CompiledLayout, type CompiledMiddleware, type CompiledPage, type CompiledRoute, type CompiledRouteRule, type ComposedHandler, type DefineActionOptions, type GenericSchema, type Input, type InternalFetchOptions, type IsrCacheEntry, type IsrCacheEntryInternal, type IsrCacheStore, type IsrRule, type IsrServeOptions, type OpenAPIGenerationOptions, type RegisterOptions, type ResolveSelectSsrInput, type ResolvedSelectSsr, type RouteMeta, type RouteRegistrar, type RouteRule, type RouteRulesMiddlewareOptions, type ScalarDocumentationOptions, type SelectSsrMode, type SelectSsrValue, type ServerAction, type Span, type SpanAttributes, type SpanContext, type SpanEndOptions, type SpanEvent, type SpanOptions, type SpanStatus, type UbeanBindings, type UbeanContext, type UbeanEnv, type UbeanHandler, type UbeanMiddleware, type UbeanVariables, fail, invokeServerFn, isActionFailure, isServerAction, unwrapActionResult, unwrapServerFnResult };
package/dist/index.js CHANGED
@@ -1433,6 +1433,15 @@ function createInternalAdapter(c, options) {
1433
1433
  }
1434
1434
  //#endregion
1435
1435
  //#region src/openapi.ts
1436
+ /**
1437
+ * Scalar 文档页加载脚本的来源(jsdelivr)。
1438
+ *
1439
+ * 页面自己写死了这个 `<script src>`,因此它的来源也必须能被 CSP 声明 —— 由调用方(`@ubean/app`)
1440
+ * 从生效的 CSP 上追加该来源后,作为 {@link ScalarDocumentationOptions.contentSecurityPolicy}
1441
+ * 回传,避免「框架内置页面被框架自己的默认 CSP 拦掉」(2026-09-17 实测:默认 `script-src 'self'`
1442
+ * 让 DevTools 的 API Docs 面板整页空白)。
1443
+ */
1444
+ const SCALAR_SCRIPT_ORIGIN = "https://cdn.jsdelivr.net";
1436
1445
  function registerOpenAPIRoutes(app, options = {}) {
1437
1446
  const { scalarPath = "/_scalar", openAPIPath = "/_openapi.json", title = "API Reference" } = options;
1438
1447
  const documentation = {
@@ -1455,6 +1464,7 @@ function registerOpenAPIRoutes(app, options = {}) {
1455
1464
  });
1456
1465
  });
1457
1466
  app.get(scalarPath, (c) => {
1467
+ if (options.contentSecurityPolicy) c.header("Content-Security-Policy", options.contentSecurityPolicy);
1458
1468
  const scalarHTML = `<!doctype html>
1459
1469
  <html>
1460
1470
  <head>
@@ -1475,14 +1485,15 @@ function registerOpenAPIRoutes(app, options = {}) {
1475
1485
  "theme": "purple",
1476
1486
  "layout": "modern",
1477
1487
  "hideClientButton": false,
1478
- "defaultHttpClient": { "targetKey": "shell", "clientKey": "curl" }
1488
+ "defaultHttpClient": { "targetKey": "shell", "clientKey": "curl" },
1489
+ "withDefaultFonts": false
1479
1490
  }'
1480
1491
  ><\/script>
1481
- <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"><\/script>
1492
+ <script src="${SCALAR_SCRIPT_ORIGIN}/npm/@scalar/api-reference"><\/script>
1482
1493
  </body>
1483
1494
  </html>`;
1484
1495
  return c.html(scalarHTML);
1485
1496
  });
1486
1497
  }
1487
1498
  //#endregion
1488
- export { ACTIONS_ENDPOINT, ACTION_BRAND, ACTION_RESPONSE_HEADER, ActionError, UbeanRouter, applyPathTransform, bindActionContextStorage, buildActionContext, buildFormActionUrl, buildIsrCacheKey, clearActions, clearInternalFetcher, compileRouteRules, convertUbeanRoutePath, createActionId, createActionsMiddleware, createDetachedActionContext, createInternalAdapter, createRouteLoader, createRouteRulesMiddleware, createServerRouter, defineAction, defineHandler, defineHandlerMeta, defineMiddleware, defineServerFn, describeActionsOpenApi, dispatchAction, extractRouteMeta, fail, getAction, getActionContext, getInternalFetcher, getIsrCache, getIsrRuleFromContext, getStaleIsrCache, hasAction, hasFormAction, invalidateIsrCache, invalidateIsrCachePattern, invokeServerFn, isActionFailure, isActionResponse, isActionsRequest, isBotUserAgent, isHandlerChain, isIsrEntryStale, isServerAction, isValidActionId, listActions, matchRouteRules, normalizeActionResult, normalizeIsrRule, parseActionInput, parseFormActionName, registerAction, registerActions, registerApiRoutes, registerOpenAPIRoutes, registerPageRoutes, registerRoutes, resolveSelectSsr, runAction, runPageAction, runWithActionContext, serveIsr, setInternalFetcher, setIsrCache, sortPagesForRegistration, ssrModeHeader, unwrapActionResult, unwrapServerFnResult, useRouter, validateActionInput };
1499
+ export { ACTIONS_ENDPOINT, ACTION_BRAND, ACTION_RESPONSE_HEADER, ActionError, SCALAR_SCRIPT_ORIGIN, UbeanRouter, applyPathTransform, bindActionContextStorage, buildActionContext, buildFormActionUrl, buildIsrCacheKey, clearActions, clearInternalFetcher, compileRouteRules, convertUbeanRoutePath, createActionId, createActionsMiddleware, createDetachedActionContext, createInternalAdapter, createRouteLoader, createRouteRulesMiddleware, createServerRouter, defineAction, defineHandler, defineHandlerMeta, defineMiddleware, defineServerFn, describeActionsOpenApi, dispatchAction, extractRouteMeta, fail, getAction, getActionContext, getInternalFetcher, getIsrCache, getIsrRuleFromContext, getStaleIsrCache, hasAction, hasFormAction, invalidateIsrCache, invalidateIsrCachePattern, invokeServerFn, isActionFailure, isActionResponse, isActionsRequest, isBotUserAgent, isHandlerChain, isIsrEntryStale, isServerAction, isValidActionId, listActions, matchRouteRules, normalizeActionResult, normalizeIsrRule, parseActionInput, parseFormActionName, registerAction, registerActions, registerApiRoutes, registerOpenAPIRoutes, registerPageRoutes, registerRoutes, resolveSelectSsr, runAction, runPageAction, runWithActionContext, serveIsr, setInternalFetcher, setIsrCache, sortPagesForRegistration, ssrModeHeader, unwrapActionResult, unwrapServerFnResult, useRouter, validateActionInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/routes",
3
- "version": "0.5.1",
3
+ "version": "0.6.0-beta.1",
4
4
  "description": "Server routes runtime for ubean (defineHandler, defineMiddleware, registerRoutes, Server Actions, rou3 server router, route rules, ISR, internal-fetch, OpenAPI)",
5
5
  "files": [
6
6
  "dist"
@@ -24,23 +24,23 @@
24
24
  "@soybeanjs/fetch": "^0.1.0",
25
25
  "@standard-community/standard-json": "^0.3.6",
26
26
  "@standard-community/standard-openapi": "^0.2.10",
27
- "@ubean/i18n": "0.5.1",
28
- "@ubean/shared": "0.5.1",
27
+ "@ubean/i18n": "0.6.0-beta.1",
28
+ "@ubean/shared": "0.6.0-beta.1",
29
29
  "hono": "4.13.7",
30
30
  "hono-openapi": "^1.3.3",
31
31
  "rou3": "^0.9.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^26.5.0",
35
- "@ubean/pages": "0.5.1",
36
- "@ubean/scan": "0.5.1",
35
+ "@ubean/pages": "0.6.0-beta.1",
36
+ "@ubean/scan": "0.6.0-beta.1",
37
37
  "typescript": "npm:typescript-native-bridge@latest",
38
38
  "vite-plus": "0.3.1",
39
39
  "vue": "^3.5.42"
40
40
  },
41
41
  "peerDependencies": {
42
- "@ubean/pages": "0.5.1",
43
- "@ubean/scan": "0.5.1",
42
+ "@ubean/pages": "0.6.0-beta.1",
43
+ "@ubean/scan": "0.6.0-beta.1",
44
44
  "vue": "^3.0.0"
45
45
  },
46
46
  "peerDependenciesMeta": {