@apifuse/provider-sdk 2.2.0-beta.4 → 2.2.0-beta.40

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 (303) hide show
  1. package/AUTHORING.md +501 -13
  2. package/CHANGELOG.md +165 -1
  3. package/README.md +72 -14
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +88 -4
  6. package/bin/apifuse-dev.ts +38 -5
  7. package/bin/apifuse-pack-check.ts +22 -2
  8. package/bin/apifuse-pack-smoke.ts +57 -2
  9. package/bin/apifuse-pack-types.ts +356 -38
  10. package/bin/apifuse-perf.ts +14 -13
  11. package/bin/apifuse-record.ts +691 -68
  12. package/bin/apifuse-submit-check.ts +518 -37
  13. package/bin/apifuse-sync-assets.ts +117 -0
  14. package/bin/submit-check-delimited-text.ts +50 -0
  15. package/dist/auth-turn/index.d.ts +3 -3
  16. package/dist/auth-turn/index.js +1 -1
  17. package/dist/auth.d.ts +14 -0
  18. package/dist/auth.js +67 -0
  19. package/dist/ceremonies/index.d.ts +16 -0
  20. package/dist/ceremonies/index.js +141 -36
  21. package/dist/cli/commands.d.ts +1 -1
  22. package/dist/cli/commands.js +8 -0
  23. package/dist/cli/create.d.ts +3 -0
  24. package/dist/cli/create.js +34 -35
  25. package/dist/cli/prompt-assets.d.ts +80 -0
  26. package/dist/cli/prompt-assets.js +743 -0
  27. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  28. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  29. package/dist/cli/templates/provider/README.md.tpl +4 -4
  30. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  31. package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -1
  32. package/dist/config/loader.d.ts +177 -16
  33. package/dist/config/loader.js +424 -127
  34. package/dist/contract-serialization.js +4 -8
  35. package/dist/contract-types.d.ts +1 -0
  36. package/dist/contract.js +2 -0
  37. package/dist/declaration-validation.d.ts +32 -0
  38. package/dist/declaration-validation.js +207 -0
  39. package/dist/define.d.ts +51 -25
  40. package/dist/define.js +752 -38
  41. package/dist/error-resolution.d.ts +4 -0
  42. package/dist/error-resolution.js +122 -0
  43. package/dist/errors.d.ts +18 -0
  44. package/dist/errors.js +40 -0
  45. package/dist/fixture-sanitization.d.ts +28 -0
  46. package/dist/fixture-sanitization.js +217 -0
  47. package/dist/health-scenario.d.ts +1842 -0
  48. package/dist/health-scenario.js +624 -0
  49. package/dist/index.d.ts +19 -9
  50. package/dist/index.js +10 -6
  51. package/dist/lint.d.ts +6 -1
  52. package/dist/lint.js +362 -3
  53. package/dist/native-address.d.ts +43 -0
  54. package/dist/native-address.js +281 -0
  55. package/dist/native-egress-policy.d.ts +31 -0
  56. package/dist/native-egress-policy.js +288 -0
  57. package/dist/observability.d.ts +5 -2
  58. package/dist/observability.js +48 -1
  59. package/dist/provider.d.ts +8 -2
  60. package/dist/provider.js +3 -1
  61. package/dist/runtime/auth-flow.d.ts +5 -1
  62. package/dist/runtime/auth-flow.js +6 -0
  63. package/dist/runtime/browser.d.ts +1 -0
  64. package/dist/runtime/browser.js +492 -49
  65. package/dist/runtime/cache.d.ts +1 -0
  66. package/dist/runtime/cache.js +169 -15
  67. package/dist/runtime/choice-wordlist.d.ts +9 -0
  68. package/dist/runtime/choice-wordlist.js +138 -0
  69. package/dist/runtime/choice.d.ts +13 -1
  70. package/dist/runtime/choice.js +490 -102
  71. package/dist/runtime/executor.d.ts +2 -2
  72. package/dist/runtime/executor.js +26 -2
  73. package/dist/runtime/http.d.ts +1 -0
  74. package/dist/runtime/http.js +515 -53
  75. package/dist/runtime/instrumentation.d.ts +2 -2
  76. package/dist/runtime/instrumentation.js +366 -8
  77. package/dist/runtime/native-network-errors.d.ts +33 -0
  78. package/dist/runtime/native-network-errors.js +69 -0
  79. package/dist/runtime/native-network.d.ts +96 -0
  80. package/dist/runtime/native-network.js +1232 -0
  81. package/dist/runtime/ocr.d.ts +29 -0
  82. package/dist/runtime/ocr.js +440 -0
  83. package/dist/runtime/proxy-errors.js +6 -2
  84. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  85. package/dist/runtime/proxy-nodemaven.js +146 -0
  86. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  87. package/dist/runtime/proxy-telemetry.js +154 -47
  88. package/dist/runtime/redirects.d.ts +29 -0
  89. package/dist/runtime/redirects.js +36 -0
  90. package/dist/runtime/redis.d.ts +1 -1
  91. package/dist/runtime/redis.js +4 -2
  92. package/dist/runtime/request-options.d.ts +68 -1
  93. package/dist/runtime/request-options.js +548 -0
  94. package/dist/runtime/resolver-config.d.ts +6 -0
  95. package/dist/runtime/resolver-config.js +6 -0
  96. package/dist/runtime/resolver-public.d.ts +1 -0
  97. package/dist/runtime/resolver-public.js +1 -0
  98. package/dist/runtime/resolver-shared.d.ts +3 -0
  99. package/dist/runtime/resolver-shared.js +12 -0
  100. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  101. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  102. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  103. package/dist/runtime/resolver-vendors/browser.js +377 -0
  104. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  105. package/dist/runtime/resolver-vendors/capsolver.js +526 -0
  106. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  107. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  108. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  109. package/dist/runtime/resolver-vendors/twocaptcha.js +407 -0
  110. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  111. package/dist/runtime/resolver-vendors/types.js +96 -0
  112. package/dist/runtime/resolver.d.ts +60 -0
  113. package/dist/runtime/resolver.js +737 -0
  114. package/dist/runtime/secrets.d.ts +27 -0
  115. package/dist/runtime/secrets.js +51 -0
  116. package/dist/runtime/state.d.ts +3 -0
  117. package/dist/runtime/state.js +277 -71
  118. package/dist/runtime/stealth-cookies.d.ts +20 -0
  119. package/dist/runtime/stealth-cookies.js +111 -0
  120. package/dist/runtime/stealth.d.ts +28 -3
  121. package/dist/runtime/stealth.js +519 -255
  122. package/dist/runtime/stt.js +1 -12
  123. package/dist/runtime/timeout.d.ts +5 -0
  124. package/dist/runtime/timeout.js +12 -0
  125. package/dist/runtime/trace-config.d.ts +12 -0
  126. package/dist/runtime/trace-config.js +61 -0
  127. package/dist/serve.d.ts +1 -1
  128. package/dist/serve.js +1 -1
  129. package/dist/server/index.d.ts +5 -3
  130. package/dist/server/index.js +3 -3
  131. package/dist/server/self-test-input-tokens.d.ts +2 -1
  132. package/dist/server/self-test-input-tokens.js +18 -14
  133. package/dist/server/self-test.d.ts +114 -0
  134. package/dist/server/self-test.js +784 -148
  135. package/dist/server/serve-implementation.d.ts +213 -0
  136. package/dist/server/serve-implementation.js +2173 -0
  137. package/dist/server/serve.d.ts +1 -70
  138. package/dist/server/serve.js +1 -1130
  139. package/dist/server/trace-output.d.ts +4 -0
  140. package/dist/server/trace-output.js +20 -0
  141. package/dist/server/types.d.ts +30 -5
  142. package/dist/server/types.js +13 -1
  143. package/dist/stateful/errors.d.ts +19 -0
  144. package/dist/stateful/errors.js +24 -0
  145. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  146. package/dist/stateful/http-provider-event-emitter.js +237 -0
  147. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  148. package/dist/stateful/http-session-owner-registry.js +210 -0
  149. package/dist/stateful/index.d.ts +18 -0
  150. package/dist/stateful/index.js +18 -0
  151. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  152. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  153. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  154. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  155. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  156. package/dist/stateful/provider-event-pipeline.js +1 -0
  157. package/dist/stateful/provider-events.d.ts +101 -0
  158. package/dist/stateful/provider-events.js +289 -0
  159. package/dist/stateful/session-key.d.ts +15 -0
  160. package/dist/stateful/session-key.js +86 -0
  161. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  162. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  163. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  164. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  165. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  166. package/dist/stateful/stateful-provider-adapter.js +287 -0
  167. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  168. package/dist/stateful/stateful-provider-observability.js +161 -0
  169. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  170. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  171. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  172. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  173. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  174. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  175. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  176. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  177. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  178. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  179. package/dist/stateful-signing.d.ts +18 -0
  180. package/dist/stateful-signing.js +27 -0
  181. package/dist/stealth/profiles.js +16 -7
  182. package/dist/stream-evidence.d.ts +74 -0
  183. package/dist/stream-evidence.js +785 -0
  184. package/dist/stream.js +7 -1
  185. package/dist/testing/index.d.ts +2 -1
  186. package/dist/testing/index.js +2 -1
  187. package/dist/testing/run.d.ts +32 -2
  188. package/dist/testing/run.js +489 -21
  189. package/dist/trace-sanitization.d.ts +5 -0
  190. package/dist/trace-sanitization.js +45 -0
  191. package/dist/types.d.ts +545 -23
  192. package/dist/types.js +1 -0
  193. package/package.json +44 -5
  194. package/src/auth-turn/index.ts +1 -1
  195. package/src/auth.ts +118 -0
  196. package/src/ceremonies/index.ts +189 -46
  197. package/src/cli/commands.ts +10 -0
  198. package/src/cli/create.ts +42 -35
  199. package/src/cli/prompt-assets.ts +865 -0
  200. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  201. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  202. package/src/cli/templates/provider/README.md.tpl +4 -4
  203. package/src/cli/templates/provider/index.ts.tpl +6 -3
  204. package/src/cli/templates/provider/operations/ping.ts.tpl +2 -1
  205. package/src/config/loader.ts +665 -163
  206. package/src/contract-serialization.ts +5 -7
  207. package/src/contract-types.ts +1 -0
  208. package/src/contract.ts +2 -0
  209. package/src/declaration-validation.ts +266 -0
  210. package/src/define.ts +970 -87
  211. package/src/error-resolution.ts +127 -0
  212. package/src/errors.ts +52 -0
  213. package/src/fixture-sanitization.ts +248 -0
  214. package/src/health-scenario.ts +875 -0
  215. package/src/index.ts +204 -8
  216. package/src/lint.ts +408 -4
  217. package/src/native-address.ts +340 -0
  218. package/src/native-egress-policy.ts +358 -0
  219. package/src/observability.ts +51 -1
  220. package/src/provider.ts +133 -0
  221. package/src/runtime/auth-flow.ts +12 -0
  222. package/src/runtime/browser.ts +661 -63
  223. package/src/runtime/cache.ts +189 -14
  224. package/src/runtime/choice-wordlist.ts +145 -0
  225. package/src/runtime/choice.ts +631 -120
  226. package/src/runtime/executor.ts +40 -7
  227. package/src/runtime/http.ts +641 -61
  228. package/src/runtime/instrumentation.ts +520 -15
  229. package/src/runtime/native-network-errors.ts +99 -0
  230. package/src/runtime/native-network.ts +1605 -0
  231. package/src/runtime/ocr.ts +523 -0
  232. package/src/runtime/proxy-errors.ts +12 -4
  233. package/src/runtime/proxy-nodemaven.ts +221 -0
  234. package/src/runtime/proxy-telemetry.ts +244 -75
  235. package/src/runtime/redirects.ts +66 -0
  236. package/src/runtime/redis.ts +7 -2
  237. package/src/runtime/request-options.ts +680 -1
  238. package/src/runtime/resolver-config.ts +6 -0
  239. package/src/runtime/resolver-public.ts +20 -0
  240. package/src/runtime/resolver-shared.ts +17 -0
  241. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  242. package/src/runtime/resolver-vendors/browser.ts +533 -0
  243. package/src/runtime/resolver-vendors/capsolver.ts +700 -0
  244. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  245. package/src/runtime/resolver-vendors/twocaptcha.ts +539 -0
  246. package/src/runtime/resolver-vendors/types.ts +212 -0
  247. package/src/runtime/resolver.ts +1103 -0
  248. package/src/runtime/secrets.ts +64 -0
  249. package/src/runtime/state.ts +394 -77
  250. package/src/runtime/stealth-cookies.ts +132 -0
  251. package/src/runtime/stealth.ts +675 -289
  252. package/src/runtime/stt.ts +1 -19
  253. package/src/runtime/timeout.ts +18 -0
  254. package/src/runtime/trace-config.ts +77 -0
  255. package/src/serve.ts +6 -1
  256. package/src/server/index.ts +37 -2
  257. package/src/server/self-test-input-tokens.ts +29 -14
  258. package/src/server/self-test.ts +1025 -175
  259. package/src/server/serve-implementation.ts +3250 -0
  260. package/src/server/serve.ts +1 -1626
  261. package/src/server/trace-output.ts +32 -0
  262. package/src/server/types.ts +13 -1
  263. package/src/stateful/README.md +146 -0
  264. package/src/stateful/errors.ts +35 -0
  265. package/src/stateful/http-provider-event-emitter.ts +314 -0
  266. package/src/stateful/http-session-owner-registry.ts +306 -0
  267. package/src/stateful/index.ts +18 -0
  268. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  269. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  270. package/src/stateful/provider-event-pipeline.ts +61 -0
  271. package/src/stateful/provider-events.ts +462 -0
  272. package/src/stateful/session-key.ts +111 -0
  273. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  274. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  275. package/src/stateful/stateful-provider-adapter.ts +562 -0
  276. package/src/stateful/stateful-provider-observability.ts +261 -0
  277. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  278. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  279. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  280. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  281. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  282. package/src/stateful-signing.ts +46 -0
  283. package/src/stealth/profiles.ts +17 -7
  284. package/src/stream-evidence.ts +988 -0
  285. package/src/stream.ts +8 -1
  286. package/src/testing/index.ts +10 -1
  287. package/src/testing/run.ts +658 -15
  288. package/src/trace-sanitization.ts +63 -0
  289. package/src/types.ts +660 -38
  290. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  291. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  292. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  293. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  294. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  295. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  296. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  297. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  298. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  299. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  300. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  301. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  302. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  303. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -2,7 +2,7 @@ import type { ProviderContext } from "../types.js";
2
2
  import { type CreateTraceContextOptions, type TraceContext } from "./trace.js";
3
3
  export interface InstrumentationOptions extends CreateTraceContextOptions {
4
4
  }
5
- export type InstrumentedProviderContext<T extends ProviderContext> = Omit<T, "trace"> & {
5
+ export type InstrumentedProviderContext<T extends Pick<ProviderContext, "trace">> = Omit<T, "trace"> & {
6
6
  trace: TraceContext;
7
7
  };
8
- export declare function wrapWithInstrumentation<T extends ProviderContext>(ctx: T, options?: InstrumentationOptions): InstrumentedProviderContext<T>;
8
+ export declare function wrapWithInstrumentation<T extends Pick<ProviderContext, "trace">>(ctx: T, options?: InstrumentationOptions): InstrumentedProviderContext<T>;
@@ -1,5 +1,14 @@
1
+ import { readableBytes, readableLines, readableTextChunks } from "../stream.js";
2
+ import { parseHttpRequestInvocation, isSensitiveKey, redactSensitiveError, redactSensitiveText, redactUrlQueryParams, requestOptionsFromHttpInvocation, serializeRequestUrl, } from "./request-options.js";
1
3
  import { createTraceContext, getTraceRecorder, } from "./trace.js";
4
+ import { RESOLVER_INSTRUMENTATION_METADATA } from "./resolver-shared.js";
2
5
  const BROWSER_PAGE_METHODS = new Set(["goto", "fill", "click", "type", "waitForSelector"]);
6
+ const DIAGNOSTIC_BASE_URL = "http://apifuse-instrumentation.invalid";
7
+ function isThenable(value) {
8
+ return ((typeof value === "object" || typeof value === "function") &&
9
+ value !== null &&
10
+ typeof value.then === "function");
11
+ }
3
12
  function getErrorStatus(error) {
4
13
  if (typeof error === "object" &&
5
14
  error !== null &&
@@ -46,8 +55,173 @@ function getUrl(namespace, args, result) {
46
55
  }
47
56
  return undefined;
48
57
  }
58
+ function requestOptionsForInvocation(namespace, methodName, args) {
59
+ if (namespace === "http") {
60
+ const invocation = parseHttpRequestInvocation(methodName, [...args]);
61
+ return invocation ? requestOptionsFromHttpInvocation(invocation) : undefined;
62
+ }
63
+ if (namespace !== "stealth" || methodName !== "fetch" || typeof args[0] !== "string") {
64
+ return undefined;
65
+ }
66
+ const options = args[1];
67
+ return options !== null && typeof options === "object" && !Array.isArray(options)
68
+ ? options
69
+ : undefined;
70
+ }
71
+ function fallbackSensitiveValues(options) {
72
+ const sensitiveParams = options?.sensitiveParams;
73
+ if (!sensitiveParams || typeof sensitiveParams !== "object")
74
+ return [];
75
+ return Object.values(sensitiveParams).map(String);
76
+ }
77
+ function stripDiagnosticBase(url) {
78
+ return url.startsWith(DIAGNOSTIC_BASE_URL) ? url.slice(DIAGNOSTIC_BASE_URL.length) || "/" : url;
79
+ }
80
+ function serializeDiagnosticUrl(url, options) {
81
+ try {
82
+ return {
83
+ degraded: false,
84
+ serializedUrl: serializeRequestUrl(url, options?.params, options?.sensitiveParams),
85
+ };
86
+ }
87
+ catch {
88
+ try {
89
+ const absoluteUrl = new URL(url, DIAGNOSTIC_BASE_URL).toString();
90
+ const serialized = serializeRequestUrl(absoluteUrl, options?.params, options?.sensitiveParams);
91
+ return {
92
+ degraded: false,
93
+ serializedUrl: {
94
+ requestUrl: stripDiagnosticBase(serialized.requestUrl),
95
+ redactedUrl: stripDiagnosticBase(serialized.redactedUrl),
96
+ sensitiveValues: serialized.sensitiveValues,
97
+ },
98
+ };
99
+ }
100
+ catch {
101
+ const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
102
+ const structural = redactUrlQueryParams(url, sensitiveParamNames);
103
+ return {
104
+ degraded: true,
105
+ serializedUrl: {
106
+ requestUrl: url,
107
+ redactedUrl: structural.redactedUrl,
108
+ sensitiveValues: [
109
+ ...new Set([...fallbackSensitiveValues(options), ...structural.sensitiveValues]),
110
+ ],
111
+ },
112
+ };
113
+ }
114
+ }
115
+ }
116
+ function snapshotRequestDiagnostics(namespace, methodName, args) {
117
+ const options = requestOptionsForInvocation(namespace, methodName, args);
118
+ const url = typeof args[0] === "string" ? args[0] : undefined;
119
+ const hasSensitiveParams = Boolean(options?.sensitiveParams && Object.keys(options.sensitiveParams).length > 0);
120
+ const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
121
+ const diagnosticUrl = hasSensitiveParams && url ? serializeDiagnosticUrl(url, options) : undefined;
122
+ const traceUrl = hasSensitiveParams && url
123
+ ? serializeDiagnosticUrl(url, { sensitiveParams: options?.sensitiveParams }).serializedUrl
124
+ .redactedUrl
125
+ : undefined;
126
+ return {
127
+ ...(diagnosticUrl?.degraded ? { diagnosticUrlDegraded: true } : {}),
128
+ ...(hasSensitiveParams ? { requestId: crypto.randomUUID() } : {}),
129
+ serializedUrl: diagnosticUrl?.serializedUrl,
130
+ sensitiveParamNames,
131
+ sensitiveValues: diagnosticUrl?.serializedUrl.sensitiveValues ?? fallbackSensitiveValues(options),
132
+ traceUrl,
133
+ };
134
+ }
135
+ function sanitizeRequestError(error, diagnostics) {
136
+ return redactSensitiveError(error, diagnostics.sensitiveValues, diagnostics.serializedUrl?.requestUrl, diagnostics.serializedUrl?.redactedUrl);
137
+ }
138
+ function isHttpStreamResponse(value) {
139
+ return (typeof value === "object" &&
140
+ value !== null &&
141
+ "body" in value &&
142
+ value.body instanceof ReadableStream);
143
+ }
144
+ function instrumentHttpStreamConsumption(value, recorder, args, diagnostics) {
145
+ const source = value.body;
146
+ let reader;
147
+ const body = new ReadableStream({
148
+ async pull(controller) {
149
+ try {
150
+ reader ??= source.getReader();
151
+ const chunk = await reader.read();
152
+ if (chunk.done) {
153
+ controller.close();
154
+ return;
155
+ }
156
+ controller.enqueue(chunk.value);
157
+ }
158
+ catch (error) {
159
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
160
+ try {
161
+ await recorder.runSpan("http.stream.consume", () => {
162
+ throw sanitizedError;
163
+ }, {
164
+ onError: (spanError) => buildSpanAttributes("http", "stream", args, undefined, spanError, diagnostics),
165
+ });
166
+ }
167
+ catch (recordedError) {
168
+ controller.error(recordedError);
169
+ }
170
+ }
171
+ },
172
+ async cancel(reason) {
173
+ try {
174
+ await (reader ? reader.cancel(reason) : source.cancel(reason));
175
+ }
176
+ catch (error) {
177
+ throw sanitizeRequestError(error, diagnostics);
178
+ }
179
+ },
180
+ }, { highWaterMark: 0 });
181
+ const instrumented = {
182
+ ...value,
183
+ body,
184
+ bytes: () => readableBytes(body),
185
+ textChunks: () => readableTextChunks(body),
186
+ lines: () => readableLines(body),
187
+ };
188
+ try {
189
+ Object.assign(value, instrumented);
190
+ return value;
191
+ }
192
+ catch {
193
+ return instrumented;
194
+ }
195
+ }
196
+ function isAsyncIterable(value) {
197
+ return (typeof value === "object" &&
198
+ value !== null &&
199
+ Symbol.asyncIterator in value &&
200
+ typeof value[Symbol.asyncIterator] === "function");
201
+ }
202
+ function instrumentHttpSseConsumption(value, recorder, args, diagnostics) {
203
+ const source = value;
204
+ return {
205
+ async *[Symbol.asyncIterator]() {
206
+ try {
207
+ for await (const event of source)
208
+ yield event;
209
+ }
210
+ catch (error) {
211
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
212
+ return await recorder.runSpan("http.sse.consume", () => {
213
+ throw sanitizedError;
214
+ }, {
215
+ onError: (spanError) => buildSpanAttributes("http", "sse", args, undefined, spanError, diagnostics),
216
+ });
217
+ }
218
+ },
219
+ };
220
+ }
49
221
  function getMethod(namespace, methodName, args) {
50
222
  if (namespace === "http") {
223
+ // Preserve the original instrumentation contract: generic entry points are
224
+ // reported as REQUEST/STREAM/SSE, independent of transport options.
51
225
  return methodName.toUpperCase();
52
226
  }
53
227
  if (namespace === "stealth") {
@@ -59,15 +233,23 @@ function getMethod(namespace, methodName, args) {
59
233
  }
60
234
  return undefined;
61
235
  }
62
- function buildSpanAttributes(namespace, methodName, args, result, error) {
236
+ function buildSpanAttributes(namespace, methodName, args, result, error, diagnostics = { sensitiveParamNames: [], sensitiveValues: [] }) {
63
237
  const attributes = {};
64
- const url = getUrl(namespace, args, result);
238
+ const rawUrl = getUrl(namespace, args, result);
239
+ const structuralUrl = diagnostics.traceUrl ?? rawUrl;
240
+ const url = structuralUrl
241
+ ? redactSensitiveText(structuralUrl, diagnostics.sensitiveValues, diagnostics.serializedUrl?.requestUrl, diagnostics.serializedUrl?.redactedUrl)
242
+ : undefined;
65
243
  const method = getMethod(namespace, methodName, args);
66
244
  const status = error ? getErrorStatus(error) : getResponseStatus(namespace, result);
67
245
  const duration = error ? undefined : getResponseDuration(result);
68
246
  if (url) {
69
247
  attributes.url = url;
70
248
  }
249
+ if (diagnostics.requestId)
250
+ attributes.request_id = diagnostics.requestId;
251
+ if (diagnostics.diagnosticUrlDegraded)
252
+ attributes.redaction_degraded = true;
71
253
  if (method) {
72
254
  attributes.method = method;
73
255
  }
@@ -86,6 +268,51 @@ function buildSpanAttributes(namespace, methodName, args, result, error) {
86
268
  }
87
269
  return attributes;
88
270
  }
271
+ function isStealthRedirectRunResult(value) {
272
+ return (typeof value === "object" &&
273
+ value !== null &&
274
+ "reason" in value &&
275
+ typeof value.reason === "string" &&
276
+ "hops" in value &&
277
+ Array.isArray(value.hops) &&
278
+ "final" in value &&
279
+ typeof value.final === "object" &&
280
+ value.final !== null);
281
+ }
282
+ function buildStealthRedirectAttributes(args, result, error, diagnostics) {
283
+ const attributes = buildSpanAttributes("stealth", "fetch", args, undefined, error, diagnostics);
284
+ if (!isStealthRedirectRunResult(result))
285
+ return attributes;
286
+ attributes.redirect_reason = result.reason;
287
+ attributes.redirect_hop_count = result.hops.length;
288
+ attributes.status = result.final.status;
289
+ if (result.hops.length > 0) {
290
+ const sensitiveValues = new Set(diagnostics.sensitiveValues);
291
+ const path = result.hops
292
+ .map((hop) => {
293
+ const hopUrl = hop.nextUrl ?? hop.url;
294
+ const responseSensitiveParamNames = [...queryParamNames(hopUrl)].filter(isSensitiveKey);
295
+ const structural = redactUrlQueryParams(hopUrl, [
296
+ ...new Set([...diagnostics.sensitiveParamNames, ...responseSensitiveParamNames]),
297
+ ]);
298
+ for (const value of structural.sensitiveValues)
299
+ sensitiveValues.add(value);
300
+ const safeUrl = redactSensitiveText(structural.redactedUrl, [...sensitiveValues]);
301
+ return `${hop.method} ${hop.status} ${safeUrl}`;
302
+ })
303
+ .join(" -> ");
304
+ attributes.redirect_path = redactSensitiveText(path, [...sensitiveValues], diagnostics.serializedUrl?.requestUrl, diagnostics.serializedUrl?.redactedUrl);
305
+ }
306
+ return attributes;
307
+ }
308
+ function queryParamNames(url) {
309
+ const queryStart = url.indexOf("?");
310
+ if (queryStart === -1)
311
+ return new Set();
312
+ const fragmentStart = url.indexOf("#", queryStart);
313
+ const query = url.slice(queryStart + 1, fragmentStart === -1 ? undefined : fragmentStart);
314
+ return new Set(new URLSearchParams(query).keys());
315
+ }
89
316
  function getBrowserPageAttributes(methodName, args, elapsedMs, error) {
90
317
  const attributes = {};
91
318
  if (methodName === "goto") {
@@ -146,18 +373,83 @@ function wrapPage(page, trace) {
146
373
  },
147
374
  });
148
375
  }
149
- function wrapNamespace(namespace, target, trace) {
376
+ function wrapStealthRedirects(redirects, trace) {
377
+ const recorder = getTraceRecorder(trace);
378
+ if (!recorder)
379
+ return redirects;
380
+ return {
381
+ run(...args) {
382
+ const diagnosticArgs = [args[0].url, args[0]];
383
+ const diagnostics = snapshotRequestDiagnostics("stealth", "fetch", diagnosticArgs);
384
+ let result;
385
+ try {
386
+ result = redirects.run(...args);
387
+ }
388
+ catch (error) {
389
+ const sanitizedError = sanitizeRequestError(error, diagnostics);
390
+ recorder
391
+ .runSpan("stealth.redirects.run", () => {
392
+ throw sanitizedError;
393
+ }, {
394
+ onError: (spanError) => buildStealthRedirectAttributes(diagnosticArgs, undefined, spanError, diagnostics),
395
+ })
396
+ .catch(() => undefined);
397
+ throw sanitizedError;
398
+ }
399
+ const sanitizedResult = Promise.resolve(result).catch((error) => {
400
+ throw sanitizeRequestError(error, diagnostics);
401
+ });
402
+ return recorder.runSpan("stealth.redirects.run", () => sanitizedResult, {
403
+ onSuccess: (spanResult) => buildStealthRedirectAttributes(diagnosticArgs, spanResult, undefined, diagnostics),
404
+ onError: (error) => buildStealthRedirectAttributes(diagnosticArgs, undefined, error, diagnostics),
405
+ });
406
+ },
407
+ };
408
+ }
409
+ function wrapStealthSession(session, trace) {
410
+ const wrappedSession = wrapNamespace("stealth", session, trace);
411
+ const redirects = wrapStealthRedirects(session.redirects, trace);
412
+ return new Proxy(wrappedSession, {
413
+ get(target, property, receiver) {
414
+ return property === "redirects" ? redirects : Reflect.get(target, property, receiver);
415
+ },
416
+ });
417
+ }
418
+ function wrapNamespace(namespace, target, trace, shouldInstrument) {
150
419
  const recorder = getTraceRecorder(trace);
151
420
  if (!recorder) {
152
421
  return target;
153
422
  }
154
423
  const wrappedMethods = new Map();
424
+ const resolverMetadata = namespace === "resolver" ? { target, traceRecorder: recorder } : undefined;
155
425
  return new Proxy(target, {
156
426
  get(namespaceTarget, property, receiver) {
427
+ if (property === RESOLVER_INSTRUMENTATION_METADATA && resolverMetadata) {
428
+ return resolverMetadata;
429
+ }
157
430
  const value = Reflect.get(namespaceTarget, property, receiver);
158
431
  if (typeof value !== "function" || property === "constructor") {
159
432
  return value;
160
433
  }
434
+ if (namespace === "resolver" && property === "solve") {
435
+ if (wrappedMethods.has(property)) {
436
+ return wrappedMethods.get(property);
437
+ }
438
+ const wrapped = (...args) => {
439
+ const challenge = args[0];
440
+ const challengeKind = typeof challenge === "object" &&
441
+ challenge !== null &&
442
+ "kind" in challenge &&
443
+ typeof challenge.kind === "string"
444
+ ? challenge.kind
445
+ : undefined;
446
+ return recorder.runSpan("resolver.solve", () => Reflect.apply(value, namespaceTarget, [args[0], args[1], recorder]), {
447
+ attributes: challengeKind ? { challenge_kind: challengeKind } : undefined,
448
+ });
449
+ };
450
+ wrappedMethods.set(property, wrapped);
451
+ return wrapped;
452
+ }
161
453
  if (namespace === "browser" && property === "newPage") {
162
454
  if (wrappedMethods.has(property)) {
163
455
  return wrappedMethods.get(property);
@@ -214,10 +506,75 @@ function wrapNamespace(namespace, target, trace) {
214
506
  wrappedMethods.set(property, wrapped);
215
507
  return wrapped;
216
508
  }
217
- const wrapped = (...args) => recorder.runSpan(`${namespace}.${methodName}`, () => Reflect.apply(value, namespaceTarget, args), {
218
- onSuccess: (result) => buildSpanAttributes(namespace, methodName, args, result),
219
- onError: (error) => buildSpanAttributes(namespace, methodName, args, undefined, error),
220
- });
509
+ const wrapped = (...args) => {
510
+ if (shouldInstrument && !shouldInstrument(methodName, args)) {
511
+ return Reflect.apply(value, namespaceTarget, args);
512
+ }
513
+ const requestDiagnostics = snapshotRequestDiagnostics(namespace, methodName, args);
514
+ // Invoke first and decide by the RETURN VALUE. `runSpan` always
515
+ // returns a Promise, so unconditionally span-wrapping every member
516
+ // silently rewrote synchronous contracts: `ctx.state.namespace()`
517
+ // (a sync factory) came back as a Promise, and every method call on
518
+ // it threw a raw TypeError — surfaced in production as catchtable's
519
+ // deterministic CONFIRM_STATE_UNAVAILABLE on 2026-07-27 (and the
520
+ // 2026-07-22 reserve internal_error loop before it). Sync members
521
+ // keep their sync contract; only genuinely async operations are
522
+ // recorded as spans.
523
+ let result;
524
+ try {
525
+ result = Reflect.apply(value, namespaceTarget, args);
526
+ }
527
+ catch (error) {
528
+ const sanitizedError = sanitizeRequestError(error, requestDiagnostics);
529
+ // A promise-returning implementation may still throw
530
+ // SYNCHRONOUSLY during pre-flight validation. Preserve the
531
+ // synchronous throw contract, but keep recording the failure
532
+ // span (the pre-fidelity wrapper captured these).
533
+ recorder
534
+ .runSpan(`${namespace}.${methodName}`, () => {
535
+ throw sanitizedError;
536
+ }, {
537
+ onError: (spanError) => buildSpanAttributes(namespace, methodName, args, undefined, spanError, requestDiagnostics),
538
+ })
539
+ .catch(() => undefined);
540
+ throw sanitizedError;
541
+ }
542
+ if (!isThenable(result)) {
543
+ // The state namespace factory returns the object whose METHODS
544
+ // are the operations worth tracing — instrument that object so
545
+ // `state.get`/`state.compareAndSet`/… spans exist (they never
546
+ // could before: the factory's return value was destroyed).
547
+ if (namespace === "state" &&
548
+ methodName === "namespace" &&
549
+ typeof result === "object" &&
550
+ result !== null) {
551
+ return wrapNamespace(namespace, result, trace);
552
+ }
553
+ if (namespace === "stealth" &&
554
+ methodName === "createSession" &&
555
+ typeof result === "object" &&
556
+ result !== null) {
557
+ return wrapStealthSession(result, trace);
558
+ }
559
+ return result;
560
+ }
561
+ const sanitizedResult = Promise.resolve(result).catch((error) => {
562
+ throw sanitizeRequestError(error, requestDiagnostics);
563
+ });
564
+ const tracedResult = recorder.runSpan(`${namespace}.${methodName}`, () => sanitizedResult, {
565
+ onSuccess: (spanResult) => buildSpanAttributes(namespace, methodName, args, spanResult, undefined, requestDiagnostics),
566
+ onError: (error) => buildSpanAttributes(namespace, methodName, args, undefined, error, requestDiagnostics),
567
+ });
568
+ return namespace === "http" && methodName === "stream"
569
+ ? tracedResult.then((spanResult) => isHttpStreamResponse(spanResult)
570
+ ? instrumentHttpStreamConsumption(spanResult, recorder, args, requestDiagnostics)
571
+ : spanResult)
572
+ : namespace === "http" && methodName === "sse"
573
+ ? tracedResult.then((spanResult) => isAsyncIterable(spanResult)
574
+ ? instrumentHttpSseConsumption(spanResult, recorder, args, requestDiagnostics)
575
+ : spanResult)
576
+ : tracedResult;
577
+ };
221
578
  wrappedMethods.set(property, wrapped);
222
579
  return wrapped;
223
580
  },
@@ -240,7 +597,8 @@ export function wrapWithInstrumentation(ctx, options = {}) {
240
597
  property === "stealth" ||
241
598
  property === "browser" ||
242
599
  property === "session" ||
243
- property === "state") {
600
+ property === "state" ||
601
+ property === "resolver") {
244
602
  const namespace = property;
245
603
  if (wrappedTargets.has(namespace)) {
246
604
  return wrappedTargets.get(namespace);
@@ -0,0 +1,33 @@
1
+ import { TransportError } from "../errors.js";
2
+ export type NativeNetworkErrorCode = "native_connection_aborted" | "native_connection_closed" | "native_connection_failed" | "native_connection_idle_timeout" | "native_connection_timeout" | "native_egress_authorization_failed" | "native_egress_grant_expired" | "native_egress_grant_invalid" | "native_egress_grant_limit_exceeded" | "native_egress_input_invalid" | "native_egress_not_declared" | "native_egress_policy_invalid" | "native_dynamic_egress_unsupported" | "native_proxy_expired" | "native_proxy_invalid";
3
+ export declare class NativeNetworkError extends TransportError {
4
+ constructor(message: string, code: NativeNetworkErrorCode, cause?: Error);
5
+ get code(): NativeNetworkErrorCode;
6
+ }
7
+ export declare function safeDiagnosticEgressHost(value: unknown): string;
8
+ export declare class NativeProxyExpiredError extends NativeNetworkError {
9
+ readonly expiresAt: string;
10
+ constructor(expiresAt: string);
11
+ }
12
+ /** Raised before transport setup when a native destination is not authorized. */
13
+ export declare class NativeEgressNotDeclaredError extends NativeNetworkError {
14
+ readonly port: number;
15
+ readonly tls: "required" | "disabled";
16
+ readonly host: string;
17
+ constructor(host: string, port: number, tls: "required" | "disabled");
18
+ }
19
+ /**
20
+ * Raised when the destination was authorized by a grant whose TTL elapsed and
21
+ * its expiry remains in the client's bounded recent-expiry evidence window.
22
+ */
23
+ export declare class NativeEgressGrantExpiredError extends NativeNetworkError {
24
+ readonly port: number;
25
+ readonly tls: "required" | "disabled";
26
+ readonly expiresAt: string;
27
+ readonly host: string;
28
+ constructor(host: string, port: number, tls: "required" | "disabled", expiresAt: string);
29
+ }
30
+ /** Raised when an established connection exceeds its opt-in read-idle window. */
31
+ export declare class NativeIdleTimeoutError extends NativeNetworkError {
32
+ constructor();
33
+ }
@@ -0,0 +1,69 @@
1
+ import { TransportError } from "../errors.js";
2
+ import { canonicalizeEgressHost } from "../native-address.js";
3
+ export class NativeNetworkError extends TransportError {
4
+ constructor(message, code, cause) {
5
+ const isEgressPolicyFailure = code.startsWith("native_egress_") || code === "native_dynamic_egress_unsupported";
6
+ super(message, {
7
+ code,
8
+ status: 0,
9
+ ...(cause ? { cause } : {}),
10
+ ...(isEgressPolicyFailure ? { category: "provider_error", retryable: false } : {}),
11
+ });
12
+ this.name = "NativeNetworkError";
13
+ }
14
+ get code() {
15
+ return super.code;
16
+ }
17
+ }
18
+ export function safeDiagnosticEgressHost(value) {
19
+ const canonical = canonicalizeEgressHost(value);
20
+ return canonical.ok ? canonical.host : `<invalid-host:${canonical.reason}>`;
21
+ }
22
+ export class NativeProxyExpiredError extends NativeNetworkError {
23
+ expiresAt;
24
+ constructor(expiresAt) {
25
+ super("Native connection closed at sticky proxy expiry", "native_proxy_expired");
26
+ this.expiresAt = expiresAt;
27
+ this.name = "NativeProxyExpiredError";
28
+ }
29
+ }
30
+ /** Raised before transport setup when a native destination is not authorized. */
31
+ export class NativeEgressNotDeclaredError extends NativeNetworkError {
32
+ port;
33
+ tls;
34
+ host;
35
+ constructor(host, port, tls) {
36
+ const diagnosticHost = safeDiagnosticEgressHost(host);
37
+ super(`Native ${tls === "required" ? "TLS" : "TCP"} egress is not declared for ${diagnosticHost}:${port}`, "native_egress_not_declared");
38
+ this.port = port;
39
+ this.tls = tls;
40
+ this.host = diagnosticHost;
41
+ this.name = "NativeEgressNotDeclaredError";
42
+ }
43
+ }
44
+ /**
45
+ * Raised when the destination was authorized by a grant whose TTL elapsed and
46
+ * its expiry remains in the client's bounded recent-expiry evidence window.
47
+ */
48
+ export class NativeEgressGrantExpiredError extends NativeNetworkError {
49
+ port;
50
+ tls;
51
+ expiresAt;
52
+ host;
53
+ constructor(host, port, tls, expiresAt) {
54
+ const diagnosticHost = safeDiagnosticEgressHost(host);
55
+ super(`Native ${tls === "required" ? "TLS" : "TCP"} egress grant expired for ${diagnosticHost}:${port}`, "native_egress_grant_expired");
56
+ this.port = port;
57
+ this.tls = tls;
58
+ this.expiresAt = expiresAt;
59
+ this.host = diagnosticHost;
60
+ this.name = "NativeEgressGrantExpiredError";
61
+ }
62
+ }
63
+ /** Raised when an established connection exceeds its opt-in read-idle window. */
64
+ export class NativeIdleTimeoutError extends NativeNetworkError {
65
+ constructor() {
66
+ super("Native network socket timed out while reading.", "native_connection_idle_timeout");
67
+ this.name = "NativeIdleTimeoutError";
68
+ }
69
+ }
@@ -0,0 +1,96 @@
1
+ import { Socket } from "node:net";
2
+ import { type TLSSocket } from "node:tls";
3
+ import { type ProxyProtocol } from "../config/loader.js";
4
+ import { type DynamicEgressRuleSnapshot } from "../native-egress-policy.js";
5
+ import type { NativeNetworkClient, NativeNetworkConnectInput, NativeNetworkConnection, NativeNetworkDynamicGrantOptions, NativeNetworkEgressGrant, NativeProviderConfig, NativeProxyEgressInfo, ProviderProxyPolicy, ProviderProxyProvider, EnvContext } from "../types.js";
6
+ export { NativeEgressGrantExpiredError, NativeEgressNotDeclaredError, NativeIdleTimeoutError, NativeNetworkError, NativeProxyExpiredError, } from "./native-network-errors.js";
7
+ export type { NativeNetworkErrorCode } from "./native-network-errors.js";
8
+ export type NativeGatewayProxy = NativeProxyEgressInfo & {
9
+ readonly url: string;
10
+ };
11
+ export type NativeGatewayProxySynthesisInput = {
12
+ readonly vendor: ProviderProxyProvider;
13
+ readonly policy: ProviderProxyPolicy;
14
+ readonly affinityKey?: string;
15
+ readonly now: number;
16
+ readonly protocol: ProxyProtocol;
17
+ readonly credentials: VendorCredentialResolver;
18
+ };
19
+ export type VendorCredentialLookup = {
20
+ readonly kind: "present";
21
+ readonly values: Readonly<Record<string, string>>;
22
+ } | {
23
+ readonly kind: "absent";
24
+ readonly missing: readonly string[];
25
+ };
26
+ export type VendorCredentialResolver = (vendor: ProviderProxyProvider) => VendorCredentialLookup;
27
+ export type NativeGatewayProxySkipReason = {
28
+ readonly kind: "credentials_absent";
29
+ readonly missing: readonly string[];
30
+ } | {
31
+ readonly kind: "protocol_unsupported";
32
+ readonly protocol: string;
33
+ } | {
34
+ readonly kind: "allocation_failed";
35
+ readonly cause: Error;
36
+ } | {
37
+ readonly kind: "credential_lookup_failed";
38
+ readonly cause: Error;
39
+ };
40
+ export type NativeGatewayProxySynthesisResult = NativeGatewayProxy | {
41
+ readonly kind: "skipped";
42
+ readonly reason: NativeGatewayProxySkipReason;
43
+ } | undefined;
44
+ /** A vendor adapter in the ordered native gateway resolution chain. */
45
+ export type NativeGatewayProxySynthesizer = (input: NativeGatewayProxySynthesisInput) => NativeGatewayProxySynthesisResult | Promise<NativeGatewayProxySynthesisResult>;
46
+ export type NativeGatewayProxyResolutionInput = {
47
+ readonly policy: ProviderProxyPolicy;
48
+ readonly affinityKey?: string;
49
+ readonly now?: number;
50
+ readonly protocol?: ProxyProtocol;
51
+ readonly credentials?: VendorCredentialResolver;
52
+ readonly gatewaySynthesizers?: readonly NativeGatewayProxySynthesizer[];
53
+ };
54
+ export type NativeNetworkClientOptions = {
55
+ readonly proxyPolicy?: ProviderProxyPolicy;
56
+ readonly affinityKey?: string;
57
+ /** Stable credential/account identity; hashed before vendor synthesis. */
58
+ readonly credentialIdentity?: string;
59
+ /** Vendor credential lookup; defaults to the process EnvContext. */
60
+ readonly credentials?: VendorCredentialResolver;
61
+ /** Explicit CONNECT/SOCKS5 override; vendors otherwise choose their default. */
62
+ readonly proxyProtocol?: ProxyProtocol;
63
+ /** Vendor adapters in priority order within each policy vendor slot. */
64
+ readonly gatewaySynthesizers?: readonly NativeGatewayProxySynthesizer[];
65
+ /** Warning-level lifecycle diagnostic sink. */
66
+ readonly warn?: (message: string) => void;
67
+ /**
68
+ * Provider-declared native egress. Undefined preserves legacy unrestricted
69
+ * behavior; any provided declaration, including an empty object, is enforced.
70
+ */
71
+ readonly egress?: NonNullable<NativeProviderConfig["network"]>;
72
+ /** Additional deployment authorization layered on top of SDK enforcement. */
73
+ readonly grantTcpEgress?: (input: NativeNetworkDynamicGrantOptions) => NativeNetworkEgressGrant;
74
+ };
75
+ /** Build a resolver over the SDK's existing injectable environment context. */
76
+ export declare function createEnvVendorCredentialResolver(env?: EnvContext): VendorCredentialResolver;
77
+ /** Domain-separated, process-independent affinity derived from credential identity. */
78
+ export declare function deriveNativeCredentialAffinityKey(credentialIdentity: string): string;
79
+ /** Resolve the first configured native gateway, including allocation vendors. */
80
+ export declare function resolveNativeGatewayProxy(input: NativeGatewayProxyResolutionInput): Promise<NativeGatewayProxy | undefined>;
81
+ export declare function createNativeNetworkConnection(socket: Socket | TLSSocket, proxy: NativeGatewayProxy | undefined, options: NativeNetworkClientOptions, idleTimeoutMs?: number): NativeNetworkConnection;
82
+ type NativeConnectTls = "required" | "disabled";
83
+ export declare const NATIVE_EGRESS_EXPIRED_EVIDENCE_LIMIT = 256;
84
+ /** Internal validator-independent source selector matcher. */
85
+ export declare function matchesSourceHost(rule: DynamicEgressRuleSnapshot, host: string): boolean;
86
+ /** Internal canonical snapshot shared by production and SDK transport test doubles. */
87
+ export declare function snapshotNativeConnectInput(input: NativeNetworkConnectInput): NativeNetworkConnectInput;
88
+ /** Internal canonical snapshot shared by production and SDK transport test doubles. */
89
+ export declare function snapshotNativeGrantInput(input: NativeNetworkDynamicGrantOptions): NativeNetworkDynamicGrantOptions;
90
+ /** Internal authorization seam shared by production and SDK transport test doubles. */
91
+ export declare function createNativeEgressAuthorization(options: NativeNetworkClientOptions): {
92
+ assertConnect(input: NativeNetworkConnectInput, tls: NativeConnectTls): void;
93
+ grant(input: NativeNetworkDynamicGrantOptions): NativeNetworkEgressGrant;
94
+ };
95
+ /** Create the SDK byte-stream runtime with provider-declared egress enforcement. */
96
+ export declare function createNativeNetworkClient(options?: NativeNetworkClientOptions): NativeNetworkClient;