@apifuse/provider-sdk 2.2.0-beta.62 → 2.2.0-beta.64

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 (261) hide show
  1. package/AUTHORING.md +367 -9
  2. package/CHANGELOG.md +8 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1 -0
  5. package/bin/apifuse-check.ts +84 -2
  6. package/bin/apifuse-dev.ts +11 -31
  7. package/bin/apifuse-migrate-deployment.ts +200 -0
  8. package/bin/apifuse-pack-check.ts +11 -4
  9. package/bin/apifuse-pack-types.ts +187 -4
  10. package/bin/apifuse-record.ts +44 -32
  11. package/bin/apifuse-submit-check.ts +9 -5
  12. package/bin/apifuse-test.ts +3 -1
  13. package/dist/cli/commands.d.ts +1 -1
  14. package/dist/cli/commands.js +11 -0
  15. package/dist/cli/deployment-intent.d.ts +178 -0
  16. package/dist/cli/deployment-intent.js +277 -0
  17. package/dist/cli/migrate-deployment-intent.d.ts +132 -0
  18. package/dist/cli/migrate-deployment-intent.js +1552 -0
  19. package/dist/cli/migrate-provider-shape.d.ts +5 -1
  20. package/dist/cli/migrate-provider-shape.js +4 -2
  21. package/dist/cli/resolver-runtime.d.ts +21 -0
  22. package/dist/cli/resolver-runtime.js +31 -0
  23. package/dist/define.d.ts +3 -0
  24. package/dist/define.js +5 -0
  25. package/dist/dev.d.ts +3 -1
  26. package/dist/dev.js +6 -1
  27. package/dist/engine.d.ts +35 -1
  28. package/dist/engine.js +21 -2
  29. package/dist/error-resolution.d.ts +1 -0
  30. package/dist/error-resolution.js +54 -0
  31. package/dist/errors.d.ts +39 -1
  32. package/dist/errors.js +50 -0
  33. package/dist/handle-meta.d.ts +36 -1
  34. package/dist/handle-meta.js +16 -0
  35. package/dist/handle.d.ts +23 -5
  36. package/dist/handle.js +54 -8
  37. package/dist/health-scenario.d.ts +38 -0
  38. package/dist/i18n/error-messages.d.ts +86 -0
  39. package/dist/i18n/error-messages.js +192 -0
  40. package/dist/i18n/index.d.ts +1 -0
  41. package/dist/i18n/index.js +1 -0
  42. package/dist/i18n/keys.d.ts +12 -0
  43. package/dist/i18n/keys.js +76 -5
  44. package/dist/index.d.ts +11 -3
  45. package/dist/index.js +9 -1
  46. package/dist/lint.d.ts +15 -0
  47. package/dist/lint.js +469 -82
  48. package/dist/provider.d.ts +6 -6
  49. package/dist/provider.js +3 -3
  50. package/dist/runtime/browser-telemetry-binding.d.ts +5 -0
  51. package/dist/runtime/browser-telemetry-binding.js +83 -0
  52. package/dist/runtime/browser-telemetry.d.ts +76 -0
  53. package/dist/runtime/browser-telemetry.js +165 -0
  54. package/dist/runtime/browser.d.ts +3 -0
  55. package/dist/runtime/browser.js +208 -47
  56. package/dist/runtime/cache-telemetry.d.ts +71 -0
  57. package/dist/runtime/cache-telemetry.js +177 -0
  58. package/dist/runtime/cache.js +67 -7
  59. package/dist/runtime/capability-response.d.ts +3 -0
  60. package/dist/runtime/capability-response.js +56 -0
  61. package/dist/runtime/capability-telemetry.d.ts +46 -0
  62. package/dist/runtime/capability-telemetry.js +68 -0
  63. package/dist/runtime/diagnostic-env.d.ts +3 -0
  64. package/dist/runtime/diagnostic-env.js +10 -1
  65. package/dist/runtime/engine-mode.d.ts +74 -0
  66. package/dist/runtime/engine-mode.js +152 -0
  67. package/dist/runtime/handle.js +9 -1
  68. package/dist/runtime/http-telemetry-guard.d.ts +10 -0
  69. package/dist/runtime/http-telemetry-guard.js +62 -10
  70. package/dist/runtime/http.js +141 -35
  71. package/dist/runtime/instrumentation.js +92 -13
  72. package/dist/runtime/ocr-telemetry.d.ts +82 -0
  73. package/dist/runtime/ocr-telemetry.js +192 -0
  74. package/dist/runtime/ocr.js +35 -8
  75. package/dist/runtime/request-telemetry.d.ts +2 -0
  76. package/dist/runtime/request-telemetry.js +2 -1
  77. package/dist/runtime/resolver-runtime-options.d.ts +14 -0
  78. package/dist/runtime/resolver-runtime-options.js +33 -0
  79. package/dist/runtime/resolver-shared.d.ts +3 -2
  80. package/dist/runtime/resolver-shared.js +4 -4
  81. package/dist/runtime/resolver-telemetry.d.ts +1 -0
  82. package/dist/runtime/resolver-telemetry.js +1 -1
  83. package/dist/runtime/resolver-vendors/browser.d.ts +2 -0
  84. package/dist/runtime/resolver-vendors/browser.js +46 -0
  85. package/dist/runtime/resolver-vendors/hosts.d.ts +21 -0
  86. package/dist/runtime/resolver-vendors/hosts.js +35 -0
  87. package/dist/runtime/resolver-vendors/hypersolutions.js +2 -2
  88. package/dist/runtime/resolver-vendors/types.d.ts +5 -4
  89. package/dist/runtime/resolver.d.ts +4 -1
  90. package/dist/runtime/resolver.js +46 -13
  91. package/dist/runtime/state-telemetry.d.ts +79 -0
  92. package/dist/runtime/state-telemetry.js +194 -0
  93. package/dist/runtime/state.d.ts +3 -0
  94. package/dist/runtime/state.js +26 -7
  95. package/dist/runtime/stealth-cookies.d.ts +5 -1
  96. package/dist/runtime/stealth-cookies.js +21 -1
  97. package/dist/runtime/stealth-owned-headers.d.ts +26 -0
  98. package/dist/runtime/stealth-owned-headers.js +37 -0
  99. package/dist/runtime/stealth-telemetry.d.ts +92 -0
  100. package/dist/runtime/stealth-telemetry.js +179 -0
  101. package/dist/runtime/stealth.d.ts +4 -1
  102. package/dist/runtime/stealth.js +228 -85
  103. package/dist/runtime/stt-telemetry.d.ts +77 -0
  104. package/dist/runtime/stt-telemetry.js +176 -0
  105. package/dist/runtime/stt.js +15 -6
  106. package/dist/runtime-boundary-lint.d.ts +132 -0
  107. package/dist/runtime-boundary-lint.js +586 -0
  108. package/dist/server/error-stack-frames.d.ts +35 -0
  109. package/dist/server/error-stack-frames.js +219 -0
  110. package/dist/server/index.d.ts +7 -0
  111. package/dist/server/index.js +4 -0
  112. package/dist/server/sdk-version.d.ts +3 -0
  113. package/dist/server/sdk-version.js +19 -0
  114. package/dist/server/self-test.js +1 -18
  115. package/dist/server/sensitive-values.d.ts +1 -1
  116. package/dist/server/sensitive-values.js +9 -0
  117. package/dist/server/serve-implementation.d.ts +51 -2
  118. package/dist/server/serve-implementation.js +337 -90
  119. package/dist/server/types.d.ts +1 -0
  120. package/dist/server/types.js +7 -0
  121. package/dist/stateful/stateful-provider-owner-forwarder.js +22 -0
  122. package/dist/stateful/stateful-provider-runtime-context.d.ts +3 -0
  123. package/dist/stateful/stateful-provider-runtime-context.js +1 -0
  124. package/dist/types.d.ts +123 -1
  125. package/dist/typescript-module.d.ts +39 -0
  126. package/dist/typescript-module.js +72 -0
  127. package/package.json +6 -1
  128. package/src/cli/commands.ts +14 -0
  129. package/src/cli/deployment-intent.ts +364 -0
  130. package/src/cli/migrate-deployment-intent.ts +1908 -0
  131. package/src/cli/migrate-provider-shape.ts +10 -4
  132. package/src/cli/resolver-runtime.ts +72 -0
  133. package/src/define.ts +13 -0
  134. package/src/dev.ts +9 -2
  135. package/src/engine.ts +38 -2
  136. package/src/error-resolution.ts +58 -0
  137. package/src/errors.ts +77 -1
  138. package/src/handle-meta.ts +51 -1
  139. package/src/handle.ts +92 -10
  140. package/src/health-scenario.ts +38 -0
  141. package/src/i18n/error-messages.ts +255 -0
  142. package/src/i18n/index.ts +1 -0
  143. package/src/i18n/keys.ts +80 -6
  144. package/src/index.ts +86 -0
  145. package/src/lint.ts +604 -91
  146. package/src/provider.ts +12 -0
  147. package/src/runtime/browser-telemetry-binding.ts +92 -0
  148. package/src/runtime/browser-telemetry.ts +289 -0
  149. package/src/runtime/browser.ts +249 -65
  150. package/src/runtime/cache-telemetry.ts +247 -0
  151. package/src/runtime/cache.ts +68 -17
  152. package/src/runtime/capability-response.ts +53 -0
  153. package/src/runtime/capability-telemetry.ts +101 -0
  154. package/src/runtime/diagnostic-env.ts +11 -1
  155. package/src/runtime/engine-mode.ts +233 -0
  156. package/src/runtime/handle.ts +9 -1
  157. package/src/runtime/http-telemetry-guard.ts +66 -13
  158. package/src/runtime/http.ts +168 -37
  159. package/src/runtime/instrumentation.ts +105 -16
  160. package/src/runtime/ocr-telemetry.ts +308 -0
  161. package/src/runtime/ocr.ts +114 -74
  162. package/src/runtime/request-telemetry.ts +2 -1
  163. package/src/runtime/resolver-runtime-options.ts +50 -0
  164. package/src/runtime/resolver-shared.ts +9 -4
  165. package/src/runtime/resolver-telemetry.ts +1 -1
  166. package/src/runtime/resolver-vendors/browser.ts +65 -7
  167. package/src/runtime/resolver-vendors/hosts.ts +43 -0
  168. package/src/runtime/resolver-vendors/hypersolutions.ts +2 -2
  169. package/src/runtime/resolver-vendors/types.ts +5 -4
  170. package/src/runtime/resolver.ts +64 -21
  171. package/src/runtime/state-telemetry.ts +298 -0
  172. package/src/runtime/state.ts +46 -45
  173. package/src/runtime/stealth-cookies.ts +24 -1
  174. package/src/runtime/stealth-owned-headers.ts +41 -0
  175. package/src/runtime/stealth-telemetry.ts +304 -0
  176. package/src/runtime/stealth.ts +355 -150
  177. package/src/runtime/stt-telemetry.ts +282 -0
  178. package/src/runtime/stt.ts +93 -71
  179. package/src/runtime-boundary-lint.ts +703 -0
  180. package/src/server/error-stack-frames.ts +214 -0
  181. package/src/server/index.ts +53 -0
  182. package/src/server/sdk-version.ts +22 -0
  183. package/src/server/self-test.ts +1 -21
  184. package/src/server/sensitive-values.ts +14 -0
  185. package/src/server/serve-implementation.ts +569 -108
  186. package/src/server/types.ts +7 -0
  187. package/src/stateful/stateful-provider-owner-forwarder.ts +23 -0
  188. package/src/stateful/stateful-provider-runtime-context.ts +4 -0
  189. package/src/types.ts +128 -1
  190. package/src/typescript-module.ts +100 -0
  191. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +0 -6
  192. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +0 -3
  193. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +0 -10
  194. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-a.ts.txt +0 -3
  195. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-b.ts.txt +0 -3
  196. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-barrel.ts.txt +0 -2
  197. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-ambiguous-index.ts.txt +0 -3
  198. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-computed.ts.txt +0 -6
  199. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-a.ts.txt +0 -1
  200. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-b.ts.txt +0 -1
  201. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-cycle-index.ts.txt +0 -3
  202. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-barrel.ts.txt +0 -7
  203. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-catalog.ts.txt +0 -19
  204. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-docs.ts.txt +0 -6
  205. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-index.ts.txt +0 -3
  206. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-daiso-stores.ts.txt +0 -8
  207. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-indirect-config.ts.txt +0 -5
  208. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-nonstatic.ts.txt +0 -4
  209. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-package-index.ts.txt +0 -3
  210. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-index.ts.txt +0 -3
  211. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-leaf.ts.txt +0 -10
  212. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-one.ts.txt +0 -1
  213. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-reexport-two.ts.txt +0 -1
  214. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-index.ts.txt +0 -3
  215. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-one.ts.txt +0 -6
  216. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-composed-two.ts.txt +0 -6
  217. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-mixed-index.ts.txt +0 -14
  218. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-runtime-registry.ts.txt +0 -3
  219. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-barrel.ts.txt +0 -2
  220. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-index.ts.txt +0 -3
  221. package/src/cli/__tests__/fixtures/migrate-operation-declaration/discovery-star-package-leaf.ts.txt +0 -3
  222. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +0 -8
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +0 -15
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +0 -9
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-kebab-operation-id.ts.txt +0 -17
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +0 -5
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +0 -24
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +0 -16
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-snake-operation-id.ts.txt +0 -21
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-duplicate-provider.ts.txt +0 -11
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-id-unresolved.ts.txt +0 -7
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +0 -3
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-many.ts.txt +0 -18
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-one-to-one.ts.txt +0 -13
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +0 -31
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +0 -11
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +0 -11
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +0 -11
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +0 -21
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +0 -11
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +0 -14
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-en.json +0 -1
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ja.json +0 -1
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-canonical-ko.json +0 -1
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/locale-existing-operation-namespace-en.json +0 -8
  246. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +0 -7
  247. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +0 -6
  248. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +0 -7
  249. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +0 -6
  250. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-binding-ambiguous.ts.txt +0 -12
  251. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported-other.ts.txt +0 -7
  252. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-imported.ts.txt +0 -5
  253. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-key-ambiguous.ts.txt +0 -19
  254. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-shorthand.ts.txt +0 -9
  255. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-typed.ts.txt +0 -11
  256. package/src/cli/__tests__/fixtures/migrate-operation-declaration/registry-unrelated.ts.txt +0 -13
  257. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +0 -7
  258. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +0 -7
  259. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +0 -15
  260. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +0 -4
  261. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +0 -12
@@ -0,0 +1,214 @@
1
+ import { type DiagnosticRedactor, redactDiagnosticText } from "../runtime/diagnostic-redactor.js";
2
+
3
+ /**
4
+ * Bounded, whitelist-shaped stack frames for masked (>=500) provider failures.
5
+ *
6
+ * `sanitizeDiagnosticText` is a blacklist scrubber for free text: a V8/Bun
7
+ * frame such as `at inner (/srv/app/probe.ts:3:30)` comes out as
8
+ * `at inner ([REDACTED])`, and even a bare `serve-implementation.ts:2039:12`
9
+ * trips the opaque-token heuristics. Stack frames therefore never go through
10
+ * it. Instead each frame is parsed against a strict grammar and re-emitted
11
+ * from its parts only: an optional `async`/`new` marker, the function name
12
+ * (identifier characters only), the file *basename* (never a filesystem
13
+ * directory, URL, or drive letter) and the numeric line:column. The sole
14
+ * exception is an engine-internal location (`native`, or a `node:` module id
15
+ * of identifier-shaped segments), which is kept verbatim because it names no
16
+ * deployment path. Frames that do not fit the grammar (eval frames, frames
17
+ * without a location, oversized lines) are dropped rather than passed
18
+ * through.
19
+ */
20
+ export const MAX_PROVIDER_ERROR_STACK_FRAMES = 5;
21
+ const MAX_STACK_SCAN_CHARS = 16 * 1024;
22
+ const MAX_STACK_SCAN_LINES = 64;
23
+ const MAX_STACK_LINE_CHARS = 1024;
24
+
25
+ const FRAME_LINE = /^\s+at\s+(\S.*)$/;
26
+ const FRAME_MODIFIER = /^(async|new)\s+(.*)$/;
27
+ const FRAME_FUNCTION_NAME = /^[\w$.<>[\] #]{1,80}$/;
28
+ const FRAME_LOCATION = /^(.*):(\d{1,7}):(\d{1,7})$/;
29
+ const MAX_NODE_MODULE_ID_CHARS = 128;
30
+ // Engine-internal module ids only: `node:` plus `/`-separated identifier-shaped
31
+ // segments (`node:async_hooks`, `node:internal/process/task_queues`). Every
32
+ // segment must start with a letter or `_`, so `..` traversal and dotfile
33
+ // segments cannot ride through this branch.
34
+ const FRAME_NODE_MODULE = /^node:[A-Za-z_][\w.-]{0,40}(?:\/[A-Za-z_][\w.-]{0,40}){0,7}$/;
35
+ const FRAME_BASENAME = /^[\w.$-]{1,120}$/;
36
+ // A basename of dots only (`.`, `..`, `...`) names no file.
37
+ const FRAME_BASENAME_HAS_NAME = /[^.]/;
38
+
39
+ function parseFunctionName(raw: string): { modifier?: string; name?: string } | undefined {
40
+ let rest = raw.trim();
41
+ let modifier: string | undefined;
42
+ const modified = FRAME_MODIFIER.exec(rest);
43
+ if (modified) {
44
+ modifier = modified[1];
45
+ rest = modified[2].trim();
46
+ }
47
+ if (rest.length === 0) return { modifier };
48
+ if (!FRAME_FUNCTION_NAME.test(rest)) return undefined;
49
+ return { modifier, name: rest };
50
+ }
51
+
52
+ function parseLocation(raw: string): string | undefined {
53
+ if (/[\s()]/.test(raw)) return undefined;
54
+ const located = FRAME_LOCATION.exec(raw);
55
+ if (!located) return undefined;
56
+ const [, path, line, column] = located;
57
+ let file: string;
58
+ if (
59
+ path === "native" ||
60
+ (path.length <= MAX_NODE_MODULE_ID_CHARS && FRAME_NODE_MODULE.test(path))
61
+ ) {
62
+ // Not filesystem paths: engine-internal module ids carry no deployment
63
+ // information. This is the one branch that keeps a `/`, and the grammar
64
+ // above bounds it to identifier segments.
65
+ file = path;
66
+ } else {
67
+ const separator = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
68
+ const basename = separator >= 0 ? path.slice(separator + 1) : path;
69
+ if (!FRAME_BASENAME.test(basename)) return undefined;
70
+ // `.` and `..` pass the basename character class but name no file: they
71
+ // are the traversal tokens the grammar exists to exclude, so a path such
72
+ // as `/srv/app/..:1:1` must not be emitted as `..:1:1`.
73
+ if (!FRAME_BASENAME_HAS_NAME.test(basename)) return undefined;
74
+ file = basename;
75
+ }
76
+ return `${file}:${line}:${column}`;
77
+ }
78
+
79
+ /** Parses one `at ...` line into `[async |new ][fn ](basename:line:col)`, or undefined. */
80
+ export function parseProviderErrorStackFrame(line: string): string | undefined {
81
+ if (line.length > MAX_STACK_LINE_CHARS) return undefined;
82
+ const frame = FRAME_LINE.exec(line);
83
+ if (!frame) return undefined;
84
+ const rest = frame[1].trimEnd();
85
+
86
+ let functionPart: string;
87
+ let locationPart: string;
88
+ if (rest.endsWith(")")) {
89
+ const open = rest.lastIndexOf("(");
90
+ if (open < 0) return undefined;
91
+ functionPart = rest.slice(0, open);
92
+ locationPart = rest.slice(open + 1, -1);
93
+ } else {
94
+ // A frame with no parenthesized location still carries its `async`/`new`
95
+ // modifier inline (`at async file:///app/index.mjs:12:3`, emitted by V8
96
+ // for an anonymous async frame such as a module's top-level await).
97
+ // Split it off here: `parseLocation` rejects anything containing
98
+ // whitespace, so leaving it attached dropped the whole frame.
99
+ const modified = FRAME_MODIFIER.exec(rest);
100
+ functionPart = modified ? modified[1] : "";
101
+ locationPart = modified ? modified[2].trim() : rest;
102
+ }
103
+ // Eval frames nest parentheses inside the function part; never pass them through.
104
+ if (/[()]/.test(functionPart)) return undefined;
105
+
106
+ const location = parseLocation(locationPart);
107
+ if (!location) return undefined;
108
+ const fn = parseFunctionName(functionPart);
109
+ if (!fn) return undefined;
110
+
111
+ const prefix = [fn.modifier, fn.name].filter((part) => part !== undefined).join(" ");
112
+ return prefix.length > 0 ? `${prefix} (${location})` : `(${location})`;
113
+ }
114
+
115
+ // V8 (Node >= 21) installs `stack` as a shared native accessor pair on every
116
+ // Error instance; JSC (Bun) installs a data property. Capture the engine's own
117
+ // accessor once so a provider-defined accessor (a different function object) is
118
+ // still rejected while the engine's is trusted. The engine accessor itself can
119
+ // call a process-global `Error.prepareStackTrace` hook, a process-wide trust
120
+ // boundary this module cannot narrow: a provider that installs one already
121
+ // reshapes `stack` for every consumer, and the whitelist grammar below still
122
+ // bounds what the resulting text can carry.
123
+ const NATIVE_STACK_GETTER = Object.getOwnPropertyDescriptor(new Error(), "stack")?.get;
124
+
125
+ function readOwnStackString(error: unknown): string | undefined {
126
+ // Only engine-captured stacks: a thrown plain object is provider-authored text.
127
+ if (!(error instanceof Error)) return undefined;
128
+ try {
129
+ const descriptor = Object.getOwnPropertyDescriptor(error, "stack");
130
+ if (descriptor === undefined) return undefined;
131
+ let stack: unknown;
132
+ if (Object.hasOwn(descriptor, "value")) {
133
+ stack = descriptor.value;
134
+ } else if (
135
+ typeof NATIVE_STACK_GETTER === "function" &&
136
+ descriptor.get === NATIVE_STACK_GETTER
137
+ ) {
138
+ stack = Reflect.apply(NATIVE_STACK_GETTER, error, []);
139
+ } else {
140
+ // A provider-defined accessor must never run inside the logger.
141
+ return undefined;
142
+ }
143
+ return typeof stack === "string" ? stack : undefined;
144
+ } catch {
145
+ return undefined;
146
+ }
147
+ }
148
+
149
+ // Header shapes ahead of the frame block: `Name: message` (V8/JSC),
150
+ // `Name [CODE]: message` (node:assert), `Name` (empty message), or the bare
151
+ // message (Playwright rewrites `stack` as message-first). The message itself
152
+ // is matched verbatim, so anything before it must be a short name-like prefix.
153
+ const HEADER_NAME_PREFIX = /^(?:[\w$][\w$ .[\]-]{0,119}: )?$/;
154
+ const HEADER_NAME_ONLY = /^[\w$][\w$ .[\]-]{0,119}$/;
155
+
156
+ /**
157
+ * The frame block that follows the header, or undefined when the header does
158
+ * not embed the current `message` followed by a newline. Fail closed there: if
159
+ * `message` was mutated after the stack was formatted, the original message
160
+ * lines are still in the string and could be parsed as forged frames. (A
161
+ * mutation that truncates exactly at one of the message's own newlines is
162
+ * indistinguishable from the string alone; the whitelist grammar and the
163
+ * redactor still bound what such a line can carry.)
164
+ */
165
+ function frameBlock(stack: string, error: object): string | undefined {
166
+ let message: unknown;
167
+ try {
168
+ message = (error as { message?: unknown }).message;
169
+ } catch {
170
+ return undefined;
171
+ }
172
+ if (typeof message !== "string") return undefined;
173
+ if (message.length === 0) {
174
+ const newline = stack.indexOf("\n");
175
+ if (newline < 0 || !HEADER_NAME_ONLY.test(stack.slice(0, newline))) return undefined;
176
+ return stack.slice(newline + 1);
177
+ }
178
+ const at = stack.indexOf(`${message}\n`);
179
+ if (at < 0 || !HEADER_NAME_PREFIX.test(stack.slice(0, at))) return undefined;
180
+ return stack.slice(at + message.length + 1);
181
+ }
182
+
183
+ /**
184
+ * Up to {@link MAX_PROVIDER_ERROR_STACK_FRAMES} whitelist-shaped frames from
185
+ * `error.stack`, or undefined when nothing parses. For an engine-formatted
186
+ * stack the header (which embeds the current `message`) is located and
187
+ * stripped first, so a provider-controlled *message* containing newlines
188
+ * cannot inject frame-shaped text (no header match, no frames). A provider
189
+ * that overwrites `stack` or `name` outright can still put grammar-shaped
190
+ * frames in the record: the field is a diagnostic hint, not an attested
191
+ * location, and the whitelist plus the redactor bound what it can carry.
192
+ * Each emitted frame still passes
193
+ * through the request redactor so a registered secret that happens to appear
194
+ * in a function or file name is masked (fail-closed to `[REDACTION_FAILED]`).
195
+ */
196
+ export function providerErrorStackFrames(
197
+ error: unknown,
198
+ redact?: DiagnosticRedactor,
199
+ ): string[] | undefined {
200
+ const stack = readOwnStackString(error);
201
+ if (stack === undefined) return undefined;
202
+
203
+ const body = frameBlock(stack, error as object);
204
+ if (body === undefined) return undefined;
205
+
206
+ const frames: string[] = [];
207
+ const lines = body.slice(0, MAX_STACK_SCAN_CHARS).split("\n", MAX_STACK_SCAN_LINES);
208
+ for (const line of lines) {
209
+ if (frames.length >= MAX_PROVIDER_ERROR_STACK_FRAMES) break;
210
+ const frame = parseProviderErrorStackFrame(line);
211
+ if (frame !== undefined) frames.push(redactDiagnosticText(frame, redact));
212
+ }
213
+ return frames.length > 0 ? frames : undefined;
214
+ }
@@ -1,3 +1,5 @@
1
+ export type { ProviderLocaleCatalogMap } from "../i18n/catalog.js";
2
+ export type { ProviderLocale, ProviderLocaleCatalog } from "../i18n/keys.js";
1
3
  export type {
2
4
  ProxyCacheStatus,
3
5
  ProxyProtocol,
@@ -23,6 +25,19 @@ export {
23
25
  type TelemetryKey,
24
26
  type TenantNeutral,
25
27
  } from "../runtime/request-telemetry.js";
28
+ export {
29
+ OcrTelemetryCollector,
30
+ bindOcrTelemetry,
31
+ type OcrTelemetryBackend,
32
+ type OcrTelemetryEngine,
33
+ type OcrTelemetryErrorCode,
34
+ type OcrTelemetryEvent,
35
+ type OcrTelemetryModel,
36
+ type OcrTelemetryFinishReason,
37
+ type OcrTelemetryHeaderPayload,
38
+ type OcrTelemetryLogPayload,
39
+ type OcrTelemetrySink,
40
+ } from "../runtime/ocr-telemetry.js";
26
41
  export {
27
42
  ResolverTelemetryCollector,
28
43
  type ResolverAttemptSample,
@@ -43,8 +58,46 @@ export {
43
58
  type ResolverTelemetrySink,
44
59
  type ResolverVendorAttemptTelemetryEvent,
45
60
  } from "../runtime/resolver-telemetry.js";
61
+ export {
62
+ StealthTelemetryCollector,
63
+ type StealthTelemetryAttemptEvent,
64
+ type StealthTelemetryAttemptKind,
65
+ type StealthTelemetryAttemptSample,
66
+ type StealthTelemetryDiagnostics,
67
+ type StealthTelemetryErrorCode,
68
+ type StealthTelemetryHeaderPayload,
69
+ type StealthTelemetryLogPayload,
70
+ type StealthTelemetryRequestClass,
71
+ type StealthTelemetrySbsdEvent,
72
+ type StealthTelemetrySbsdOutcome,
73
+ type StealthTelemetrySink,
74
+ } from "../runtime/stealth-telemetry.js";
75
+ export {
76
+ SttTelemetryCollector,
77
+ bindSttTelemetry,
78
+ type SttTelemetryBackend,
79
+ type SttTelemetryEngine,
80
+ type SttTelemetryErrorCode,
81
+ type SttTelemetryEvent,
82
+ type SttTelemetryModel,
83
+ type SttTelemetryHeaderPayload,
84
+ type SttTelemetryLogPayload,
85
+ type SttTelemetrySink,
86
+ } from "../runtime/stt-telemetry.js";
87
+
88
+ export {
89
+ BrowserTelemetryCollector,
90
+ type BrowserTelemetryErrorCode,
91
+ type BrowserTelemetryHeaderPayload,
92
+ type BrowserTelemetryLogPayload,
93
+ type BrowserTelemetryPoolAcquireOutcome,
94
+ type BrowserTelemetrySink,
95
+ type BrowserTelemetrySampleName,
96
+ type BrowserTelemetryEngine,
97
+ } from "../runtime/browser-telemetry.js";
46
98
  export type { ResolverVendorUnavailableReason } from "../runtime/resolver-vendors/types.js";
47
99
  export type { Span, TraceContext } from "../runtime/trace.js";
100
+ export type { StealthBrowser, StealthOS, StealthProfileDescriptor } from "../types.js";
48
101
  export {
49
102
  createServerApp,
50
103
  createServerAppAsync,
@@ -0,0 +1,22 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ /** Published @apifuse/provider-sdk version, read from the package manifest; "unknown" when unreadable. */
4
+ export function resolveSdkVersion(): string {
5
+ try {
6
+ const packageJsonUrl = new URL("../../package.json", import.meta.url);
7
+ const parsed: unknown = JSON.parse(readFileSync(packageJsonUrl, "utf8"));
8
+ if (
9
+ parsed &&
10
+ typeof parsed === "object" &&
11
+ "version" in parsed &&
12
+ typeof (parsed as { version: unknown }).version === "string"
13
+ ) {
14
+ return (parsed as { version: string }).version;
15
+ }
16
+ } catch {
17
+ // fall through to unknown
18
+ }
19
+ return "unknown";
20
+ }
21
+
22
+ export const SDK_VERSION = resolveSdkVersion();
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { readFileSync } from "node:fs";
3
2
 
4
3
  import { TURN_KINDS } from "../auth-turn/index.js";
4
+ import { SDK_VERSION } from "./sdk-version.js";
5
5
 
6
6
  import { type Context, Hono } from "hono";
7
7
  import { z } from "zod";
@@ -183,26 +183,6 @@ export interface SelfTestAppOptions {
183
183
  logger?: (event: SelfTestCancellationLogEvent) => void;
184
184
  }
185
185
 
186
- function resolveSdkVersion(): string {
187
- try {
188
- const packageJsonUrl = new URL("../../package.json", import.meta.url);
189
- const parsed: unknown = JSON.parse(readFileSync(packageJsonUrl, "utf8"));
190
- if (
191
- parsed &&
192
- typeof parsed === "object" &&
193
- "version" in parsed &&
194
- typeof (parsed as { version: unknown }).version === "string"
195
- ) {
196
- return (parsed as { version: string }).version;
197
- }
198
- } catch {
199
- // fall through to unknown
200
- }
201
- return "unknown";
202
- }
203
-
204
- const SDK_VERSION = resolveSdkVersion();
205
-
206
186
  type AnyHealthCheckSuite = HealthCheckSuite<unknown, unknown>;
207
187
  type AnyHealthCheckCase = HealthCheckCase<unknown, unknown>;
208
188
 
@@ -12,6 +12,10 @@ import {
12
12
  ENGINE_OWNED_PROXY_CREDENTIAL_ENV_NAMES,
13
13
  ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES,
14
14
  } from "../engine.js";
15
+ import {
16
+ REMOTE_ENGINE_CLIENT_API_KEY_ENV,
17
+ REMOTE_ENGINE_CLIENT_URL_ENV,
18
+ } from "../runtime/engine-mode.js";
15
19
  import { APIFUSE__CACHE__KEY_PEPPER_ENV } from "../runtime/cache.js";
16
20
  import { APIFUSE__ENGINE__CEREMONY_LEASE_KEY } from "../runtime/egress-lease.js";
17
21
  import {
@@ -45,6 +49,7 @@ export const DIAGNOSTIC_SENSITIVE_SOURCE_KINDS = [
45
49
  "engineProxyCredentials",
46
50
  "engineSolverKeys",
47
51
  "engineCeremonyLeaseCredentials",
52
+ "engineClientCredentials",
48
53
  "ocrCredentials",
49
54
  "sttCredentials",
50
55
  "cdpCredentials",
@@ -120,6 +125,15 @@ export function collectDiagnosticSensitiveValues(
120
125
  // These are the resolver-config API keys after #251's engine credential projection.
121
126
  engineSolverKeys: () => resolvedEnvValues(ENGINE_OWNED_RESOLVER_CREDENTIAL_ENV_NAMES),
122
127
  engineCeremonyLeaseCredentials: () => resolvedEnvValues([APIFUSE__ENGINE__CEREMONY_LEASE_KEY]),
128
+ // Remote engine client credential (projected before the ADR-0011 flip). The
129
+ // endpoint itself is an internal service URL, so only credentials embedded
130
+ // in it are inventoried, not the whole URL.
131
+ engineClientCredentials: () => [
132
+ ...resolvedEnvValues([REMOTE_ENGINE_CLIENT_API_KEY_ENV]),
133
+ ...resolvedStringVariants(env[REMOTE_ENGINE_CLIENT_URL_ENV]).flatMap((url) =>
134
+ urlCredentialComponents(url, { includePathAndQuery: false }),
135
+ ),
136
+ ],
123
137
  ocrCredentials: () =>
124
138
  resolvedEnvValues([APIFUSE__OCR__CLOUDFLARE_API_TOKEN_ENV, APIFUSE__OCR__API_KEY_ENV]),
125
139
  sttCredentials: () => resolvedEnvValues([APIFUSE__STT__CLOUDFLARE_API_TOKEN_ENV]),