@heybox/hb-sdk 0.6.6-alpha.3 → 0.6.6-alpha.4

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.
@@ -19,7 +19,7 @@
19
19
  ## Package metadata
20
20
 
21
21
  - Package: `@heybox/hb-sdk`
22
- - Version at generation time: `0.6.6-alpha.3`
22
+ - Version at generation time: `0.6.6-alpha.4`
23
23
  - Public root export: `@heybox/hb-sdk`
24
24
  - Protocol export: `@heybox/hb-sdk/protocol`
25
25
  - Vite plugin export: `@heybox/hb-sdk/vite`
@@ -204,6 +204,7 @@ import { HB_SDK_VERSION } from '../core/version';
204
204
  import { renderMiniappManifest, validateMiniappPackageVersionForBuild } from '../miniapp-manifest/schema';
205
205
  import { readMiniappVersionFromPackageJson } from '../miniapp-manifest/node';
206
206
  import { enforceMiniappHtmlPolicy } from './html-policy';
207
+ import { shouldSkipMiniappPlatformCspFromEnv } from './runtime-permission-env';
207
208
 
208
209
  type MiniappManifestPlugin = {
209
210
  name: string;
@@ -248,6 +249,7 @@ const sdkVersionPlaceholder = ['__HB_SDK', 'VERSION__'].join('_');
248
249
  const sdkVersionBuildConstant = ['__HB_SDK_BUILD', 'VERSION__'].join('_');
249
250
 
250
251
  export function miniappManifest(): MiniappManifestPlugin {
252
+ const skipPlatformCsp = shouldSkipMiniappPlatformCspFromEnv();
251
253
  let root = process.cwd();
252
254
  let outDir = 'dist';
253
255
  let command: 'build' | 'serve' = 'build';
@@ -278,7 +280,10 @@ export function miniappManifest(): MiniappManifestPlugin {
278
280
  }
279
281
  },
280
282
  transformIndexHtml(html) {
281
- return enforceMiniappHtmlPolicy(html, command === 'serve' ? { hmrWebSocketUrl } : undefined);
283
+ return enforceMiniappHtmlPolicy(html, {
284
+ ...(command === 'serve' ? { hmrWebSocketUrl } : {}),
285
+ skipPlatformCsp,
286
+ });
282
287
  },
283
288
  async closeBundle() {
284
289
  // Rollup 在 buildStart/transform 失败后仍会调用 closeBundle。
@@ -303,7 +308,7 @@ export function miniappManifest(): MiniappManifestPlugin {
303
308
  if (!htmlFiles.includes(indexHtmlPath)) {
304
309
  throw new Error('构建产物必须包含入口 dist/index.html');
305
310
  }
306
- writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(readFileSync(indexHtmlPath, 'utf8')));
311
+ writeFileSync(indexHtmlPath, enforceMiniappHtmlPolicy(readFileSync(indexHtmlPath, 'utf8'), { skipPlatformCsp }));
307
312
 
308
313
  const manifestPath = path.join(outputRoot, 'manifest.json');
309
314
  mkdirSync(path.dirname(manifestPath), { recursive: true });
@@ -381,7 +386,9 @@ export default defineConfig({
381
386
 
382
387
  工坊小程序构建产物只能在兼容的小黑盒 Runtime 中启动。普通浏览器直接打开时不会执行标准业务脚本,并会提示在小黑盒 APP 内打开。项目应使用标准 Vite module 入口。
383
388
 
384
- 插件只接受单页应用:输出目录只能存在入口 `index.html`。build 会用结构化 HTML parser 校验入口,并把平台 CSP 插入 `<head>` 首位;已有 CSP 会原样保留,两份策略按浏览器交集生效。正式策略禁止 `fetch`、XHR、WebSocket、EventSource、Beacon、Worker、iframe、表单和对象加载等浏览器原生出口;业务网络请求应使用 `network.request()`。dev 使用相同策略,只额外放行当前 Vite 的精确 HMR WebSocket 地址。
389
+ 插件只接受单页应用:输出目录只能存在入口 `index.html`。`hb-sdk dev` `hb-sdk remote deploy` 会读取绑定小程序的远端 Runtime 权限;仅当 `network.request` 已启用且 `useOfficialDomain=true` 时跳过平台 CSP,否则 build 会把平台 CSP 插入 `<head>` 首位。直接运行 `vite build`、匿名 dev、非法快照或远端权限读取失败时均继续注入。已有 CSP 始终原样保留;注入平台 CSP 时,两份策略按浏览器交集生效。
390
+
391
+ 平台 CSP 会禁止 `fetch`、XHR、WebSocket、EventSource、Beacon、Worker、iframe、表单和对象加载等浏览器原生出口;dev 只额外放行当前 Vite 的精确 HMR WebSocket 地址。跳过平台 CSP 时,这些能力不再由 SDK 构建产物统一限制,但需要宿主授权的业务网络请求仍应使用 `network.request()`。本地 Mock 权限覆盖不会改变构建 CSP,构建判定始终以远端权限快照为准。
385
392
 
386
393
  meta refresh、外部 anchor、`dns-prefetch`、`preconnect`、`prerender`、外部资源 URL 和额外 HTML 会使 build 失败。内联 script/style 允许,但 `unsafe-eval` 不允许。`dev`、`hb-sdk build` 和手动 Vite build 都不请求远端最低 SDK 版本;构建仍会把当前 `sdkVersion` 写入 Manifest,`hb-sdk remote deploy` 仍校验 Manifest 结构并经过服务端 precheck / submit-audit 策略。
387
394
 
package/skill/skill.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.6.6-alpha.3+skill.7940a3d57a8b",
3
+ "skillVersion": "0.6.6-alpha.4+skill.849ac4dd68e1",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.6.6-alpha.3",
7
- "compatibility": "0.6.6-alpha.3"
6
+ "version": "0.6.6-alpha.4",
7
+ "compatibility": "0.6.6-alpha.4"
8
8
  },
9
9
  "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-7940a3d57a8b57fb3045378c068cc875bea2def32d926fcef19e0accad67901b"
10
+ "integrity": "sha256-849ac4dd68e1d39c13e686809d6a4e9c1bcfd90fbac899b45f43bd364db1fc68"
11
11
  }
@@ -1,4 +1,5 @@
1
1
  export declare const PRODUCTION_CSP: string;
2
2
  export declare function enforceMiniappHtmlPolicy(html: string, options?: {
3
3
  hmrWebSocketUrl?: string;
4
+ skipPlatformCsp?: boolean;
4
5
  }): string;
@@ -0,0 +1,9 @@
1
+ export declare const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = "HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN";
2
+ export declare const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = "HB_SDK_RUNTIME_PERMISSION_CONTEXT";
3
+ export declare function shouldSkipMiniappPlatformCspFromEnv(env?: NodeJS.ProcessEnv): boolean;
4
+ export declare function createMiniappPlatformCspEnv(env: NodeJS.ProcessEnv, skipPlatformCsp: boolean): {
5
+ HB_SDK_RUNTIME_PERMISSION_CONTEXT: string;
6
+ HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN: string;
7
+ TZ?: string | undefined;
8
+ };
9
+ export declare function withMiniappPlatformCspEnv<T>(skipPlatformCsp: boolean, action: () => Promise<T>, env?: NodeJS.ProcessEnv): Promise<T>;