@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.51

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 (368) hide show
  1. package/AUTHORING.md +537 -33
  2. package/CHANGELOG.md +205 -1
  3. package/README.md +83 -22
  4. package/SUBMISSION.md +2 -2
  5. package/bin/apifuse-check.ts +165 -11
  6. package/bin/apifuse-dev.ts +57 -13
  7. package/bin/apifuse-migrate-operation-declaration.ts +55 -0
  8. package/bin/apifuse-migrate-shape.ts +202 -0
  9. package/bin/apifuse-pack-check.ts +22 -2
  10. package/bin/apifuse-pack-smoke.ts +57 -2
  11. package/bin/apifuse-pack-types.ts +357 -38
  12. package/bin/apifuse-perf.ts +14 -13
  13. package/bin/apifuse-record.ts +709 -72
  14. package/bin/apifuse-submit-check.ts +2344 -324
  15. package/bin/apifuse-sync-assets.ts +117 -0
  16. package/bin/submit-check-delimited-text.ts +50 -0
  17. package/dist/auth-turn/index.d.ts +3 -3
  18. package/dist/auth-turn/index.js +1 -1
  19. package/dist/auth.d.ts +14 -0
  20. package/dist/auth.js +67 -0
  21. package/dist/ceremonies/index.d.ts +16 -0
  22. package/dist/ceremonies/index.js +141 -36
  23. package/dist/cli/commands.d.ts +1 -1
  24. package/dist/cli/commands.js +27 -0
  25. package/dist/cli/create.d.ts +4 -1
  26. package/dist/cli/create.js +42 -37
  27. package/dist/cli/migrate-operation-declaration.d.ts +59 -0
  28. package/dist/cli/migrate-operation-declaration.js +1249 -0
  29. package/dist/cli/migrate-operation-shape.d.ts +44 -0
  30. package/dist/cli/migrate-operation-shape.js +113 -0
  31. package/dist/cli/migrate-provider-shape.d.ts +52 -0
  32. package/dist/cli/migrate-provider-shape.js +578 -0
  33. package/dist/cli/prompt-assets.d.ts +80 -0
  34. package/dist/cli/prompt-assets.js +743 -0
  35. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  36. package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
  37. package/dist/cli/templates/provider/README.md.tpl +5 -5
  38. package/dist/cli/templates/provider/index.ts.tpl +6 -3
  39. package/dist/cli/templates/provider/operations/ping.ts.tpl +4 -1
  40. package/dist/cli/templates/provider/provider.json.tpl +6 -0
  41. package/dist/config/loader.d.ts +179 -16
  42. package/dist/config/loader.js +435 -127
  43. package/dist/contract-serialization.js +4 -8
  44. package/dist/contract-types.d.ts +12 -5
  45. package/dist/contract.js +24 -10
  46. package/dist/declaration-validation.d.ts +33 -0
  47. package/dist/declaration-validation.js +266 -0
  48. package/dist/define.d.ts +66 -29
  49. package/dist/define.js +778 -69
  50. package/dist/dev.d.ts +3 -0
  51. package/dist/dev.js +1 -1
  52. package/dist/engine.d.ts +78 -0
  53. package/dist/engine.js +133 -0
  54. package/dist/error-observability.d.ts +7 -0
  55. package/dist/error-observability.js +61 -0
  56. package/dist/error-resolution.d.ts +4 -0
  57. package/dist/error-resolution.js +122 -0
  58. package/dist/errors.d.ts +33 -0
  59. package/dist/errors.js +40 -0
  60. package/dist/fixture-sanitization.d.ts +28 -0
  61. package/dist/fixture-sanitization.js +227 -0
  62. package/dist/health-scenario.d.ts +1842 -0
  63. package/dist/health-scenario.js +624 -0
  64. package/dist/index.d.ts +21 -10
  65. package/dist/index.js +12 -7
  66. package/dist/lint.d.ts +23 -11
  67. package/dist/lint.js +572 -69
  68. package/dist/native-address.d.ts +43 -0
  69. package/dist/native-address.js +281 -0
  70. package/dist/native-egress-policy.d.ts +31 -0
  71. package/dist/native-egress-policy.js +288 -0
  72. package/dist/observability.d.ts +5 -2
  73. package/dist/observability.js +48 -1
  74. package/dist/provider.d.ts +10 -2
  75. package/dist/provider.js +4 -1
  76. package/dist/runtime/auth-flow.d.ts +5 -1
  77. package/dist/runtime/auth-flow.js +6 -0
  78. package/dist/runtime/browser.d.ts +1 -0
  79. package/dist/runtime/browser.js +492 -49
  80. package/dist/runtime/cache.d.ts +1 -0
  81. package/dist/runtime/cache.js +169 -15
  82. package/dist/runtime/choice-wordlist.d.ts +9 -0
  83. package/dist/runtime/choice-wordlist.js +138 -0
  84. package/dist/runtime/choice.d.ts +13 -1
  85. package/dist/runtime/choice.js +490 -102
  86. package/dist/runtime/chrome149-header-order.d.ts +58 -0
  87. package/dist/runtime/chrome149-header-order.js +289 -0
  88. package/dist/runtime/env.js +12 -0
  89. package/dist/runtime/executor.d.ts +3 -2
  90. package/dist/runtime/executor.js +26 -25
  91. package/dist/runtime/http.d.ts +1 -0
  92. package/dist/runtime/http.js +515 -53
  93. package/dist/runtime/insights.js +2 -2
  94. package/dist/runtime/instrumentation.d.ts +2 -2
  95. package/dist/runtime/instrumentation.js +366 -8
  96. package/dist/runtime/native-network-errors.d.ts +33 -0
  97. package/dist/runtime/native-network-errors.js +69 -0
  98. package/dist/runtime/native-network.d.ts +96 -0
  99. package/dist/runtime/native-network.js +1232 -0
  100. package/dist/runtime/ocr.d.ts +29 -0
  101. package/dist/runtime/ocr.js +440 -0
  102. package/dist/runtime/otlp.d.ts +71 -2
  103. package/dist/runtime/otlp.js +397 -16
  104. package/dist/runtime/proxy-errors.js +6 -2
  105. package/dist/runtime/proxy-nodemaven.d.ts +56 -0
  106. package/dist/runtime/proxy-nodemaven.js +146 -0
  107. package/dist/runtime/proxy-telemetry.d.ts +80 -1
  108. package/dist/runtime/proxy-telemetry.js +154 -47
  109. package/dist/runtime/redirects.d.ts +29 -0
  110. package/dist/runtime/redirects.js +36 -0
  111. package/dist/runtime/redis.d.ts +1 -1
  112. package/dist/runtime/redis.js +4 -2
  113. package/dist/runtime/request-options.d.ts +68 -1
  114. package/dist/runtime/request-options.js +548 -0
  115. package/dist/runtime/resolver-config.d.ts +6 -0
  116. package/dist/runtime/resolver-config.js +6 -0
  117. package/dist/runtime/resolver-public.d.ts +1 -0
  118. package/dist/runtime/resolver-public.js +1 -0
  119. package/dist/runtime/resolver-shared.d.ts +14 -0
  120. package/dist/runtime/resolver-shared.js +12 -0
  121. package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
  122. package/dist/runtime/resolver-vendors/bindings.js +40 -0
  123. package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
  124. package/dist/runtime/resolver-vendors/browser.js +377 -0
  125. package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
  126. package/dist/runtime/resolver-vendors/capsolver.js +531 -0
  127. package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
  128. package/dist/runtime/resolver-vendors/hosts.js +33 -0
  129. package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
  130. package/dist/runtime/resolver-vendors/twocaptcha.js +408 -0
  131. package/dist/runtime/resolver-vendors/types.d.ts +94 -0
  132. package/dist/runtime/resolver-vendors/types.js +96 -0
  133. package/dist/runtime/resolver.d.ts +72 -0
  134. package/dist/runtime/resolver.js +771 -0
  135. package/dist/runtime/secrets.d.ts +27 -0
  136. package/dist/runtime/secrets.js +51 -0
  137. package/dist/runtime/state.d.ts +3 -0
  138. package/dist/runtime/state.js +277 -71
  139. package/dist/runtime/stealth-cookies.d.ts +20 -0
  140. package/dist/runtime/stealth-cookies.js +111 -0
  141. package/dist/runtime/stealth.d.ts +41 -5
  142. package/dist/runtime/stealth.js +997 -291
  143. package/dist/runtime/stt.js +1 -12
  144. package/dist/runtime/timeout.d.ts +5 -0
  145. package/dist/runtime/timeout.js +12 -0
  146. package/dist/runtime/trace-config.d.ts +12 -0
  147. package/dist/runtime/trace-config.js +62 -0
  148. package/dist/runtime/trace.d.ts +5 -0
  149. package/dist/runtime/trace.js +43 -10
  150. package/dist/serve.d.ts +1 -1
  151. package/dist/serve.js +1 -1
  152. package/dist/server/error-observability.d.ts +1 -0
  153. package/dist/server/error-observability.js +1 -0
  154. package/dist/server/index.d.ts +5 -2
  155. package/dist/server/index.js +2 -2
  156. package/dist/server/self-test-input-tokens.d.ts +2 -1
  157. package/dist/server/self-test-input-tokens.js +18 -14
  158. package/dist/server/self-test.d.ts +14 -3
  159. package/dist/server/self-test.js +129 -58
  160. package/dist/server/serve-implementation.d.ts +230 -0
  161. package/dist/server/serve-implementation.js +2265 -0
  162. package/dist/server/serve.d.ts +1 -70
  163. package/dist/server/serve.js +1 -1131
  164. package/dist/server/trace-output.d.ts +6 -0
  165. package/dist/server/trace-output.js +79 -0
  166. package/dist/server/types.d.ts +30 -5
  167. package/dist/server/types.js +13 -1
  168. package/dist/stateful/errors.d.ts +19 -0
  169. package/dist/stateful/errors.js +24 -0
  170. package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
  171. package/dist/stateful/http-provider-event-emitter.js +237 -0
  172. package/dist/stateful/http-session-owner-registry.d.ts +44 -0
  173. package/dist/stateful/http-session-owner-registry.js +210 -0
  174. package/dist/stateful/index.d.ts +18 -0
  175. package/dist/stateful/index.js +18 -0
  176. package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
  177. package/dist/stateful/provider-event-delivery-failures.js +43 -0
  178. package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
  179. package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
  180. package/dist/stateful/provider-event-pipeline.d.ts +50 -0
  181. package/dist/stateful/provider-event-pipeline.js +1 -0
  182. package/dist/stateful/provider-events.d.ts +101 -0
  183. package/dist/stateful/provider-events.js +289 -0
  184. package/dist/stateful/session-key.d.ts +15 -0
  185. package/dist/stateful/session-key.js +86 -0
  186. package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
  187. package/dist/stateful/stateful-provider-adapter-context.js +42 -0
  188. package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
  189. package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
  190. package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
  191. package/dist/stateful/stateful-provider-adapter.js +287 -0
  192. package/dist/stateful/stateful-provider-observability.d.ts +62 -0
  193. package/dist/stateful/stateful-provider-observability.js +161 -0
  194. package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
  195. package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
  196. package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
  197. package/dist/stateful/stateful-provider-runtime-context.js +60 -0
  198. package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
  199. package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
  200. package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
  201. package/dist/stateful/stateful-provider-session-routing.js +345 -0
  202. package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
  203. package/dist/stateful/stateful-provider-session-runtime.js +245 -0
  204. package/dist/stateful-signing.d.ts +18 -0
  205. package/dist/stateful-signing.js +27 -0
  206. package/dist/stealth/profiles.d.ts +9 -4
  207. package/dist/stealth/profiles.js +160 -211
  208. package/dist/stream-evidence.d.ts +74 -0
  209. package/dist/stream-evidence.js +785 -0
  210. package/dist/stream.js +7 -1
  211. package/dist/testing/index.d.ts +2 -1
  212. package/dist/testing/index.js +2 -1
  213. package/dist/testing/run.d.ts +32 -2
  214. package/dist/testing/run.js +489 -21
  215. package/dist/trace-sanitization.d.ts +5 -0
  216. package/dist/trace-sanitization.js +45 -0
  217. package/dist/types.d.ts +673 -131
  218. package/dist/types.js +1 -0
  219. package/package.json +45 -5
  220. package/src/auth-turn/index.ts +1 -1
  221. package/src/auth.ts +118 -0
  222. package/src/ceremonies/index.ts +189 -46
  223. package/src/cli/__tests__/fixtures/migrate-operation-declaration/approval-override.ts.txt +6 -0
  224. package/src/cli/__tests__/fixtures/migrate-operation-declaration/codemod-syntax.ts.txt +3 -0
  225. package/src/cli/__tests__/fixtures/migrate-operation-declaration/connection-precedence.ts.txt +10 -0
  226. package/src/cli/__tests__/fixtures/migrate-operation-declaration/docs-conflict.ts.txt +8 -0
  227. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-hoisted-array-spread.ts.txt +15 -0
  228. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-imported-array-spread.ts.txt +9 -0
  229. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-map.ts.txt +5 -0
  230. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-mixed-array-spread.ts.txt +24 -0
  231. package/src/cli/__tests__/fixtures/migrate-operation-declaration/examples-operation.ts.txt +16 -0
  232. package/src/cli/__tests__/fixtures/migrate-operation-declaration/factory-map.ts.txt +3 -0
  233. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoist-all.ts.txt +31 -0
  234. package/src/cli/__tests__/fixtures/migrate-operation-declaration/hoisted-const.ts.txt +11 -0
  235. package/src/cli/__tests__/fixtures/migrate-operation-declaration/imported-spread.ts.txt +11 -0
  236. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-map.ts.txt +11 -0
  237. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-cast-tail.ts.txt +21 -0
  238. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-ekitan.ts.txt +11 -0
  239. package/src/cli/__tests__/fixtures/migrate-operation-declaration/inline-spread-override.ts.txt +14 -0
  240. package/src/cli/__tests__/fixtures/migrate-operation-declaration/missing-english-locale.ts.txt +7 -0
  241. package/src/cli/__tests__/fixtures/migrate-operation-declaration/no-safety.ts.txt +6 -0
  242. package/src/cli/__tests__/fixtures/migrate-operation-declaration/non-literal.ts.txt +7 -0
  243. package/src/cli/__tests__/fixtures/migrate-operation-declaration/redundant-approval.ts.txt +6 -0
  244. package/src/cli/__tests__/fixtures/migrate-operation-declaration/safety-conflict.ts.txt +7 -0
  245. package/src/cli/__tests__/fixtures/migrate-operation-declaration/stream.ts.txt +7 -0
  246. package/src/cli/__tests__/fixtures/migrate-operation-declaration/tool-router-spread.ts.txt +15 -0
  247. package/src/cli/__tests__/fixtures/migrate-operation-declaration/unparseable.ts.txt +4 -0
  248. package/src/cli/__tests__/fixtures/migrate-operation-declaration/verbatim-template.ts.txt +12 -0
  249. package/src/cli/commands.ts +33 -0
  250. package/src/cli/create.ts +50 -37
  251. package/src/cli/migrate-operation-declaration.ts +1751 -0
  252. package/src/cli/migrate-operation-shape.ts +184 -0
  253. package/src/cli/migrate-provider-shape.ts +772 -0
  254. package/src/cli/prompt-assets.ts +865 -0
  255. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  256. package/src/cli/templates/provider/Dockerfile.tpl +1 -1
  257. package/src/cli/templates/provider/README.md.tpl +5 -5
  258. package/src/cli/templates/provider/index.ts.tpl +6 -3
  259. package/src/cli/templates/provider/operations/ping.ts.tpl +4 -1
  260. package/src/cli/templates/provider/provider.json.tpl +6 -0
  261. package/src/config/loader.ts +690 -163
  262. package/src/contract-serialization.ts +5 -7
  263. package/src/contract-types.ts +12 -5
  264. package/src/contract.ts +24 -10
  265. package/src/declaration-validation.ts +330 -0
  266. package/src/define.ts +1048 -131
  267. package/src/dev.ts +4 -1
  268. package/src/engine.ts +279 -0
  269. package/src/error-observability.ts +64 -0
  270. package/src/error-resolution.ts +127 -0
  271. package/src/errors.ts +68 -0
  272. package/src/fixture-sanitization.ts +264 -0
  273. package/src/health-scenario.ts +875 -0
  274. package/src/index.ts +220 -13
  275. package/src/lint.ts +698 -90
  276. package/src/native-address.ts +340 -0
  277. package/src/native-egress-policy.ts +358 -0
  278. package/src/observability.ts +51 -1
  279. package/src/provider.ts +161 -3
  280. package/src/runtime/auth-flow.ts +12 -0
  281. package/src/runtime/browser.ts +661 -63
  282. package/src/runtime/cache.ts +189 -14
  283. package/src/runtime/choice-wordlist.ts +145 -0
  284. package/src/runtime/choice.ts +631 -120
  285. package/src/runtime/chrome149-header-order.ts +330 -0
  286. package/src/runtime/env.ts +13 -0
  287. package/src/runtime/executor.ts +43 -31
  288. package/src/runtime/http.ts +641 -61
  289. package/src/runtime/insights.ts +2 -2
  290. package/src/runtime/instrumentation.ts +520 -15
  291. package/src/runtime/native-network-errors.ts +99 -0
  292. package/src/runtime/native-network.ts +1605 -0
  293. package/src/runtime/ocr.ts +523 -0
  294. package/src/runtime/otlp.ts +467 -21
  295. package/src/runtime/proxy-errors.ts +12 -4
  296. package/src/runtime/proxy-nodemaven.ts +221 -0
  297. package/src/runtime/proxy-telemetry.ts +244 -75
  298. package/src/runtime/redirects.ts +66 -0
  299. package/src/runtime/redis.ts +7 -2
  300. package/src/runtime/request-options.ts +680 -1
  301. package/src/runtime/resolver-config.ts +6 -0
  302. package/src/runtime/resolver-public.ts +23 -0
  303. package/src/runtime/resolver-shared.ts +33 -0
  304. package/src/runtime/resolver-vendors/bindings.ts +56 -0
  305. package/src/runtime/resolver-vendors/browser.ts +533 -0
  306. package/src/runtime/resolver-vendors/capsolver.ts +707 -0
  307. package/src/runtime/resolver-vendors/hosts.ts +38 -0
  308. package/src/runtime/resolver-vendors/twocaptcha.ts +540 -0
  309. package/src/runtime/resolver-vendors/types.ts +212 -0
  310. package/src/runtime/resolver.ts +1157 -0
  311. package/src/runtime/secrets.ts +64 -0
  312. package/src/runtime/state.ts +394 -77
  313. package/src/runtime/stealth-cookies.ts +132 -0
  314. package/src/runtime/stealth.ts +1280 -336
  315. package/src/runtime/stt.ts +1 -19
  316. package/src/runtime/timeout.ts +18 -0
  317. package/src/runtime/trace-config.ts +78 -0
  318. package/src/runtime/trace.ts +57 -17
  319. package/src/serve.ts +6 -1
  320. package/src/server/error-observability.ts +1 -0
  321. package/src/server/index.ts +34 -2
  322. package/src/server/self-test-input-tokens.ts +29 -14
  323. package/src/server/self-test.ts +191 -68
  324. package/src/server/serve-implementation.ts +3378 -0
  325. package/src/server/serve.ts +1 -1632
  326. package/src/server/trace-output.ts +129 -0
  327. package/src/server/types.ts +13 -1
  328. package/src/stateful/README.md +146 -0
  329. package/src/stateful/errors.ts +35 -0
  330. package/src/stateful/http-provider-event-emitter.ts +314 -0
  331. package/src/stateful/http-session-owner-registry.ts +306 -0
  332. package/src/stateful/index.ts +18 -0
  333. package/src/stateful/provider-event-delivery-failures.ts +80 -0
  334. package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
  335. package/src/stateful/provider-event-pipeline.ts +61 -0
  336. package/src/stateful/provider-events.ts +462 -0
  337. package/src/stateful/session-key.ts +111 -0
  338. package/src/stateful/stateful-provider-adapter-context.ts +59 -0
  339. package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
  340. package/src/stateful/stateful-provider-adapter.ts +562 -0
  341. package/src/stateful/stateful-provider-observability.ts +261 -0
  342. package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
  343. package/src/stateful/stateful-provider-runtime-context.ts +92 -0
  344. package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
  345. package/src/stateful/stateful-provider-session-routing.ts +546 -0
  346. package/src/stateful/stateful-provider-session-runtime.ts +403 -0
  347. package/src/stateful-signing.ts +46 -0
  348. package/src/stealth/profiles.ts +202 -231
  349. package/src/stream-evidence.ts +988 -0
  350. package/src/stream.ts +8 -1
  351. package/src/testing/index.ts +10 -1
  352. package/src/testing/run.ts +658 -15
  353. package/src/trace-sanitization.ts +63 -0
  354. package/src/types.ts +788 -174
  355. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  356. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  357. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  358. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  359. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  360. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  361. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  362. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  363. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  364. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  365. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  366. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  367. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  368. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
@@ -2,21 +2,30 @@
2
2
 
3
3
  import { existsSync } from "node:fs";
4
4
  import { dirname, relative, resolve } from "node:path";
5
- import type { ProviderDefinition } from "../src/index.js";
6
5
  import {
7
- createBrowserClient,
8
6
  createCredentialContext,
9
7
  createEnvContext,
10
8
  createHttpClient,
9
+ createInProcessProviderEngine,
10
+ createOcrClientFromEnv,
11
11
  createProviderCache,
12
12
  createProviderChoiceContext,
13
- createStealthClient,
13
+ createProviderEnvironment,
14
+ createUnsupportedResolverClient,
14
15
  createSttClientFromEnv,
15
16
  PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV,
17
+ readEngineProxyCredentials,
18
+ type ProviderDefinition,
19
+ type ProviderEngineBindingCandidates,
16
20
  ProviderError,
21
+ type ProviderProxyPolicy,
17
22
  } from "../src/index.js";
23
+ import { createBrowserClient } from "../src/runtime/browser.js";
24
+ import { createResolverClientFromEnv } from "../src/runtime/resolver.js";
18
25
  import { createMemoryProviderRuntimeState } from "../src/runtime/state.js";
26
+ import { createStealthClient } from "../src/runtime/stealth.js";
19
27
  import { createTraceContext } from "../src/runtime/trace.js";
28
+ import { getStealthProfile } from "../src/stealth/profiles.js";
20
29
  import type { BrowserClient, ProviderContext } from "../src/types.js";
21
30
 
22
31
  const HELP_TEXT = `Usage: apifuse dev [path]
@@ -74,14 +83,20 @@ export async function main() {
74
83
  export function createProviderContext(provider: ProviderDefinition): {
75
84
  ctx: ProviderContext;
76
85
  } {
77
- const env = createEnvContext([
78
- ...(provider.secrets?.map((secret) => secret.name) ?? []),
79
- PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV,
80
- ]);
86
+ const providerEnvironment = createProviderEnvironment(
87
+ process.env,
88
+ provider.secrets?.map((secret) => secret.name) ?? [],
89
+ );
90
+ const providerEnv = { get: (key: string) => providerEnvironment[key] };
91
+ const engineEnv = createEnvContext([PROVIDER_RUNTIME_CHOICE_TOKEN_MASTER_SECRET_ENV]);
92
+ const engineCredentials = readEngineProxyCredentials();
81
93
  const credential = createCredentialContext();
82
94
  const state = createMemoryProviderRuntimeState();
83
- const ctx: ProviderContext = {
84
- env,
95
+ const cache = createProviderCache({ providerId: provider.id });
96
+ const proxyPolicy = resolveNativeProxyPolicy(provider);
97
+ const stealthProfile = provider.stealth ? getStealthProfile(provider.stealth) : undefined;
98
+ const candidates: ProviderEngineBindingCandidates = {
99
+ env: providerEnv,
85
100
  credential,
86
101
  auth: createUnsupportedAuthStub(),
87
102
  browser:
@@ -92,22 +107,51 @@ export function createProviderContext(provider: ProviderDefinition): {
92
107
  })
93
108
  : createUnsupportedBrowserStub(),
94
109
  http: createHttpClient(),
95
- cache: createProviderCache({ providerId: provider.id }),
110
+ cache,
96
111
  state,
97
112
  trace: createTraceContext(),
98
- stealth: createStealthClient("http://localhost"),
113
+ stealth: createStealthClient("http://localhost", {
114
+ ...(provider.stealth ? { stealth: provider.stealth } : {}),
115
+ }),
116
+ ocr: createOcrClientFromEnv(provider.ocr),
99
117
  stt: createSttClientFromEnv(provider.stt),
118
+ resolver: provider.resolver
119
+ ? createResolverClientFromEnv(provider.resolver, engineCredentials, {
120
+ allowedHosts: provider.allowedHosts,
121
+ cache,
122
+ ...(proxyPolicy
123
+ ? {
124
+ proxyIntent: {
125
+ mode: proxyPolicy.mode,
126
+ upstream: { proxy: provider.proxy },
127
+ ...(stealthProfile ? { userAgent: stealthProfile.userAgent } : {}),
128
+ },
129
+ }
130
+ : {}),
131
+ })
132
+ : createUnsupportedResolverClient("Provider does not declare resolver capability"),
100
133
  choice: createProviderChoiceContext({
101
134
  providerId: provider.id,
102
- env,
135
+ env: engineEnv,
103
136
  credential,
104
137
  state,
105
138
  }),
106
139
  };
140
+ const ctx = createInProcessProviderEngine().attach({
141
+ provider,
142
+ bindings: candidates,
143
+ }) as ProviderContext;
107
144
 
108
145
  return { ctx };
109
146
  }
110
147
 
148
+ function resolveNativeProxyPolicy(provider: ProviderDefinition): ProviderProxyPolicy | undefined {
149
+ if (typeof provider.proxy === "object") return provider.proxy;
150
+ if (provider.proxy === true) return { mode: "optional" };
151
+ if (provider.proxy === false) return { mode: "disabled" };
152
+ return undefined;
153
+ }
154
+
111
155
  function normalizeArgs(argv: string[]): string[] {
112
156
  return argv[0] === "dev" ? argv.slice(1) : argv;
113
157
  }
@@ -216,7 +260,7 @@ function isProviderDefinition(value: unknown): value is ProviderDefinition {
216
260
  return (
217
261
  typeof value.id === "string" &&
218
262
  typeof value.version === "string" &&
219
- (value.runtime === "standard" || value.runtime === "browser") &&
263
+ (value.runtime === "standard" || value.runtime === "shared" || value.runtime === "browser") &&
220
264
  typeof value.meta.displayName === "string" &&
221
265
  typeof value.meta.category === "string"
222
266
  );
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * `apifuse migrate-operation-declaration [path] [--check] [--json]`
5
+ *
6
+ * Rewrites ADR-0009's legacy nested operation declarations to the flat
7
+ * authoring contract. The run is repository-atomic: any declaration the
8
+ * codemod cannot prove leaves every source file untouched and exits 2.
9
+ */
10
+
11
+ import { resolve } from "node:path";
12
+
13
+ import { migrateOperationDeclarationRepository } from "../src/cli/migrate-operation-declaration.js";
14
+
15
+ export async function main(): Promise<number> {
16
+ const args = process.argv.slice(3);
17
+ const check = args.includes("--check");
18
+ const json = args.includes("--json");
19
+ const positional = args.filter((argument) => !argument.startsWith("--"));
20
+ const providerRoot = resolve(positional[0] ?? ".");
21
+ const result = migrateOperationDeclarationRepository(providerRoot, { check });
22
+
23
+ if (json) {
24
+ console.log(
25
+ JSON.stringify({
26
+ schemaVersion: 1,
27
+ command: "migrate-operation-declaration",
28
+ ...result,
29
+ }),
30
+ );
31
+ } else if (result.status === "refused") {
32
+ console.error(
33
+ `migrate-operation-declaration: refused ${result.refusals.length} declaration(s); no files were written.`,
34
+ );
35
+ for (const item of result.refusals) {
36
+ console.error(` ${item.file} [${item.operationKey}] ${item.reason}: ${item.detail}`);
37
+ }
38
+ } else if (result.status === "unchanged") {
39
+ console.log("migrate-operation-declaration: already flat; nothing to do.");
40
+ } else {
41
+ const verb = result.status === "would-migrate" ? "would migrate" : "migrated";
42
+ const sidecar = result.sidecar === undefined ? "" : ` and ${result.sidecar}`;
43
+ console.log(
44
+ `migrate-operation-declaration: ${verb} ${result.operationCount} operation(s) across ${result.changedFiles.length} file(s)${sidecar}.`,
45
+ );
46
+ }
47
+
48
+ const exitCode = result.status === "refused" ? 2 : 0;
49
+ process.exitCode = exitCode;
50
+ return exitCode;
51
+ }
52
+
53
+ if (import.meta.main) {
54
+ process.exit(await main());
55
+ }
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * `apifuse migrate-shape [path] [--check] [--json]`
5
+ *
6
+ * Applies the provider authoring-shape migration for the phase-separated SDK
7
+ * (2.2.0-beta.37+) to a provider repository. Two coordinated transforms:
8
+ *
9
+ * 1. `index.ts`: single-phase `defineProvider({...operations})` becomes the
10
+ * two-phase declaration builder. The old shape default-exports a builder
11
+ * FUNCTION under the new SDK, so the module stops loading.
12
+ * 2. Every provider source file: legacy `defineOperation(config)` /
13
+ * `defineStreamOperation(config)` become the curried
14
+ * `defineOperation<ProviderContext>()(config)`. The legacy call returns
15
+ * the inner factory with the config swallowed, so every operation in the
16
+ * map turns into a function and finalizeProvider rejects the provider
17
+ * with a misleading health-check error.
18
+ *
19
+ * Both halves belong to the same SDK bump: this transform and the pin bump
20
+ * must land in one commit.
21
+ *
22
+ * Exit codes: 0 migrated or already migrated; 1 any skip (the transform
23
+ * refuses to guess) or a missing index.ts. `--check` reports without
24
+ * writing. A skip is a hard stop for fan-out callers — never pair a pin bump
25
+ * with a skipped migration.
26
+ */
27
+
28
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
29
+ import { dirname, join, relative, resolve } from "node:path";
30
+
31
+ import { migrateOperationShape } from "../src/cli/migrate-operation-shape.js";
32
+ import { migrateProviderShape } from "../src/cli/migrate-provider-shape.js";
33
+
34
+ const SOURCE_SKIP_DIRECTORIES = new Set([
35
+ "node_modules",
36
+ "__tests__",
37
+ "__fixtures__",
38
+ ".git",
39
+ "dist",
40
+ ]);
41
+
42
+ type FileOutcome = {
43
+ readonly path: string;
44
+ readonly status: string;
45
+ readonly detail?: string;
46
+ };
47
+
48
+ export async function main(): Promise<void> {
49
+ const args = process.argv.slice(3);
50
+ const check = args.includes("--check");
51
+ const json = args.includes("--json");
52
+ const positional = args.filter((argument) => !argument.startsWith("--"));
53
+ const providerRoot = resolve(positional[0] ?? ".");
54
+ const indexPath = resolve(providerRoot, "index.ts");
55
+
56
+ const report = (payload: Record<string, unknown>, humanText: string): void => {
57
+ if (json) {
58
+ console.log(
59
+ JSON.stringify({ schemaVersion: 2, providerRoot, ...payload }),
60
+ );
61
+ } else {
62
+ console.log(humanText);
63
+ }
64
+ };
65
+
66
+ if (!existsSync(indexPath)) {
67
+ report(
68
+ { status: "skipped", reason: "index.ts not found" },
69
+ `migrate-shape: ${indexPath} not found.`,
70
+ );
71
+ process.exit(1);
72
+ }
73
+
74
+ // ── Pass 1: provider two-phase shape on index.ts
75
+ const indexSource = readFileSync(indexPath, "utf8");
76
+ const providerResult = migrateProviderShape(indexSource, indexPath);
77
+
78
+ if (providerResult.status === "skipped") {
79
+ report(
80
+ { status: "skipped", stage: "provider-shape", reason: providerResult.reason },
81
+ `migrate-shape: skipped — ${providerResult.reason}\nThis provider needs a manual migration; do not bump its SDK pin without one.`,
82
+ );
83
+ process.exit(1);
84
+ }
85
+
86
+ // ── Pass 2: operation currying across the provider's source tree.
87
+ // The index.ts input for this pass is pass 1's OUTPUT, so a provider
88
+ // whose index both holds the declaration and defines operations gets
89
+ // both transforms in one write.
90
+ const indexAfterProvider = providerResult.code;
91
+ const outcomes: FileOutcome[] = [];
92
+ const pendingWrites = new Map<string, string>();
93
+ let operationRewrites = 0;
94
+
95
+ for (const sourcePath of collectSourceFiles(providerRoot)) {
96
+ const isIndex = sourcePath === indexPath;
97
+ const input = isIndex
98
+ ? indexAfterProvider
99
+ : readFileSync(sourcePath, "utf8");
100
+ // Operation modules import the alias from the provider entry; the
101
+ // entry file declares it itself.
102
+ const contextSpecifier = isIndex
103
+ ? "./index"
104
+ : relativeImportToIndex(sourcePath, providerRoot);
105
+ const result = migrateOperationShape(input, sourcePath, contextSpecifier);
106
+
107
+ if (result.status === "skipped") {
108
+ report(
109
+ {
110
+ status: "skipped",
111
+ stage: "operation-shape",
112
+ file: relative(providerRoot, sourcePath),
113
+ reason: result.reason,
114
+ },
115
+ `migrate-shape: skipped at ${relative(providerRoot, sourcePath)} — ${result.reason}\nThis provider needs a manual migration; do not bump its SDK pin without one.`,
116
+ );
117
+ process.exit(1);
118
+ }
119
+ if (result.status === "migrated") {
120
+ operationRewrites += result.rewrites;
121
+ pendingWrites.set(sourcePath, result.code);
122
+ outcomes.push({
123
+ path: relative(providerRoot, sourcePath),
124
+ status: "curried",
125
+ detail: `${result.rewrites} call site(s)`,
126
+ });
127
+ } else if (isIndex && providerResult.status === "migrated") {
128
+ // Provider shape changed even though no operation calls did.
129
+ pendingWrites.set(sourcePath, result.code);
130
+ }
131
+ }
132
+
133
+ const providerChanged = providerResult.status === "migrated";
134
+ const anythingChanged = providerChanged || operationRewrites > 0;
135
+
136
+ if (!anythingChanged) {
137
+ report(
138
+ { status: "unchanged" },
139
+ "migrate-shape: already migrated; nothing to do.",
140
+ );
141
+ return;
142
+ }
143
+
144
+ if (check) {
145
+ report(
146
+ {
147
+ status: "would-migrate",
148
+ providerShape: providerChanged ? providerResult.kind : "unchanged",
149
+ operationCallSites: operationRewrites,
150
+ files: outcomes,
151
+ },
152
+ `migrate-shape: would migrate (provider: ${providerChanged ? providerResult.kind : "unchanged"}, operation call sites: ${operationRewrites}). Run without --check to write.`,
153
+ );
154
+ return;
155
+ }
156
+
157
+ for (const [path, code] of pendingWrites) {
158
+ writeFileSync(path, code, "utf8");
159
+ }
160
+ report(
161
+ {
162
+ status: "migrated",
163
+ providerShape: providerChanged ? providerResult.kind : "unchanged",
164
+ operationCallSites: operationRewrites,
165
+ files: outcomes,
166
+ },
167
+ `migrate-shape: migrated (provider: ${providerChanged ? providerResult.kind : "unchanged"}, operation call sites: ${operationRewrites} across ${pendingWrites.size} file(s)). Review the diff, then run \`apifuse check\` and \`bun test\`.`,
168
+ );
169
+ }
170
+
171
+ /** Provider-authored .ts sources, excluding tests, fixtures, and build output. */
172
+ function collectSourceFiles(root: string): string[] {
173
+ const files: string[] = [];
174
+ const walk = (directory: string): void => {
175
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
176
+ if (entry.isDirectory()) {
177
+ if (SOURCE_SKIP_DIRECTORIES.has(entry.name)) continue;
178
+ walk(join(directory, entry.name));
179
+ continue;
180
+ }
181
+ if (!entry.name.endsWith(".ts")) continue;
182
+ if (entry.name.endsWith(".d.ts")) continue;
183
+ if (entry.name.endsWith(".test.ts")) continue;
184
+ files.push(join(directory, entry.name));
185
+ }
186
+ };
187
+ walk(root);
188
+ return files.sort();
189
+ }
190
+
191
+ /** `operations/foo.ts` -> `../index`; `operations/a/b.ts` -> `../../index`. */
192
+ function relativeImportToIndex(sourcePath: string, providerRoot: string): string {
193
+ const fromDirectory = dirname(sourcePath);
194
+ let specifier = relative(fromDirectory, join(providerRoot, "index"));
195
+ specifier = specifier.split("\\").join("/");
196
+ if (!specifier.startsWith(".")) specifier = `./${specifier}`;
197
+ return specifier;
198
+ }
199
+
200
+ if (import.meta.main) {
201
+ await main();
202
+ }
@@ -48,6 +48,13 @@ const requiredPaths = [
48
48
  "src/cli/templates/provider/operations/ping.ts.tpl",
49
49
  "src/cli/templates/provider/schemas/ping.ts.tpl",
50
50
  "src/cli/templates/provider/upstream/README.md.tpl",
51
+ "src/cli/templates/provider/AGENTS.md.tpl",
52
+ "src/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl",
53
+ "src/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl",
54
+ "src/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl",
55
+ "src/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl",
56
+ "src/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl",
57
+ "src/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl",
51
58
  "dist/cli/templates/provider/.dockerignore.tpl",
52
59
  "dist/cli/templates/provider/.gitignore.tpl",
53
60
  "dist/cli/templates/provider/Dockerfile.tpl",
@@ -60,6 +67,13 @@ const requiredPaths = [
60
67
  "dist/cli/templates/provider/operations/ping.ts.tpl",
61
68
  "dist/cli/templates/provider/schemas/ping.ts.tpl",
62
69
  "dist/cli/templates/provider/upstream/README.md.tpl",
70
+ "dist/cli/templates/provider/AGENTS.md.tpl",
71
+ "dist/cli/templates/provider/.agents/skills/normalization-standards/SKILL.md.tpl",
72
+ "dist/cli/templates/provider/.agents/skills/upstream-contract-verification/SKILL.md.tpl",
73
+ "dist/cli/templates/provider/.agents/skills/fixtures-and-recording/SKILL.md.tpl",
74
+ "dist/cli/templates/provider/.agents/skills/pagination-and-counts/SKILL.md.tpl",
75
+ "dist/cli/templates/provider/.agents/skills/health-checks-and-fail-closed/SKILL.md.tpl",
76
+ "dist/cli/templates/provider/.agents/skills/upstream-notes/README.md.tpl",
63
77
  "dist/auth-turn/index.js",
64
78
  "dist/auth-turn/index.d.ts",
65
79
  "dist/auth-turn/auth-turn.v1.schema.json",
@@ -142,9 +156,9 @@ function assertPublicSmokeDocs(label: string, content: string): void {
142
156
  );
143
157
  }
144
158
 
145
- if (!content.includes("impit")) {
159
+ if (!content.includes("wreq-js")) {
146
160
  throw new Error(
147
- `${label} must include impit stealth runtime guidance for TLS/browser bounties.`,
161
+ `${label} must include wreq-js stealth runtime guidance for TLS/browser bounties.`,
148
162
  );
149
163
  }
150
164
 
@@ -154,6 +168,12 @@ function assertPublicSmokeDocs(label: string, content: string): void {
154
168
  );
155
169
  }
156
170
 
171
+ if (!content.includes("Chrome, Firefox, and Safari")) {
172
+ throw new Error(
173
+ `${label} must document the browser families supported by the TypeScript stealth runtime.`,
174
+ );
175
+ }
176
+
157
177
  if (
158
178
  !content.includes('browser.engine: "playwright-stealth"') ||
159
179
  !content.includes("nodriver")
@@ -59,6 +59,21 @@ try {
59
59
  );
60
60
 
61
61
  run("bun", ["install"], consumerDir);
62
+ run(
63
+ "bun",
64
+ [
65
+ "--eval",
66
+ [
67
+ 'import { resolveProxy } from "@apifuse/provider-sdk";',
68
+ 'if (typeof resolveProxy !== "function") throw new Error("resolveProxy is not exported");',
69
+ 'const resolved = await resolveProxy({ proxy: "http://127.0.0.1:8080" });',
70
+ 'if (resolved.url !== "http://127.0.0.1:8080") throw new Error("resolveProxy returned the wrong URL");',
71
+ 'console.log("packed root resolveProxy export OK");',
72
+ ].join("\n"),
73
+ ],
74
+ consumerDir,
75
+ );
76
+ smokePackedStealthNative(consumerDir);
62
77
 
63
78
  const cliBin = join(consumerDir, "node_modules", ".bin", "apifuse");
64
79
  if (!existsSync(cliBin)) {
@@ -202,6 +217,43 @@ function run(command: string, args: string[], cwd: string): void {
202
217
  }
203
218
  }
204
219
 
220
+ function smokePackedStealthNative(consumerDir: string): void {
221
+ run(
222
+ "bun",
223
+ [
224
+ "--eval",
225
+ [
226
+ 'import { createServer } from "node:http";',
227
+ 'import { createStealthClient } from "@apifuse/provider-sdk/runtime/stealth";',
228
+ "const server = createServer((_request, response) => {",
229
+ ' response.setHeader("set-cookie", "pack_native_cookie=landed; Path=/");',
230
+ ' response.end("packed native stealth ok");',
231
+ "});",
232
+ "await new Promise((resolve, reject) => {",
233
+ ' server.once("error", reject);',
234
+ ' server.listen(0, "127.0.0.1", resolve);',
235
+ "});",
236
+ "const address = server.address();",
237
+ 'if (!address || typeof address === "string") throw new Error("Local server has no TCP address");',
238
+ 'const baseUrl = "http://127.0.0.1:" + address.port;',
239
+ 'const session = createStealthClient(baseUrl).createSession({ stealth: { browser: "safari", os: "macos" } });',
240
+ "try {",
241
+ ' const response = await session.fetch("/native");',
242
+ ' if (response.body !== "packed native stealth ok") throw new Error("Unexpected stealth body: " + response.body);',
243
+ ' if (session.cookies.get("pack_native_cookie", baseUrl + "/native") !== "landed") {',
244
+ ' throw new Error("Packed stealth Set-Cookie did not land in the SDK jar");',
245
+ " }",
246
+ ' console.log("packed native Safari stealth request OK");',
247
+ "} finally {",
248
+ " session.close();",
249
+ " await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));",
250
+ "}",
251
+ ].join("\n"),
252
+ ],
253
+ consumerDir,
254
+ );
255
+ }
256
+
205
257
  function assertGeneratedReadme(providerDir: string): void {
206
258
  const readme = readFileSync(join(providerDir, "README.md"), "utf8");
207
259
  if (!readme.includes('"requestId":"req_local_ping"')) {
@@ -213,8 +265,11 @@ function assertGeneratedReadme(providerDir: string): void {
213
265
  if (!readme.includes("bunx playwright install chromium")) {
214
266
  throw new Error("Generated README is missing browser runtime troubleshooting guidance.");
215
267
  }
216
- if (!readme.includes("impit")) {
217
- throw new Error("Generated README is missing impit stealth runtime guidance.");
268
+ if (!readme.includes("wreq-js")) {
269
+ throw new Error("Generated README is missing wreq-js stealth runtime guidance.");
270
+ }
271
+ if (!readme.includes("Chrome, Firefox, and Safari")) {
272
+ throw new Error("Generated README is missing supported stealth browser families.");
218
273
  }
219
274
  if (!readme.includes("bun run submit-check")) {
220
275
  throw new Error("Generated README must document the submit-check pre-submission workflow.");