@frontmcp/ui 0.5.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.
Files changed (393) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +438 -0
  3. package/package.json +147 -0
  4. package/src/adapters/index.d.ts +10 -0
  5. package/src/adapters/index.js +18 -0
  6. package/src/adapters/index.js.map +1 -0
  7. package/src/adapters/platform-meta.d.ts +165 -0
  8. package/src/adapters/platform-meta.js +310 -0
  9. package/src/adapters/platform-meta.js.map +1 -0
  10. package/src/base-template/bridge.d.ts +89 -0
  11. package/src/base-template/bridge.js +452 -0
  12. package/src/base-template/bridge.js.map +1 -0
  13. package/src/base-template/default-base-template.d.ts +91 -0
  14. package/src/base-template/default-base-template.js +435 -0
  15. package/src/base-template/default-base-template.js.map +1 -0
  16. package/src/base-template/index.d.ts +14 -0
  17. package/src/base-template/index.js +30 -0
  18. package/src/base-template/index.js.map +1 -0
  19. package/src/base-template/polyfills.d.ts +30 -0
  20. package/src/base-template/polyfills.js +190 -0
  21. package/src/base-template/polyfills.js.map +1 -0
  22. package/src/base-template/theme-styles.d.ts +73 -0
  23. package/src/base-template/theme-styles.js +95 -0
  24. package/src/base-template/theme-styles.js.map +1 -0
  25. package/src/bridge/adapters/base-adapter.d.ts +103 -0
  26. package/src/bridge/adapters/base-adapter.js +314 -0
  27. package/src/bridge/adapters/base-adapter.js.map +1 -0
  28. package/src/bridge/adapters/claude.adapter.d.ts +66 -0
  29. package/src/bridge/adapters/claude.adapter.js +145 -0
  30. package/src/bridge/adapters/claude.adapter.js.map +1 -0
  31. package/src/bridge/adapters/ext-apps.adapter.d.ts +142 -0
  32. package/src/bridge/adapters/ext-apps.adapter.js +416 -0
  33. package/src/bridge/adapters/ext-apps.adapter.js.map +1 -0
  34. package/src/bridge/adapters/gemini.adapter.d.ts +63 -0
  35. package/src/bridge/adapters/gemini.adapter.js +160 -0
  36. package/src/bridge/adapters/gemini.adapter.js.map +1 -0
  37. package/src/bridge/adapters/generic.adapter.d.ts +55 -0
  38. package/src/bridge/adapters/generic.adapter.js +108 -0
  39. package/src/bridge/adapters/generic.adapter.js.map +1 -0
  40. package/src/bridge/adapters/index.d.ts +25 -0
  41. package/src/bridge/adapters/index.js +65 -0
  42. package/src/bridge/adapters/index.js.map +1 -0
  43. package/src/bridge/adapters/openai.adapter.d.ts +64 -0
  44. package/src/bridge/adapters/openai.adapter.js +194 -0
  45. package/src/bridge/adapters/openai.adapter.js.map +1 -0
  46. package/src/bridge/core/adapter-registry.d.ts +121 -0
  47. package/src/bridge/core/adapter-registry.js +271 -0
  48. package/src/bridge/core/adapter-registry.js.map +1 -0
  49. package/src/bridge/core/bridge-factory.d.ts +198 -0
  50. package/src/bridge/core/bridge-factory.js +428 -0
  51. package/src/bridge/core/bridge-factory.js.map +1 -0
  52. package/src/bridge/core/index.d.ts +9 -0
  53. package/src/bridge/core/index.js +22 -0
  54. package/src/bridge/core/index.js.map +1 -0
  55. package/src/bridge/index.d.ts +61 -0
  56. package/src/bridge/index.js +94 -0
  57. package/src/bridge/index.js.map +1 -0
  58. package/src/bridge/runtime/iife-generator.d.ts +61 -0
  59. package/src/bridge/runtime/iife-generator.js +940 -0
  60. package/src/bridge/runtime/iife-generator.js.map +1 -0
  61. package/src/bridge/runtime/index.d.ts +8 -0
  62. package/src/bridge/runtime/index.js +16 -0
  63. package/src/bridge/runtime/index.js.map +1 -0
  64. package/src/bridge/types.d.ts +385 -0
  65. package/src/bridge/types.js +11 -0
  66. package/src/bridge/types.js.map +1 -0
  67. package/src/build/cdn-resources.d.ts +140 -0
  68. package/src/build/cdn-resources.js +314 -0
  69. package/src/build/cdn-resources.js.map +1 -0
  70. package/src/build/index.d.ts +294 -0
  71. package/src/build/index.js +325 -0
  72. package/src/build/index.js.map +1 -0
  73. package/src/build/widget-manifest.d.ts +212 -0
  74. package/src/build/widget-manifest.js +652 -0
  75. package/src/build/widget-manifest.js.map +1 -0
  76. package/src/bundler/bundler.d.ts +110 -0
  77. package/src/bundler/bundler.js +432 -0
  78. package/src/bundler/bundler.js.map +1 -0
  79. package/src/bundler/cache.d.ts +172 -0
  80. package/src/bundler/cache.js +250 -0
  81. package/src/bundler/cache.js.map +1 -0
  82. package/src/bundler/index.d.ts +41 -0
  83. package/src/bundler/index.js +73 -0
  84. package/src/bundler/index.js.map +1 -0
  85. package/src/bundler/sandbox/enclave-adapter.d.ts +120 -0
  86. package/src/bundler/sandbox/enclave-adapter.js +339 -0
  87. package/src/bundler/sandbox/enclave-adapter.js.map +1 -0
  88. package/src/bundler/sandbox/executor.d.ts +13 -0
  89. package/src/bundler/sandbox/executor.js +22 -0
  90. package/src/bundler/sandbox/executor.js.map +1 -0
  91. package/src/bundler/sandbox/policy.d.ts +61 -0
  92. package/src/bundler/sandbox/policy.js +238 -0
  93. package/src/bundler/sandbox/policy.js.map +1 -0
  94. package/src/bundler/types.d.ts +347 -0
  95. package/src/bundler/types.js +132 -0
  96. package/src/bundler/types.js.map +1 -0
  97. package/src/components/alert.d.ts +71 -0
  98. package/src/components/alert.js +189 -0
  99. package/src/components/alert.js.map +1 -0
  100. package/src/components/alert.schema.d.ts +114 -0
  101. package/src/components/alert.schema.js +105 -0
  102. package/src/components/alert.schema.js.map +1 -0
  103. package/src/components/avatar.d.ts +76 -0
  104. package/src/components/avatar.js +176 -0
  105. package/src/components/avatar.js.map +1 -0
  106. package/src/components/avatar.schema.d.ts +169 -0
  107. package/src/components/avatar.schema.js +103 -0
  108. package/src/components/avatar.schema.js.map +1 -0
  109. package/src/components/badge.d.ts +70 -0
  110. package/src/components/badge.js +149 -0
  111. package/src/components/badge.js.map +1 -0
  112. package/src/components/badge.schema.d.ts +109 -0
  113. package/src/components/badge.schema.js +96 -0
  114. package/src/components/badge.schema.js.map +1 -0
  115. package/src/components/button.d.ts +111 -0
  116. package/src/components/button.js +336 -0
  117. package/src/components/button.js.map +1 -0
  118. package/src/components/button.schema.d.ts +148 -0
  119. package/src/components/button.schema.js +121 -0
  120. package/src/components/button.schema.js.map +1 -0
  121. package/src/components/card.d.ts +60 -0
  122. package/src/components/card.js +117 -0
  123. package/src/components/card.js.map +1 -0
  124. package/src/components/card.schema.d.ts +113 -0
  125. package/src/components/card.schema.js +98 -0
  126. package/src/components/card.schema.js.map +1 -0
  127. package/src/components/form.d.ts +239 -0
  128. package/src/components/form.js +420 -0
  129. package/src/components/form.js.map +1 -0
  130. package/src/components/form.schema.d.ts +441 -0
  131. package/src/components/form.schema.js +406 -0
  132. package/src/components/form.schema.js.map +1 -0
  133. package/src/components/index.d.ts +29 -0
  134. package/src/components/index.js +98 -0
  135. package/src/components/index.js.map +1 -0
  136. package/src/components/list.d.ts +127 -0
  137. package/src/components/list.js +279 -0
  138. package/src/components/list.js.map +1 -0
  139. package/src/components/list.schema.d.ts +134 -0
  140. package/src/components/list.schema.js +168 -0
  141. package/src/components/list.schema.js.map +1 -0
  142. package/src/components/modal.d.ts +111 -0
  143. package/src/components/modal.js +260 -0
  144. package/src/components/modal.js.map +1 -0
  145. package/src/components/modal.schema.d.ts +186 -0
  146. package/src/components/modal.schema.js +167 -0
  147. package/src/components/modal.schema.js.map +1 -0
  148. package/src/components/table.d.ts +105 -0
  149. package/src/components/table.js +283 -0
  150. package/src/components/table.js.map +1 -0
  151. package/src/components/table.schema.d.ts +159 -0
  152. package/src/components/table.schema.js +173 -0
  153. package/src/components/table.schema.js.map +1 -0
  154. package/src/handlebars/helpers.d.ts +348 -0
  155. package/src/handlebars/helpers.js +605 -0
  156. package/src/handlebars/helpers.js.map +1 -0
  157. package/src/handlebars/index.d.ts +193 -0
  158. package/src/handlebars/index.js +350 -0
  159. package/src/handlebars/index.js.map +1 -0
  160. package/src/index.d.ts +50 -0
  161. package/src/index.js +192 -0
  162. package/src/index.js.map +1 -0
  163. package/src/layouts/base.d.ts +88 -0
  164. package/src/layouts/base.js +227 -0
  165. package/src/layouts/base.js.map +1 -0
  166. package/src/layouts/index.d.ts +7 -0
  167. package/src/layouts/index.js +25 -0
  168. package/src/layouts/index.js.map +1 -0
  169. package/src/layouts/presets.d.ts +133 -0
  170. package/src/layouts/presets.js +277 -0
  171. package/src/layouts/presets.js.map +1 -0
  172. package/src/pages/consent.d.ts +116 -0
  173. package/src/pages/consent.js +218 -0
  174. package/src/pages/consent.js.map +1 -0
  175. package/src/pages/error.d.ts +100 -0
  176. package/src/pages/error.js +263 -0
  177. package/src/pages/error.js.map +1 -0
  178. package/src/pages/index.d.ts +8 -0
  179. package/src/pages/index.js +27 -0
  180. package/src/pages/index.js.map +1 -0
  181. package/src/react/Alert.d.ts +101 -0
  182. package/src/react/Alert.js +51 -0
  183. package/src/react/Alert.js.map +1 -0
  184. package/src/react/Badge.d.ts +100 -0
  185. package/src/react/Badge.js +55 -0
  186. package/src/react/Badge.js.map +1 -0
  187. package/src/react/Button.d.ts +108 -0
  188. package/src/react/Button.js +52 -0
  189. package/src/react/Button.js.map +1 -0
  190. package/src/react/Card.d.ts +103 -0
  191. package/src/react/Card.js +55 -0
  192. package/src/react/Card.js.map +1 -0
  193. package/src/react/hooks/context.d.ts +178 -0
  194. package/src/react/hooks/context.js +287 -0
  195. package/src/react/hooks/context.js.map +1 -0
  196. package/src/react/hooks/index.d.ts +41 -0
  197. package/src/react/hooks/index.js +61 -0
  198. package/src/react/hooks/index.js.map +1 -0
  199. package/src/react/hooks/tools.d.ts +283 -0
  200. package/src/react/hooks/tools.js +465 -0
  201. package/src/react/hooks/tools.js.map +1 -0
  202. package/src/react/index.d.ts +80 -0
  203. package/src/react/index.js +113 -0
  204. package/src/react/index.js.map +1 -0
  205. package/src/react/types.d.ts +105 -0
  206. package/src/react/types.js +12 -0
  207. package/src/react/types.js.map +1 -0
  208. package/src/react/utils.d.ts +42 -0
  209. package/src/react/utils.js +99 -0
  210. package/src/react/utils.js.map +1 -0
  211. package/src/registry/index.d.ts +45 -0
  212. package/src/registry/index.js +67 -0
  213. package/src/registry/index.js.map +1 -0
  214. package/src/registry/render-template.d.ts +86 -0
  215. package/src/registry/render-template.js +239 -0
  216. package/src/registry/render-template.js.map +1 -0
  217. package/src/registry/tool-ui.registry.d.ts +260 -0
  218. package/src/registry/tool-ui.registry.js +438 -0
  219. package/src/registry/tool-ui.registry.js.map +1 -0
  220. package/src/registry/uri-utils.d.ts +55 -0
  221. package/src/registry/uri-utils.js +97 -0
  222. package/src/registry/uri-utils.js.map +1 -0
  223. package/src/render/index.d.ts +7 -0
  224. package/src/render/index.js +14 -0
  225. package/src/render/index.js.map +1 -0
  226. package/src/render/prerender.d.ts +56 -0
  227. package/src/render/prerender.js +98 -0
  228. package/src/render/prerender.js.map +1 -0
  229. package/src/renderers/cache.d.ts +144 -0
  230. package/src/renderers/cache.js +240 -0
  231. package/src/renderers/cache.js.map +1 -0
  232. package/src/renderers/html.renderer.d.ts +122 -0
  233. package/src/renderers/html.renderer.js +204 -0
  234. package/src/renderers/html.renderer.js.map +1 -0
  235. package/src/renderers/index.d.ts +35 -0
  236. package/src/renderers/index.js +70 -0
  237. package/src/renderers/index.js.map +1 -0
  238. package/src/renderers/mdx.renderer.d.ts +119 -0
  239. package/src/renderers/mdx.renderer.js +305 -0
  240. package/src/renderers/mdx.renderer.js.map +1 -0
  241. package/src/renderers/react.renderer.d.ts +95 -0
  242. package/src/renderers/react.renderer.js +260 -0
  243. package/src/renderers/react.renderer.js.map +1 -0
  244. package/src/renderers/registry.d.ts +133 -0
  245. package/src/renderers/registry.js +232 -0
  246. package/src/renderers/registry.js.map +1 -0
  247. package/src/renderers/types.d.ts +341 -0
  248. package/src/renderers/types.js +9 -0
  249. package/src/renderers/types.js.map +1 -0
  250. package/src/renderers/utils/detect.d.ts +106 -0
  251. package/src/renderers/utils/detect.js +267 -0
  252. package/src/renderers/utils/detect.js.map +1 -0
  253. package/src/renderers/utils/hash.d.ts +39 -0
  254. package/src/renderers/utils/hash.js +75 -0
  255. package/src/renderers/utils/hash.js.map +1 -0
  256. package/src/renderers/utils/index.d.ts +8 -0
  257. package/src/renderers/utils/index.js +28 -0
  258. package/src/renderers/utils/index.js.map +1 -0
  259. package/src/renderers/utils/transpiler.d.ts +88 -0
  260. package/src/renderers/utils/transpiler.js +215 -0
  261. package/src/renderers/utils/transpiler.js.map +1 -0
  262. package/src/runtime/adapters/html.adapter.d.ts +58 -0
  263. package/src/runtime/adapters/html.adapter.js +131 -0
  264. package/src/runtime/adapters/html.adapter.js.map +1 -0
  265. package/src/runtime/adapters/index.d.ts +25 -0
  266. package/src/runtime/adapters/index.js +54 -0
  267. package/src/runtime/adapters/index.js.map +1 -0
  268. package/src/runtime/adapters/mdx.adapter.d.ts +72 -0
  269. package/src/runtime/adapters/mdx.adapter.js +241 -0
  270. package/src/runtime/adapters/mdx.adapter.js.map +1 -0
  271. package/src/runtime/adapters/react.adapter.d.ts +69 -0
  272. package/src/runtime/adapters/react.adapter.js +245 -0
  273. package/src/runtime/adapters/react.adapter.js.map +1 -0
  274. package/src/runtime/adapters/types.d.ts +94 -0
  275. package/src/runtime/adapters/types.js +11 -0
  276. package/src/runtime/adapters/types.js.map +1 -0
  277. package/src/runtime/csp.d.ts +37 -0
  278. package/src/runtime/csp.js +140 -0
  279. package/src/runtime/csp.js.map +1 -0
  280. package/src/runtime/index.d.ts +16 -0
  281. package/src/runtime/index.js +72 -0
  282. package/src/runtime/index.js.map +1 -0
  283. package/src/runtime/mcp-bridge.d.ts +100 -0
  284. package/src/runtime/mcp-bridge.js +581 -0
  285. package/src/runtime/mcp-bridge.js.map +1 -0
  286. package/src/runtime/renderer-runtime.d.ts +132 -0
  287. package/src/runtime/renderer-runtime.js +389 -0
  288. package/src/runtime/renderer-runtime.js.map +1 -0
  289. package/src/runtime/sanitizer.d.ts +171 -0
  290. package/src/runtime/sanitizer.js +318 -0
  291. package/src/runtime/sanitizer.js.map +1 -0
  292. package/src/runtime/types.d.ts +414 -0
  293. package/src/runtime/types.js +12 -0
  294. package/src/runtime/types.js.map +1 -0
  295. package/src/runtime/wrapper.d.ts +375 -0
  296. package/src/runtime/wrapper.js +1793 -0
  297. package/src/runtime/wrapper.js.map +1 -0
  298. package/src/styles/index.d.ts +7 -0
  299. package/src/styles/index.js +11 -0
  300. package/src/styles/index.js.map +1 -0
  301. package/src/styles/variants.d.ts +50 -0
  302. package/src/styles/variants.js +175 -0
  303. package/src/styles/variants.js.map +1 -0
  304. package/src/theme/cdn.d.ts +194 -0
  305. package/src/theme/cdn.js +375 -0
  306. package/src/theme/cdn.js.map +1 -0
  307. package/src/theme/index.d.ts +17 -0
  308. package/src/theme/index.js +57 -0
  309. package/src/theme/index.js.map +1 -0
  310. package/src/theme/platforms.d.ts +106 -0
  311. package/src/theme/platforms.js +161 -0
  312. package/src/theme/platforms.js.map +1 -0
  313. package/src/theme/presets/github-openai.d.ts +49 -0
  314. package/src/theme/presets/github-openai.js +189 -0
  315. package/src/theme/presets/github-openai.js.map +1 -0
  316. package/src/theme/presets/index.d.ts +10 -0
  317. package/src/theme/presets/index.js +17 -0
  318. package/src/theme/presets/index.js.map +1 -0
  319. package/src/theme/theme.d.ts +395 -0
  320. package/src/theme/theme.js +332 -0
  321. package/src/theme/theme.js.map +1 -0
  322. package/src/tool-template/builder.d.ts +212 -0
  323. package/src/tool-template/builder.js +397 -0
  324. package/src/tool-template/builder.js.map +1 -0
  325. package/src/tool-template/index.d.ts +15 -0
  326. package/src/tool-template/index.js +38 -0
  327. package/src/tool-template/index.js.map +1 -0
  328. package/src/types/index.d.ts +13 -0
  329. package/src/types/index.js +26 -0
  330. package/src/types/index.js.map +1 -0
  331. package/src/types/ui-config.d.ts +357 -0
  332. package/src/types/ui-config.js +12 -0
  333. package/src/types/ui-config.js.map +1 -0
  334. package/src/types/ui-runtime.d.ts +965 -0
  335. package/src/types/ui-runtime.js +117 -0
  336. package/src/types/ui-runtime.js.map +1 -0
  337. package/src/validation/error-box.d.ts +55 -0
  338. package/src/validation/error-box.js +75 -0
  339. package/src/validation/error-box.js.map +1 -0
  340. package/src/validation/index.d.ts +12 -0
  341. package/src/validation/index.js +21 -0
  342. package/src/validation/index.js.map +1 -0
  343. package/src/validation/wrapper.d.ts +96 -0
  344. package/src/validation/wrapper.js +117 -0
  345. package/src/validation/wrapper.js.map +1 -0
  346. package/src/web-components/core/attribute-parser.d.ts +85 -0
  347. package/src/web-components/core/attribute-parser.js +189 -0
  348. package/src/web-components/core/attribute-parser.js.map +1 -0
  349. package/src/web-components/core/base-element.d.ts +197 -0
  350. package/src/web-components/core/base-element.js +289 -0
  351. package/src/web-components/core/base-element.js.map +1 -0
  352. package/src/web-components/core/index.d.ts +8 -0
  353. package/src/web-components/core/index.js +18 -0
  354. package/src/web-components/core/index.js.map +1 -0
  355. package/src/web-components/elements/fmcp-alert.d.ts +45 -0
  356. package/src/web-components/elements/fmcp-alert.js +93 -0
  357. package/src/web-components/elements/fmcp-alert.js.map +1 -0
  358. package/src/web-components/elements/fmcp-badge.d.ts +46 -0
  359. package/src/web-components/elements/fmcp-badge.js +99 -0
  360. package/src/web-components/elements/fmcp-badge.js.map +1 -0
  361. package/src/web-components/elements/fmcp-button.d.ts +124 -0
  362. package/src/web-components/elements/fmcp-button.js +233 -0
  363. package/src/web-components/elements/fmcp-button.js.map +1 -0
  364. package/src/web-components/elements/fmcp-card.d.ts +52 -0
  365. package/src/web-components/elements/fmcp-card.js +115 -0
  366. package/src/web-components/elements/fmcp-card.js.map +1 -0
  367. package/src/web-components/elements/fmcp-input.d.ts +95 -0
  368. package/src/web-components/elements/fmcp-input.js +248 -0
  369. package/src/web-components/elements/fmcp-input.js.map +1 -0
  370. package/src/web-components/elements/fmcp-select.d.ts +99 -0
  371. package/src/web-components/elements/fmcp-select.js +243 -0
  372. package/src/web-components/elements/fmcp-select.js.map +1 -0
  373. package/src/web-components/elements/index.d.ts +12 -0
  374. package/src/web-components/elements/index.js +34 -0
  375. package/src/web-components/elements/index.js.map +1 -0
  376. package/src/web-components/index.d.ts +49 -0
  377. package/src/web-components/index.js +75 -0
  378. package/src/web-components/index.js.map +1 -0
  379. package/src/web-components/register.d.ts +56 -0
  380. package/src/web-components/register.js +80 -0
  381. package/src/web-components/register.js.map +1 -0
  382. package/src/web-components/types.d.ts +121 -0
  383. package/src/web-components/types.js +25 -0
  384. package/src/web-components/types.js.map +1 -0
  385. package/src/widgets/index.d.ts +7 -0
  386. package/src/widgets/index.js +24 -0
  387. package/src/widgets/index.js.map +1 -0
  388. package/src/widgets/progress.d.ts +132 -0
  389. package/src/widgets/progress.js +303 -0
  390. package/src/widgets/progress.js.map +1 -0
  391. package/src/widgets/resource.d.ts +162 -0
  392. package/src/widgets/resource.js +340 -0
  393. package/src/widgets/resource.js.map +1 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Enclave-VM Secure Code Executor
3
+ *
4
+ * Executes bundled code in a secure sandbox using enclave-vm.
5
+ * Provides defense-in-depth security with:
6
+ * - AST-based validation (81+ blocked attack vectors)
7
+ * - Timeout enforcement (default 5000ms)
8
+ * - Resource limits (maxIterations, maxToolCalls)
9
+ * - Six security layers
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import type { SecurityPolicy } from '../types';
14
+ /**
15
+ * Context for code execution.
16
+ */
17
+ export interface ExecutionContext {
18
+ /**
19
+ * React module to inject.
20
+ */
21
+ React?: unknown;
22
+ /**
23
+ * ReactDOM module to inject.
24
+ */
25
+ ReactDOM?: unknown;
26
+ /**
27
+ * Additional modules to inject.
28
+ */
29
+ modules?: Record<string, unknown>;
30
+ /**
31
+ * Additional global variables.
32
+ */
33
+ globals?: Record<string, unknown>;
34
+ /**
35
+ * Security policy to enforce.
36
+ */
37
+ security?: SecurityPolicy;
38
+ /**
39
+ * Execution timeout in milliseconds.
40
+ * @default 5000
41
+ */
42
+ timeout?: number;
43
+ /**
44
+ * Maximum loop iterations allowed.
45
+ * @default 10000
46
+ */
47
+ maxIterations?: number;
48
+ }
49
+ /**
50
+ * Result of code execution.
51
+ */
52
+ export interface ExecutionResult<T = unknown> {
53
+ /**
54
+ * Exported value from the code.
55
+ */
56
+ exports: T;
57
+ /**
58
+ * Execution time in ms.
59
+ */
60
+ executionTime: number;
61
+ /**
62
+ * Console output captured during execution.
63
+ */
64
+ consoleOutput?: string[];
65
+ }
66
+ /**
67
+ * Execute bundled code in a secure enclave-vm sandbox.
68
+ *
69
+ * Provides a sandboxed execution context with:
70
+ * - AST-based code validation (81+ attack vectors blocked)
71
+ * - Timeout enforcement (default 5000ms)
72
+ * - Resource limits (maxIterations)
73
+ * - Six security layers (defense-in-depth)
74
+ *
75
+ * @param code - Bundled JavaScript code
76
+ * @param context - Execution context
77
+ * @returns Execution result with exports
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const code = `
82
+ * const React = require('react');
83
+ * function Widget({ data }) {
84
+ * return React.createElement('div', null, data.message);
85
+ * }
86
+ * module.exports = Widget;
87
+ * `;
88
+ *
89
+ * const result = await executeCode(code, {
90
+ * React: require('react'),
91
+ * timeout: 3000,
92
+ * });
93
+ *
94
+ * console.log(result.exports); // Widget function
95
+ * ```
96
+ */
97
+ export declare function executeCode<T = unknown>(code: string, context?: ExecutionContext): Promise<ExecutionResult<T>>;
98
+ /**
99
+ * Execute bundled code and extract the default export.
100
+ *
101
+ * Convenience wrapper around executeCode that extracts
102
+ * the default export.
103
+ *
104
+ * @param code - Bundled JavaScript code
105
+ * @param context - Execution context
106
+ * @returns Default export from the code
107
+ */
108
+ export declare function executeDefault<T = unknown>(code: string, context?: ExecutionContext): Promise<T>;
109
+ /**
110
+ * Error thrown during code execution.
111
+ */
112
+ export declare class ExecutionError extends Error {
113
+ /** Error code for categorization */
114
+ code?: string;
115
+ constructor(message: string, cause?: unknown);
116
+ }
117
+ /**
118
+ * Check if an error is an ExecutionError.
119
+ */
120
+ export declare function isExecutionError(error: unknown): error is ExecutionError;
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ /**
3
+ * Enclave-VM Secure Code Executor
4
+ *
5
+ * Executes bundled code in a secure sandbox using enclave-vm.
6
+ * Provides defense-in-depth security with:
7
+ * - AST-based validation (81+ blocked attack vectors)
8
+ * - Timeout enforcement (default 5000ms)
9
+ * - Resource limits (maxIterations, maxToolCalls)
10
+ * - Six security layers
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ExecutionError = void 0;
16
+ exports.executeCode = executeCode;
17
+ exports.executeDefault = executeDefault;
18
+ exports.isExecutionError = isExecutionError;
19
+ const enclave_vm_1 = require("enclave-vm");
20
+ /**
21
+ * Default enclave options for secure widget execution.
22
+ */
23
+ const DEFAULT_ENCLAVE_OPTIONS = {
24
+ securityLevel: 'SECURE',
25
+ timeout: 5000,
26
+ maxIterations: 10000,
27
+ validate: true,
28
+ transform: true,
29
+ };
30
+ /**
31
+ * Threshold of blocked imports that triggers STRICT security level.
32
+ * When a SecurityPolicy blocks more than this many imports, we escalate to STRICT.
33
+ */
34
+ const STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD = 10;
35
+ /**
36
+ * Map SecurityPolicy to enclave-vm security level.
37
+ */
38
+ function mapSecurityLevel(policy) {
39
+ // If policy has specific blockedImports or restrictive settings, use STRICT
40
+ if (policy?.blockedImports && policy.blockedImports.length > STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD) {
41
+ return 'STRICT';
42
+ }
43
+ // Default to SECURE for widget code
44
+ return 'SECURE';
45
+ }
46
+ /**
47
+ * Create a minimal JSX runtime from React.
48
+ */
49
+ function createJSXRuntime(React) {
50
+ const R = React;
51
+ return {
52
+ jsx: (type, props, key) => {
53
+ const { children, ...rest } = props;
54
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
55
+ },
56
+ jsxs: (type, props, key) => {
57
+ const { children, ...rest } = props;
58
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
59
+ },
60
+ jsxDEV: (type, props, key, _isStaticChildren, _source, _self) => {
61
+ const { children, ...rest } = props;
62
+ return R.createElement(type, key ? { ...rest, key } : rest, children);
63
+ },
64
+ Fragment: R.Fragment,
65
+ };
66
+ }
67
+ /**
68
+ * Dangerous global keys that should never be injected from user context.
69
+ * These could potentially bypass enclave security if allowed.
70
+ */
71
+ const DANGEROUS_GLOBAL_KEYS = new Set([
72
+ 'process',
73
+ 'require',
74
+ '__dirname',
75
+ '__filename',
76
+ 'Buffer',
77
+ 'eval',
78
+ 'Function',
79
+ 'constructor',
80
+ 'global',
81
+ 'globalThis',
82
+ 'module',
83
+ 'exports',
84
+ '__proto__',
85
+ ]);
86
+ /**
87
+ * Sanitize a key for use as a global variable name.
88
+ * Replaces non-alphanumeric characters (except _ and $) with underscores.
89
+ */
90
+ function sanitizeGlobalKey(key) {
91
+ return key.replace(/[^a-zA-Z0-9_$]/g, '_');
92
+ }
93
+ /**
94
+ * Build globals object from execution context.
95
+ */
96
+ function buildGlobals(context) {
97
+ const globals = {};
98
+ // Add React and ReactDOM if provided
99
+ if (context.React) {
100
+ globals['React'] = context.React;
101
+ }
102
+ if (context.ReactDOM) {
103
+ globals['ReactDOM'] = context.ReactDOM;
104
+ }
105
+ // Add JSX runtime if React is available
106
+ if (context.React) {
107
+ const jsxRuntime = createJSXRuntime(context.React);
108
+ globals['__jsx'] = jsxRuntime['jsx'];
109
+ globals['__jsxs'] = jsxRuntime['jsxs'];
110
+ globals['__jsxDEV'] = jsxRuntime['jsxDEV'];
111
+ globals['Fragment'] = jsxRuntime['Fragment'];
112
+ }
113
+ // Add modules as globals (enclave-vm handles require internally)
114
+ if (context.modules) {
115
+ for (const [key, value] of Object.entries(context.modules)) {
116
+ // Sanitize key and make modules accessible as globals
117
+ const sanitizedKey = sanitizeGlobalKey(key);
118
+ if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {
119
+ throw new ExecutionError(`Dangerous module key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`, { code: 'SECURITY_VIOLATION' });
120
+ }
121
+ globals[sanitizedKey] = value;
122
+ }
123
+ }
124
+ // Add user globals with security filtering
125
+ if (context.globals) {
126
+ for (const [key, value] of Object.entries(context.globals)) {
127
+ // Check for dangerous keys (both original and sanitized)
128
+ if (DANGEROUS_GLOBAL_KEYS.has(key)) {
129
+ throw new ExecutionError(`Dangerous global key '${key}' is not allowed in execution context`, {
130
+ code: 'SECURITY_VIOLATION',
131
+ });
132
+ }
133
+ // Sanitize the key for safe global variable naming
134
+ const sanitizedKey = sanitizeGlobalKey(key);
135
+ if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {
136
+ throw new ExecutionError(`Dangerous global key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`, { code: 'SECURITY_VIOLATION' });
137
+ }
138
+ globals[sanitizedKey] = value;
139
+ }
140
+ }
141
+ return globals;
142
+ }
143
+ /**
144
+ * Build require function for module resolution.
145
+ */
146
+ function buildRequireFunction(context) {
147
+ // Normalize all context.modules keys to lowercase for consistent lookup
148
+ const normalizedContextModules = {};
149
+ if (context.modules) {
150
+ for (const [key, value] of Object.entries(context.modules)) {
151
+ normalizedContextModules[key.toLowerCase()] = value;
152
+ }
153
+ }
154
+ const modules = {
155
+ react: context.React,
156
+ 'react-dom': context.ReactDOM,
157
+ 'react/jsx-runtime': context.React ? createJSXRuntime(context.React) : undefined,
158
+ 'react/jsx-dev-runtime': context.React ? createJSXRuntime(context.React) : undefined,
159
+ ...normalizedContextModules,
160
+ };
161
+ return (id) => {
162
+ const normalizedId = id.toLowerCase();
163
+ if (normalizedId in modules) {
164
+ const mod = modules[normalizedId];
165
+ if (mod === undefined) {
166
+ throw new Error(`Module '${id}' is not available. Did you forget to provide it in the context?`);
167
+ }
168
+ return mod;
169
+ }
170
+ throw new Error(`Module '${id}' is not available in the sandbox environment`);
171
+ };
172
+ }
173
+ /**
174
+ * Execute bundled code in a secure enclave-vm sandbox.
175
+ *
176
+ * Provides a sandboxed execution context with:
177
+ * - AST-based code validation (81+ attack vectors blocked)
178
+ * - Timeout enforcement (default 5000ms)
179
+ * - Resource limits (maxIterations)
180
+ * - Six security layers (defense-in-depth)
181
+ *
182
+ * @param code - Bundled JavaScript code
183
+ * @param context - Execution context
184
+ * @returns Execution result with exports
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const code = `
189
+ * const React = require('react');
190
+ * function Widget({ data }) {
191
+ * return React.createElement('div', null, data.message);
192
+ * }
193
+ * module.exports = Widget;
194
+ * `;
195
+ *
196
+ * const result = await executeCode(code, {
197
+ * React: require('react'),
198
+ * timeout: 3000,
199
+ * });
200
+ *
201
+ * console.log(result.exports); // Widget function
202
+ * ```
203
+ */
204
+ async function executeCode(code, context = {}) {
205
+ const consoleOutput = [];
206
+ // Build globals with console capture
207
+ const globals = buildGlobals(context);
208
+ // Add sandboxed console
209
+ globals['console'] = {
210
+ log: (...args) => {
211
+ consoleOutput.push(args.map(String).join(' '));
212
+ },
213
+ info: (...args) => {
214
+ consoleOutput.push(`[INFO] ${args.map(String).join(' ')}`);
215
+ },
216
+ warn: (...args) => {
217
+ consoleOutput.push(`[WARN] ${args.map(String).join(' ')}`);
218
+ },
219
+ error: (...args) => {
220
+ consoleOutput.push(`[ERROR] ${args.map(String).join(' ')}`);
221
+ },
222
+ debug: (...args) => {
223
+ consoleOutput.push(`[DEBUG] ${args.map(String).join(' ')}`);
224
+ },
225
+ trace: () => { },
226
+ dir: () => { },
227
+ table: () => { },
228
+ group: () => { },
229
+ groupEnd: () => { },
230
+ time: () => { },
231
+ timeEnd: () => { },
232
+ assert: () => { },
233
+ clear: () => { },
234
+ count: () => { },
235
+ countReset: () => { },
236
+ };
237
+ // Add require function
238
+ globals['require'] = buildRequireFunction(context);
239
+ // Create enclave with options
240
+ const enclave = new enclave_vm_1.Enclave({
241
+ ...DEFAULT_ENCLAVE_OPTIONS,
242
+ timeout: context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout,
243
+ maxIterations: context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations,
244
+ securityLevel: mapSecurityLevel(context.security),
245
+ globals,
246
+ allowFunctionsInGlobals: true, // Required for React components
247
+ });
248
+ try {
249
+ // Wrap code in module pattern to match CommonJS behavior
250
+ const wrappedCode = `
251
+ const module = { exports: {} };
252
+ const exports = module.exports;
253
+ const __filename = 'widget.js';
254
+ const __dirname = '/';
255
+ ${code}
256
+ return module.exports;
257
+ `;
258
+ const result = await enclave.run(wrappedCode);
259
+ if (!result.success) {
260
+ const errorMessage = result.error?.message ?? 'Execution failed';
261
+ const errorCode = result.error?.code;
262
+ // Map enclave error codes to descriptive messages
263
+ if (errorCode === 'TIMEOUT') {
264
+ throw new ExecutionError(`Execution timed out after ${context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout}ms`, {
265
+ code: 'TIMEOUT',
266
+ });
267
+ }
268
+ if (errorCode === 'MAX_ITERATIONS') {
269
+ throw new ExecutionError(`Maximum iterations exceeded (${context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations})`, {
270
+ code: 'MAX_ITERATIONS',
271
+ });
272
+ }
273
+ if (errorCode === 'VALIDATION_ERROR') {
274
+ throw new ExecutionError(`Security validation failed: ${errorMessage}`, { code: 'SECURITY_VIOLATION' });
275
+ }
276
+ throw new ExecutionError(errorMessage, result.error);
277
+ }
278
+ return {
279
+ exports: result.value,
280
+ executionTime: result.stats.duration,
281
+ consoleOutput: consoleOutput.length > 0 ? consoleOutput : undefined,
282
+ };
283
+ }
284
+ finally {
285
+ enclave.dispose();
286
+ }
287
+ }
288
+ /**
289
+ * Execute bundled code and extract the default export.
290
+ *
291
+ * Convenience wrapper around executeCode that extracts
292
+ * the default export.
293
+ *
294
+ * @param code - Bundled JavaScript code
295
+ * @param context - Execution context
296
+ * @returns Default export from the code
297
+ */
298
+ async function executeDefault(code, context = {}) {
299
+ const result = await executeCode(code, context);
300
+ // Check for default export
301
+ if ('default' in result.exports) {
302
+ return result.exports.default;
303
+ }
304
+ // Check for named exports
305
+ const exportKeys = Object.keys(result.exports);
306
+ // Handle empty exports - throw error as code should export something
307
+ if (exportKeys.length === 0) {
308
+ throw new ExecutionError('Code did not export any values');
309
+ }
310
+ // If only one named export, return it as the default
311
+ if (exportKeys.length === 1) {
312
+ return result.exports[exportKeys[0]];
313
+ }
314
+ // Multiple exports - return the whole exports object
315
+ return result.exports;
316
+ }
317
+ /**
318
+ * Error thrown during code execution.
319
+ */
320
+ class ExecutionError extends Error {
321
+ /** Error code for categorization */
322
+ code;
323
+ constructor(message, cause) {
324
+ super(message, { cause });
325
+ this.name = 'ExecutionError';
326
+ // Extract code from cause if present
327
+ if (cause && typeof cause === 'object' && 'code' in cause) {
328
+ this.code = cause.code;
329
+ }
330
+ }
331
+ }
332
+ exports.ExecutionError = ExecutionError;
333
+ /**
334
+ * Check if an error is an ExecutionError.
335
+ */
336
+ function isExecutionError(error) {
337
+ return error instanceof ExecutionError;
338
+ }
339
+ //# sourceMappingURL=enclave-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enclave-adapter.js","sourceRoot":"","sources":["../../../../src/bundler/sandbox/enclave-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AA6RH,kCAkGC;AAYD,wCAuBC;AAuBD,4CAEC;AAzbD,2CAAoF;AAiEpF;;GAEG;AACH,MAAM,uBAAuB,GAAkC;IAC7D,aAAa,EAAE,QAAQ;IACvB,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,KAAK;IACpB,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,yCAAyC,GAAG,EAAE,CAAC;AAErD;;GAEG;AACH,SAAS,gBAAgB,CAAC,MAAuB;IAC/C,4EAA4E;IAC5E,IAAI,MAAM,EAAE,cAAc,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,GAAG,yCAAyC,EAAE,CAAC;QACvG,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,oCAAoC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAc;IACtC,MAAM,CAAC,GAAG,KAGT,CAAC;IAEF,OAAO;QACL,GAAG,EAAE,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Ae;QAC1C,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAE7B,qCAAqC;QACrC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;YAC1D,IAAI,CAAC,IAAI,GAAI,KAA0B,CAAC,IAAI,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AAbD,wCAaC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,CAAC;AACzC,CAAC","sourcesContent":["/**\n * Enclave-VM Secure Code Executor\n *\n * Executes bundled code in a secure sandbox using enclave-vm.\n * Provides defense-in-depth security with:\n * - AST-based validation (81+ blocked attack vectors)\n * - Timeout enforcement (default 5000ms)\n * - Resource limits (maxIterations, maxToolCalls)\n * - Six security layers\n *\n * @packageDocumentation\n */\n\nimport { Enclave, type CreateEnclaveOptions, type SecurityLevel } from 'enclave-vm';\nimport type { SecurityPolicy } from '../types';\n\n/**\n * Context for code execution.\n */\nexport interface ExecutionContext {\n /**\n * React module to inject.\n */\n React?: unknown;\n\n /**\n * ReactDOM module to inject.\n */\n ReactDOM?: unknown;\n\n /**\n * Additional modules to inject.\n */\n modules?: Record<string, unknown>;\n\n /**\n * Additional global variables.\n */\n globals?: Record<string, unknown>;\n\n /**\n * Security policy to enforce.\n */\n security?: SecurityPolicy;\n\n /**\n * Execution timeout in milliseconds.\n * @default 5000\n */\n timeout?: number;\n\n /**\n * Maximum loop iterations allowed.\n * @default 10000\n */\n maxIterations?: number;\n}\n\n/**\n * Result of code execution.\n */\nexport interface ExecutionResult<T = unknown> {\n /**\n * Exported value from the code.\n */\n exports: T;\n\n /**\n * Execution time in ms.\n */\n executionTime: number;\n\n /**\n * Console output captured during execution.\n */\n consoleOutput?: string[];\n}\n\n/**\n * Default enclave options for secure widget execution.\n */\nconst DEFAULT_ENCLAVE_OPTIONS: Partial<CreateEnclaveOptions> = {\n securityLevel: 'SECURE',\n timeout: 5000,\n maxIterations: 10000,\n validate: true,\n transform: true,\n};\n\n/**\n * Threshold of blocked imports that triggers STRICT security level.\n * When a SecurityPolicy blocks more than this many imports, we escalate to STRICT.\n */\nconst STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD = 10;\n\n/**\n * Map SecurityPolicy to enclave-vm security level.\n */\nfunction mapSecurityLevel(policy?: SecurityPolicy): SecurityLevel {\n // If policy has specific blockedImports or restrictive settings, use STRICT\n if (policy?.blockedImports && policy.blockedImports.length > STRICT_SECURITY_BLOCKED_IMPORTS_THRESHOLD) {\n return 'STRICT';\n }\n // Default to SECURE for widget code\n return 'SECURE';\n}\n\n/**\n * Create a minimal JSX runtime from React.\n */\nfunction createJSXRuntime(React: unknown): Record<string, unknown> {\n const R = React as {\n createElement: (...args: unknown[]) => unknown;\n Fragment: unknown;\n };\n\n return {\n jsx: (type: unknown, props: Record<string, unknown>, key?: string) => {\n const { children, ...rest } = props;\n return R.createElement(type, key ? { ...rest, key } : rest, children);\n },\n jsxs: (type: unknown, props: Record<string, unknown>, key?: string) => {\n const { children, ...rest } = props;\n return R.createElement(type, key ? { ...rest, key } : rest, children);\n },\n jsxDEV: (\n type: unknown,\n props: Record<string, unknown>,\n key: string | undefined,\n _isStaticChildren: boolean,\n _source: unknown,\n _self: unknown,\n ) => {\n const { children, ...rest } = props;\n return R.createElement(type, key ? { ...rest, key } : rest, children);\n },\n Fragment: R.Fragment,\n };\n}\n\n/**\n * Dangerous global keys that should never be injected from user context.\n * These could potentially bypass enclave security if allowed.\n */\nconst DANGEROUS_GLOBAL_KEYS = new Set([\n 'process',\n 'require',\n '__dirname',\n '__filename',\n 'Buffer',\n 'eval',\n 'Function',\n 'constructor',\n 'global',\n 'globalThis',\n 'module',\n 'exports',\n '__proto__',\n]);\n\n/**\n * Sanitize a key for use as a global variable name.\n * Replaces non-alphanumeric characters (except _ and $) with underscores.\n */\nfunction sanitizeGlobalKey(key: string): string {\n return key.replace(/[^a-zA-Z0-9_$]/g, '_');\n}\n\n/**\n * Build globals object from execution context.\n */\nfunction buildGlobals(context: ExecutionContext): Record<string, unknown> {\n const globals: Record<string, unknown> = {};\n\n // Add React and ReactDOM if provided\n if (context.React) {\n globals['React'] = context.React;\n }\n if (context.ReactDOM) {\n globals['ReactDOM'] = context.ReactDOM;\n }\n\n // Add JSX runtime if React is available\n if (context.React) {\n const jsxRuntime = createJSXRuntime(context.React);\n globals['__jsx'] = jsxRuntime['jsx'];\n globals['__jsxs'] = jsxRuntime['jsxs'];\n globals['__jsxDEV'] = jsxRuntime['jsxDEV'];\n globals['Fragment'] = jsxRuntime['Fragment'];\n }\n\n // Add modules as globals (enclave-vm handles require internally)\n if (context.modules) {\n for (const [key, value] of Object.entries(context.modules)) {\n // Sanitize key and make modules accessible as globals\n const sanitizedKey = sanitizeGlobalKey(key);\n if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {\n throw new ExecutionError(\n `Dangerous module key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`,\n { code: 'SECURITY_VIOLATION' },\n );\n }\n globals[sanitizedKey] = value;\n }\n }\n\n // Add user globals with security filtering\n if (context.globals) {\n for (const [key, value] of Object.entries(context.globals)) {\n // Check for dangerous keys (both original and sanitized)\n if (DANGEROUS_GLOBAL_KEYS.has(key)) {\n throw new ExecutionError(`Dangerous global key '${key}' is not allowed in execution context`, {\n code: 'SECURITY_VIOLATION',\n });\n }\n // Sanitize the key for safe global variable naming\n const sanitizedKey = sanitizeGlobalKey(key);\n if (DANGEROUS_GLOBAL_KEYS.has(sanitizedKey)) {\n throw new ExecutionError(\n `Dangerous global key '${key}' (sanitized: '${sanitizedKey}') is not allowed in execution context`,\n { code: 'SECURITY_VIOLATION' },\n );\n }\n globals[sanitizedKey] = value;\n }\n }\n\n return globals;\n}\n\n/**\n * Build require function for module resolution.\n */\nfunction buildRequireFunction(context: ExecutionContext): (id: string) => unknown {\n // Normalize all context.modules keys to lowercase for consistent lookup\n const normalizedContextModules: Record<string, unknown> = {};\n if (context.modules) {\n for (const [key, value] of Object.entries(context.modules)) {\n normalizedContextModules[key.toLowerCase()] = value;\n }\n }\n\n const modules: Record<string, unknown> = {\n react: context.React,\n 'react-dom': context.ReactDOM,\n 'react/jsx-runtime': context.React ? createJSXRuntime(context.React) : undefined,\n 'react/jsx-dev-runtime': context.React ? createJSXRuntime(context.React) : undefined,\n ...normalizedContextModules,\n };\n\n return (id: string): unknown => {\n const normalizedId = id.toLowerCase();\n\n if (normalizedId in modules) {\n const mod = modules[normalizedId];\n if (mod === undefined) {\n throw new Error(`Module '${id}' is not available. Did you forget to provide it in the context?`);\n }\n return mod;\n }\n\n throw new Error(`Module '${id}' is not available in the sandbox environment`);\n };\n}\n\n/**\n * Execute bundled code in a secure enclave-vm sandbox.\n *\n * Provides a sandboxed execution context with:\n * - AST-based code validation (81+ attack vectors blocked)\n * - Timeout enforcement (default 5000ms)\n * - Resource limits (maxIterations)\n * - Six security layers (defense-in-depth)\n *\n * @param code - Bundled JavaScript code\n * @param context - Execution context\n * @returns Execution result with exports\n *\n * @example\n * ```typescript\n * const code = `\n * const React = require('react');\n * function Widget({ data }) {\n * return React.createElement('div', null, data.message);\n * }\n * module.exports = Widget;\n * `;\n *\n * const result = await executeCode(code, {\n * React: require('react'),\n * timeout: 3000,\n * });\n *\n * console.log(result.exports); // Widget function\n * ```\n */\nexport async function executeCode<T = unknown>(\n code: string,\n context: ExecutionContext = {},\n): Promise<ExecutionResult<T>> {\n const consoleOutput: string[] = [];\n\n // Build globals with console capture\n const globals = buildGlobals(context);\n\n // Add sandboxed console\n globals['console'] = {\n log: (...args: unknown[]) => {\n consoleOutput.push(args.map(String).join(' '));\n },\n info: (...args: unknown[]) => {\n consoleOutput.push(`[INFO] ${args.map(String).join(' ')}`);\n },\n warn: (...args: unknown[]) => {\n consoleOutput.push(`[WARN] ${args.map(String).join(' ')}`);\n },\n error: (...args: unknown[]) => {\n consoleOutput.push(`[ERROR] ${args.map(String).join(' ')}`);\n },\n debug: (...args: unknown[]) => {\n consoleOutput.push(`[DEBUG] ${args.map(String).join(' ')}`);\n },\n trace: () => {},\n dir: () => {},\n table: () => {},\n group: () => {},\n groupEnd: () => {},\n time: () => {},\n timeEnd: () => {},\n assert: () => {},\n clear: () => {},\n count: () => {},\n countReset: () => {},\n };\n\n // Add require function\n globals['require'] = buildRequireFunction(context);\n\n // Create enclave with options\n const enclave = new Enclave({\n ...DEFAULT_ENCLAVE_OPTIONS,\n timeout: context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout,\n maxIterations: context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations,\n securityLevel: mapSecurityLevel(context.security),\n globals,\n allowFunctionsInGlobals: true, // Required for React components\n });\n\n try {\n // Wrap code in module pattern to match CommonJS behavior\n const wrappedCode = `\n const module = { exports: {} };\n const exports = module.exports;\n const __filename = 'widget.js';\n const __dirname = '/';\n ${code}\n return module.exports;\n `;\n\n const result = await enclave.run<T>(wrappedCode);\n\n if (!result.success) {\n const errorMessage = result.error?.message ?? 'Execution failed';\n const errorCode = result.error?.code;\n\n // Map enclave error codes to descriptive messages\n if (errorCode === 'TIMEOUT') {\n throw new ExecutionError(`Execution timed out after ${context.timeout ?? DEFAULT_ENCLAVE_OPTIONS.timeout}ms`, {\n code: 'TIMEOUT',\n });\n }\n if (errorCode === 'MAX_ITERATIONS') {\n throw new ExecutionError(\n `Maximum iterations exceeded (${context.maxIterations ?? DEFAULT_ENCLAVE_OPTIONS.maxIterations})`,\n {\n code: 'MAX_ITERATIONS',\n },\n );\n }\n if (errorCode === 'VALIDATION_ERROR') {\n throw new ExecutionError(`Security validation failed: ${errorMessage}`, { code: 'SECURITY_VIOLATION' });\n }\n\n throw new ExecutionError(errorMessage, result.error);\n }\n\n return {\n exports: result.value as T,\n executionTime: result.stats.duration,\n consoleOutput: consoleOutput.length > 0 ? consoleOutput : undefined,\n };\n } finally {\n enclave.dispose();\n }\n}\n\n/**\n * Execute bundled code and extract the default export.\n *\n * Convenience wrapper around executeCode that extracts\n * the default export.\n *\n * @param code - Bundled JavaScript code\n * @param context - Execution context\n * @returns Default export from the code\n */\nexport async function executeDefault<T = unknown>(code: string, context: ExecutionContext = {}): Promise<T> {\n const result = await executeCode<{ default?: T } & Record<string, unknown>>(code, context);\n\n // Check for default export\n if ('default' in result.exports) {\n return result.exports.default as T;\n }\n\n // Check for named exports\n const exportKeys = Object.keys(result.exports);\n\n // Handle empty exports - throw error as code should export something\n if (exportKeys.length === 0) {\n throw new ExecutionError('Code did not export any values');\n }\n\n // If only one named export, return it as the default\n if (exportKeys.length === 1) {\n return result.exports[exportKeys[0]] as T;\n }\n\n // Multiple exports - return the whole exports object\n return result.exports as T;\n}\n\n/**\n * Error thrown during code execution.\n */\nexport class ExecutionError extends Error {\n /** Error code for categorization */\n code?: string;\n\n constructor(message: string, cause?: unknown) {\n super(message, { cause });\n this.name = 'ExecutionError';\n\n // Extract code from cause if present\n if (cause && typeof cause === 'object' && 'code' in cause) {\n this.code = (cause as { code: string }).code;\n }\n }\n}\n\n/**\n * Check if an error is an ExecutionError.\n */\nexport function isExecutionError(error: unknown): error is ExecutionError {\n return error instanceof ExecutionError;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Secure Code Executor
3
+ *
4
+ * Executes bundled code in a secure sandbox using enclave-vm.
5
+ * Provides defense-in-depth security with:
6
+ * - AST-based validation (81+ blocked attack vectors)
7
+ * - Timeout enforcement (default 5000ms)
8
+ * - Resource limits (maxIterations)
9
+ * - Six security layers
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ export { executeCode, executeDefault, ExecutionError, isExecutionError, type ExecutionContext, type ExecutionResult, } from './enclave-adapter';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Secure Code Executor
4
+ *
5
+ * Executes bundled code in a secure sandbox using enclave-vm.
6
+ * Provides defense-in-depth security with:
7
+ * - AST-based validation (81+ blocked attack vectors)
8
+ * - Timeout enforcement (default 5000ms)
9
+ * - Resource limits (maxIterations)
10
+ * - Six security layers
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isExecutionError = exports.ExecutionError = exports.executeDefault = exports.executeCode = void 0;
16
+ // Re-export everything from enclave-adapter
17
+ var enclave_adapter_1 = require("./enclave-adapter");
18
+ Object.defineProperty(exports, "executeCode", { enumerable: true, get: function () { return enclave_adapter_1.executeCode; } });
19
+ Object.defineProperty(exports, "executeDefault", { enumerable: true, get: function () { return enclave_adapter_1.executeDefault; } });
20
+ Object.defineProperty(exports, "ExecutionError", { enumerable: true, get: function () { return enclave_adapter_1.ExecutionError; } });
21
+ Object.defineProperty(exports, "isExecutionError", { enumerable: true, get: function () { return enclave_adapter_1.isExecutionError; } });
22
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../src/bundler/sandbox/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,4CAA4C;AAC5C,qDAO2B;AANzB,8GAAA,WAAW,OAAA;AACX,iHAAA,cAAc,OAAA;AACd,iHAAA,cAAc,OAAA;AACd,mHAAA,gBAAgB,OAAA","sourcesContent":["/**\n * Secure Code Executor\n *\n * Executes bundled code in a secure sandbox using enclave-vm.\n * Provides defense-in-depth security with:\n * - AST-based validation (81+ blocked attack vectors)\n * - Timeout enforcement (default 5000ms)\n * - Resource limits (maxIterations)\n * - Six security layers\n *\n * @packageDocumentation\n */\n\n// Re-export everything from enclave-adapter\nexport {\n executeCode,\n executeDefault,\n ExecutionError,\n isExecutionError,\n type ExecutionContext,\n type ExecutionResult,\n} from './enclave-adapter';\n"]}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Sandbox Security Policy
3
+ *
4
+ * Defines and validates security policies for bundler execution.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { SecurityPolicy, SecurityViolation } from '../types';
9
+ /**
10
+ * Validate source code against a security policy.
11
+ *
12
+ * @param source - Source code to validate
13
+ * @param policy - Security policy to enforce
14
+ * @returns Array of security violations (empty if valid)
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const violations = validateSource(code, DEFAULT_SECURITY_POLICY);
19
+ * if (violations.length > 0) {
20
+ * throw new Error(`Security violations: ${violations.map(v => v.message).join(', ')}`);
21
+ * }
22
+ * ```
23
+ */
24
+ export declare function validateSource(source: string, policy?: SecurityPolicy): SecurityViolation[];
25
+ /**
26
+ * Validate import statements against policy.
27
+ *
28
+ * @param source - Source code to check
29
+ * @param policy - Security policy
30
+ * @returns Array of import violations
31
+ */
32
+ export declare function validateImports(source: string, policy?: SecurityPolicy): SecurityViolation[];
33
+ /**
34
+ * Validate bundle size against policy.
35
+ *
36
+ * @param size - Bundle size in bytes
37
+ * @param policy - Security policy
38
+ * @returns Violation if size exceeds limit, undefined otherwise
39
+ */
40
+ export declare function validateSize(size: number, policy?: SecurityPolicy): SecurityViolation | undefined;
41
+ /**
42
+ * Create a merged security policy with defaults.
43
+ *
44
+ * @param userPolicy - User-provided policy overrides
45
+ * @returns Merged policy with defaults
46
+ */
47
+ export declare function mergePolicy(userPolicy?: Partial<SecurityPolicy>): SecurityPolicy;
48
+ /**
49
+ * Security error thrown when policy is violated.
50
+ */
51
+ export declare class SecurityError extends Error {
52
+ readonly violations: SecurityViolation[];
53
+ constructor(message: string, violations: SecurityViolation[]);
54
+ }
55
+ /**
56
+ * Throw if any violations exist.
57
+ *
58
+ * @param violations - Array of violations to check
59
+ * @throws SecurityError if violations exist
60
+ */
61
+ export declare function throwOnViolations(violations: SecurityViolation[]): void;