sdkloom 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +239 -2
  3. package/kits/allowed-sources.json +24 -0
  4. package/kits/csharp/kit.json +6 -0
  5. package/kits/csharp/src/Runtime/Client.cs +295 -0
  6. package/kits/csharp/src/Runtime/Context.cs +216 -0
  7. package/kits/csharp/src/Runtime/Errors.cs +121 -0
  8. package/kits/csharp/src/Runtime/Http.cs +218 -0
  9. package/kits/csharp/src/Runtime/Json.cs +650 -0
  10. package/kits/csharp/src/Runtime/Lang.cs +212 -0
  11. package/kits/csharp/src/Runtime/Models.cs +206 -0
  12. package/kits/csharp/src/Runtime/Multipart.cs +108 -0
  13. package/kits/csharp/src/Runtime/Pagination.cs +122 -0
  14. package/kits/csharp/src/Runtime/Sse.cs +197 -0
  15. package/kits/csharp/src/Runtime/Testing.cs +375 -0
  16. package/kits/csharp/src/Runtime/Transport.cs +212 -0
  17. package/kits/csharp/src/Runtime/Wait.cs +57 -0
  18. package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
  19. package/kits/csharp/tests/ClientTests.cs +128 -0
  20. package/kits/csharp/tests/HttpTests.cs +44 -0
  21. package/kits/csharp/tests/JsonTests.cs +132 -0
  22. package/kits/csharp/tests/LangTests.cs +57 -0
  23. package/kits/csharp/tests/MultipartTests.cs +31 -0
  24. package/kits/csharp/tests/PaginationTests.cs +93 -0
  25. package/kits/csharp/tests/SseTests.cs +122 -0
  26. package/kits/csharp/tests/TestRunner.cs +93 -0
  27. package/kits/csharp/tests/TestingTests.cs +80 -0
  28. package/kits/csharp/tests/TransportTests.cs +145 -0
  29. package/kits/csharp/tests/WaitTests.cs +39 -0
  30. package/kits/csharp/tests/WebhooksTests.cs +46 -0
  31. package/kits/csharp/versions.json +12 -0
  32. package/kits/go/kit.json +6 -0
  33. package/kits/go/src/sdkruntime/client.go +322 -0
  34. package/kits/go/src/sdkruntime/context.go +207 -0
  35. package/kits/go/src/sdkruntime/errors.go +74 -0
  36. package/kits/go/src/sdkruntime/http.go +261 -0
  37. package/kits/go/src/sdkruntime/json.go +527 -0
  38. package/kits/go/src/sdkruntime/lang.go +462 -0
  39. package/kits/go/src/sdkruntime/multipart.go +75 -0
  40. package/kits/go/src/sdkruntime/pagination.go +150 -0
  41. package/kits/go/src/sdkruntime/sse.go +267 -0
  42. package/kits/go/src/sdkruntime/testing.go +343 -0
  43. package/kits/go/src/sdkruntime/transport.go +168 -0
  44. package/kits/go/src/sdkruntime/wait.go +49 -0
  45. package/kits/go/src/sdkruntime/webhooks.go +129 -0
  46. package/kits/go/tests/client_test.go +185 -0
  47. package/kits/go/tests/http_test.go +78 -0
  48. package/kits/go/tests/json_test.go +127 -0
  49. package/kits/go/tests/lang_test.go +98 -0
  50. package/kits/go/tests/multipart_test.go +29 -0
  51. package/kits/go/tests/pagination_test.go +69 -0
  52. package/kits/go/tests/sse_test.go +129 -0
  53. package/kits/go/tests/testing_test.go +121 -0
  54. package/kits/go/tests/transport_test.go +133 -0
  55. package/kits/go/tests/wait_test.go +46 -0
  56. package/kits/go/tests/webhooks_test.go +62 -0
  57. package/kits/go/versions.json +12 -0
  58. package/kits/java/kit.json +6 -0
  59. package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
  60. package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
  61. package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
  62. package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
  63. package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
  64. package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
  65. package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
  66. package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
  67. package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
  68. package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
  69. package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
  70. package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
  71. package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
  72. package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
  73. package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
  74. package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
  75. package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
  76. package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
  77. package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
  78. package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
  79. package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
  80. package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
  81. package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
  82. package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
  83. package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
  84. package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
  85. package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
  86. package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
  87. package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
  88. package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
  89. package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
  90. package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
  91. package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
  92. package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
  93. package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
  94. package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
  95. package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
  96. package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
  97. package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
  98. package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
  99. package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
  100. package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
  101. package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
  102. package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
  103. package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
  104. package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
  105. package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
  106. package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
  107. package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
  108. package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
  109. package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
  110. package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
  111. package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
  112. package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
  113. package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
  114. package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
  115. package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
  116. package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
  117. package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
  118. package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
  119. package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
  120. package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
  121. package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
  122. package/kits/java/versions.json +41 -0
  123. package/kits/python/kit.json +6 -0
  124. package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
  125. package/kits/python/src/sdkloom_runtime/client.py +232 -0
  126. package/kits/python/src/sdkloom_runtime/compat.py +195 -0
  127. package/kits/python/src/sdkloom_runtime/context.py +134 -0
  128. package/kits/python/src/sdkloom_runtime/errors.py +65 -0
  129. package/kits/python/src/sdkloom_runtime/http.py +192 -0
  130. package/kits/python/src/sdkloom_runtime/lang.py +207 -0
  131. package/kits/python/src/sdkloom_runtime/models.py +221 -0
  132. package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
  133. package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
  134. package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
  135. package/kits/python/src/sdkloom_runtime/sse.py +121 -0
  136. package/kits/python/src/sdkloom_runtime/testing.py +224 -0
  137. package/kits/python/src/sdkloom_runtime/transport.py +120 -0
  138. package/kits/python/src/sdkloom_runtime/wait.py +44 -0
  139. package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
  140. package/kits/python/tests/support.py +28 -0
  141. package/kits/python/tests/test_client.py +275 -0
  142. package/kits/python/tests/test_compat.py +87 -0
  143. package/kits/python/tests/test_http.py +94 -0
  144. package/kits/python/tests/test_lang.py +104 -0
  145. package/kits/python/tests/test_models.py +110 -0
  146. package/kits/python/tests/test_multipart.py +37 -0
  147. package/kits/python/tests/test_pagination.py +70 -0
  148. package/kits/python/tests/test_sse.py +61 -0
  149. package/kits/python/tests/test_testing.py +130 -0
  150. package/kits/python/tests/test_transport.py +124 -0
  151. package/kits/python/tests/test_wait.py +46 -0
  152. package/kits/python/tests/test_webhooks.py +57 -0
  153. package/kits/python/versions.json +33 -0
  154. package/kits/rust/kit.json +6 -0
  155. package/kits/rust/src/runtime/client.rs +212 -0
  156. package/kits/rust/src/runtime/context.rs +182 -0
  157. package/kits/rust/src/runtime/crypto.rs +84 -0
  158. package/kits/rust/src/runtime/errors.rs +147 -0
  159. package/kits/rust/src/runtime/http.rs +248 -0
  160. package/kits/rust/src/runtime/json.rs +424 -0
  161. package/kits/rust/src/runtime/lang.rs +296 -0
  162. package/kits/rust/src/runtime/mod.rs +30 -0
  163. package/kits/rust/src/runtime/models.rs +266 -0
  164. package/kits/rust/src/runtime/multipart.rs +81 -0
  165. package/kits/rust/src/runtime/pagination.rs +117 -0
  166. package/kits/rust/src/runtime/sse.rs +195 -0
  167. package/kits/rust/src/runtime/testing.rs +308 -0
  168. package/kits/rust/src/runtime/transport.rs +324 -0
  169. package/kits/rust/src/runtime/wait.rs +29 -0
  170. package/kits/rust/src/runtime/webhooks.rs +142 -0
  171. package/kits/rust/tests/client.rs +152 -0
  172. package/kits/rust/tests/http.rs +44 -0
  173. package/kits/rust/tests/json.rs +82 -0
  174. package/kits/rust/tests/lang.rs +74 -0
  175. package/kits/rust/tests/multipart.rs +21 -0
  176. package/kits/rust/tests/pagination.rs +61 -0
  177. package/kits/rust/tests/sse.rs +77 -0
  178. package/kits/rust/tests/testing.rs +90 -0
  179. package/kits/rust/tests/transport.rs +218 -0
  180. package/kits/rust/tests/wait.rs +32 -0
  181. package/kits/rust/tests/webhooks.rs +73 -0
  182. package/kits/rust/versions.json +6 -0
  183. package/kits/typescript/kit.json +6 -0
  184. package/kits/typescript/src/client.ts +223 -0
  185. package/kits/typescript/src/context.ts +108 -0
  186. package/kits/typescript/src/errors.ts +63 -0
  187. package/kits/typescript/src/helpers.ts +49 -0
  188. package/kits/typescript/src/http.ts +192 -0
  189. package/kits/typescript/src/models.ts +139 -0
  190. package/kits/typescript/src/multipart.ts +66 -0
  191. package/kits/typescript/src/pagination.ts +54 -0
  192. package/kits/typescript/src/pipeline.ts +25 -0
  193. package/kits/typescript/src/sse.ts +102 -0
  194. package/kits/typescript/src/testing.ts +217 -0
  195. package/kits/typescript/src/transport.ts +101 -0
  196. package/kits/typescript/src/wait.ts +36 -0
  197. package/kits/typescript/src/webhooks.ts +168 -0
  198. package/kits/typescript/tests/client.test.ts +269 -0
  199. package/kits/typescript/tests/helpers.test.ts +27 -0
  200. package/kits/typescript/tests/http.test.ts +80 -0
  201. package/kits/typescript/tests/models.test.ts +71 -0
  202. package/kits/typescript/tests/multipart.test.ts +28 -0
  203. package/kits/typescript/tests/pagination.test.ts +76 -0
  204. package/kits/typescript/tests/sse.test.ts +82 -0
  205. package/kits/typescript/tests/testing.test.ts +103 -0
  206. package/kits/typescript/tests/transport.test.ts +127 -0
  207. package/kits/typescript/tests/wait.test.ts +31 -0
  208. package/kits/typescript/tests/webhooks.test.ts +53 -0
  209. package/kits/typescript/versions.json +15 -0
  210. package/package.json +37 -4
  211. package/packages/cli/recipes/apiKeyHeader.ts +16 -0
  212. package/packages/cli/recipes/apiVersionHeader.ts +16 -0
  213. package/packages/cli/recipes/basic.ts +13 -0
  214. package/packages/cli/recipes/bearer.ts +10 -0
  215. package/packages/cli/recipes/hmacSign.ts +23 -0
  216. package/packages/cli/recipes/idempotencyKey.ts +19 -0
  217. package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
  218. package/packages/cli/recipes/retry.ts +42 -0
  219. package/packages/cli/recipes/timing.ts +12 -0
  220. package/packages/cli/recipes/userAgent.ts +8 -0
  221. package/packages/cli/src/build.js +93 -0
  222. package/packages/cli/src/commands/build.js +31 -0
  223. package/packages/cli/src/commands/conformance-check.js +50 -0
  224. package/packages/cli/src/commands/contract.js +181 -0
  225. package/packages/cli/src/commands/diff.js +113 -0
  226. package/packages/cli/src/commands/doctor.js +43 -0
  227. package/packages/cli/src/commands/import-openapi.js +42 -0
  228. package/packages/cli/src/commands/init.js +27 -0
  229. package/packages/cli/src/commands/kit-check.js +145 -0
  230. package/packages/cli/src/commands/publish.js +81 -0
  231. package/packages/cli/src/commands/recipe.js +49 -0
  232. package/packages/cli/src/commands/record.js +181 -0
  233. package/packages/cli/src/commands/serve.js +156 -0
  234. package/packages/cli/src/commands/spec-check.js +57 -0
  235. package/packages/cli/src/commands/test.js +177 -0
  236. package/packages/cli/src/commands/variants.js +32 -0
  237. package/packages/cli/src/commands/verify.js +57 -0
  238. package/packages/cli/src/commands/version.js +63 -0
  239. package/packages/cli/src/containers.js +82 -0
  240. package/packages/cli/src/coverage.js +72 -0
  241. package/packages/cli/src/git.js +25 -0
  242. package/packages/cli/src/io.js +50 -0
  243. package/packages/cli/src/java/ScenarioHarness.java +297 -0
  244. package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
  245. package/packages/cli/src/java.js +70 -0
  246. package/packages/cli/src/js/harness.mjs +120 -0
  247. package/packages/cli/src/kits.js +103 -0
  248. package/packages/cli/src/languages/csharp.js +274 -0
  249. package/packages/cli/src/languages/go.js +185 -0
  250. package/packages/cli/src/languages/index.js +18 -0
  251. package/packages/cli/src/languages/java.js +187 -0
  252. package/packages/cli/src/languages/python.js +120 -0
  253. package/packages/cli/src/languages/rust.js +189 -0
  254. package/packages/cli/src/languages/types.js +93 -0
  255. package/packages/cli/src/languages/typescript.js +112 -0
  256. package/packages/cli/src/main.js +13 -0
  257. package/packages/cli/src/packaging.js +39 -0
  258. package/packages/cli/src/portability.js +45 -0
  259. package/packages/cli/src/profiles.js +55 -0
  260. package/packages/cli/src/project.js +56 -0
  261. package/packages/cli/src/python/scenario_harness.py +162 -0
  262. package/packages/cli/src/python/schema_roundtrip.py +42 -0
  263. package/packages/cli/src/registries.js +214 -0
  264. package/packages/cli/src/resolve-core.js +39 -0
  265. package/packages/cli/src/run.js +133 -0
  266. package/packages/cli/src/runtimes.js +61 -0
  267. package/packages/cli/src/scenarios-java.js +82 -0
  268. package/packages/cli/src/scenarios-javascript.js +54 -0
  269. package/packages/cli/src/scenarios-python.js +90 -0
  270. package/packages/cli/src/scenarios.js +183 -0
  271. package/packages/cli/src/schema.js +84 -0
  272. package/packages/cli/src/templates.js +85 -0
  273. package/packages/cli/src/toolchains.js +68 -0
  274. package/packages/cli/src/transpiled-tests.js +92 -0
  275. package/packages/codegen/src/canonical-json.js +31 -0
  276. package/packages/codegen/src/capabilities.js +50 -0
  277. package/packages/codegen/src/code-writer.js +54 -0
  278. package/packages/codegen/src/file-tree.js +25 -0
  279. package/packages/codegen/src/hash.js +6 -0
  280. package/packages/codegen/src/index.js +16 -0
  281. package/packages/codegen/src/lock.js +106 -0
  282. package/packages/conformance/src/case.js +143 -0
  283. package/packages/conformance/src/checks.js +40 -0
  284. package/packages/conformance/src/index.js +3 -0
  285. package/packages/conformance/src/matrix.js +48 -0
  286. package/packages/conformance/src/suite.js +48 -0
  287. package/packages/differ/src/diff.js +500 -0
  288. package/packages/differ/src/index.js +3 -0
  289. package/packages/differ/src/notes.js +112 -0
  290. package/packages/differ/src/support.js +34 -0
  291. package/packages/gen-csharp/src/emit-client.js +397 -0
  292. package/packages/gen-csharp/src/emit-harness.js +333 -0
  293. package/packages/gen-csharp/src/emit-mock.js +111 -0
  294. package/packages/gen-csharp/src/emit-models.js +119 -0
  295. package/packages/gen-csharp/src/emit-webhooks.js +57 -0
  296. package/packages/gen-csharp/src/generate.js +245 -0
  297. package/packages/gen-csharp/src/index.js +5 -0
  298. package/packages/gen-csharp/src/names.js +284 -0
  299. package/packages/gen-go/src/emit-client.js +405 -0
  300. package/packages/gen-go/src/emit-harness.js +294 -0
  301. package/packages/gen-go/src/emit-mock.js +112 -0
  302. package/packages/gen-go/src/emit-models.js +146 -0
  303. package/packages/gen-go/src/emit-webhooks.js +58 -0
  304. package/packages/gen-go/src/generate.js +205 -0
  305. package/packages/gen-go/src/index.js +5 -0
  306. package/packages/gen-go/src/names.js +197 -0
  307. package/packages/gen-java/src/emit-client.js +441 -0
  308. package/packages/gen-java/src/emit-models.js +342 -0
  309. package/packages/gen-java/src/emit-testing.js +123 -0
  310. package/packages/gen-java/src/emit-webhooks.js +70 -0
  311. package/packages/gen-java/src/generate.js +244 -0
  312. package/packages/gen-java/src/index.js +4 -0
  313. package/packages/gen-java/src/names.js +197 -0
  314. package/packages/gen-python/src/emit-client.js +272 -0
  315. package/packages/gen-python/src/emit-models.js +139 -0
  316. package/packages/gen-python/src/emit-testing.js +93 -0
  317. package/packages/gen-python/src/emit-webhooks.js +48 -0
  318. package/packages/gen-python/src/generate.js +237 -0
  319. package/packages/gen-python/src/index.js +2 -0
  320. package/packages/gen-python/src/names.js +161 -0
  321. package/packages/gen-python/src/style.js +67 -0
  322. package/packages/gen-rust/src/emit-client.js +379 -0
  323. package/packages/gen-rust/src/emit-harness.js +278 -0
  324. package/packages/gen-rust/src/emit-mock.js +121 -0
  325. package/packages/gen-rust/src/emit-models.js +117 -0
  326. package/packages/gen-rust/src/emit-webhooks.js +58 -0
  327. package/packages/gen-rust/src/generate.js +243 -0
  328. package/packages/gen-rust/src/index.js +5 -0
  329. package/packages/gen-rust/src/names.js +223 -0
  330. package/packages/gen-typescript/src/emit-client.js +434 -0
  331. package/packages/gen-typescript/src/emit-models.js +93 -0
  332. package/packages/gen-typescript/src/emit-package.js +90 -0
  333. package/packages/gen-typescript/src/emit-testing.js +138 -0
  334. package/packages/gen-typescript/src/emit-webhooks.js +52 -0
  335. package/packages/gen-typescript/src/generate.js +70 -0
  336. package/packages/gen-typescript/src/index.js +3 -0
  337. package/packages/gen-typescript/src/naming.js +64 -0
  338. package/packages/gen-typescript/src/runtime.js +81 -0
  339. package/packages/gen-typescript/src/types.js +136 -0
  340. package/packages/ir/src/api-surface.js +22 -0
  341. package/packages/ir/src/checks.js +52 -0
  342. package/packages/ir/src/index.js +32 -0
  343. package/packages/ir/src/ir.js +214 -0
  344. package/packages/ir/src/pages.js +18 -0
  345. package/packages/ir/src/validate-ir.js +462 -0
  346. package/packages/ir/src/validate-types.js +140 -0
  347. package/packages/kit/src/block-parser.js +196 -0
  348. package/packages/kit/src/index.js +15 -0
  349. package/packages/kit/src/kit-check.js +203 -0
  350. package/packages/kit/src/sources.js +53 -0
  351. package/packages/kit/src/version-policy.js +133 -0
  352. package/packages/kit/src/version-range.js +132 -0
  353. package/packages/openapi/src/import.js +292 -0
  354. package/packages/openapi/src/index.js +1 -0
  355. package/packages/openapi/src/names.js +50 -0
  356. package/packages/openapi/src/schemas.js +264 -0
  357. package/packages/packager/src/archive.js +106 -0
  358. package/packages/packager/src/crate.js +39 -0
  359. package/packages/packager/src/gomodule.js +11 -0
  360. package/packages/packager/src/index.js +9 -0
  361. package/packages/packager/src/maven.js +85 -0
  362. package/packages/packager/src/metadata.js +34 -0
  363. package/packages/packager/src/npm.js +71 -0
  364. package/packages/packager/src/nuget.js +78 -0
  365. package/packages/packager/src/sbom.js +56 -0
  366. package/packages/packager/src/wheel.js +62 -0
  367. package/packages/spec/src/index.js +11 -0
  368. package/packages/spec/src/requirements.js +139 -0
  369. package/packages/transpile/src/ast.js +51 -0
  370. package/packages/transpile/src/check.js +669 -0
  371. package/packages/transpile/src/emit-csharp.js +469 -0
  372. package/packages/transpile/src/emit-go.js +529 -0
  373. package/packages/transpile/src/emit-java.js +360 -0
  374. package/packages/transpile/src/emit-python.js +320 -0
  375. package/packages/transpile/src/emit-rust.js +499 -0
  376. package/packages/transpile/src/errors.js +15 -0
  377. package/packages/transpile/src/index.js +13 -0
  378. package/packages/transpile/src/lexer.js +161 -0
  379. package/packages/transpile/src/parser.js +543 -0
  380. package/packages/transpile/src/tests/ast.js +46 -0
  381. package/packages/transpile/src/tests/parse.js +376 -0
  382. package/packages/transpile/src/tests/translate.js +849 -0
  383. package/packages/transpile/src/transpile.js +57 -0
@@ -0,0 +1,103 @@
1
+ // @requirement SDKL-MOCK-001
2
+ // @requirement SDKL-MOCK-002
3
+ import { test } from "node:test";
4
+ import assert from "node:assert/strict";
5
+ import { HttpRequest } from "../src/http.ts";
6
+ import { asObject, asString, DecodeError } from "../src/models.ts";
7
+ import { FakeClock, MockTransport, OperationMock } from "../src/testing.ts";
8
+
9
+ const BASE = "http://mock.sdkloom.invalid";
10
+
11
+ const decodeOrder = (value: unknown, path: string): { id: string } => {
12
+ const object = asObject(value, path);
13
+ return { ...object, id: asString(object["id"], `${path}.id`) };
14
+ };
15
+
16
+ function get(path: string): HttpRequest {
17
+ return new HttpRequest("GET", `${BASE}${path}`);
18
+ }
19
+
20
+ test("fails a request no route answers, naming method and path", async () => {
21
+ await assert.rejects(new MockTransport().send(get("/x?y=1"), {}), /no mock for GET \/x/);
22
+ });
23
+
24
+ test("routes match path templates and record every call", async () => {
25
+ const transport = new MockTransport();
26
+ const route = transport.route("GET", "/orders/{id}").reply({ status: 200, json: { id: "1" } });
27
+ const response = await transport.send(get("/orders/42"), {});
28
+
29
+ assert.equal(response.status, 200);
30
+ assert.deepEqual(await response.json(), { id: "1" });
31
+ assert.equal(route.calls.length, 1);
32
+ assert.equal(transport.calls[0]?.url, `${BASE}/orders/42`);
33
+ await assert.rejects(transport.send(get("/orders/42/items"), {}), /no mock for GET \/orders\/42\/items/);
34
+ });
35
+
36
+ test("answers come in order and the last one repeats", async () => {
37
+ const transport = new MockTransport();
38
+ transport.route("GET", "/x").reply({ status: 503 }).reply({ status: 200 });
39
+ const statuses: number[] = [];
40
+ for (let index = 0; index < 3; index += 1) statuses.push((await transport.send(get("/x"), {})).status);
41
+
42
+ assert.deepEqual(statuses, [503, 200, 200]);
43
+ });
44
+
45
+ test("a route without answers fails clearly", async () => {
46
+ const transport = new MockTransport();
47
+ transport.route("GET", "/orders/{id}");
48
+
49
+ await assert.rejects(transport.send(get("/orders/1"), {}), /mock for GET \/orders\/\{id\} has no answer/);
50
+ });
51
+
52
+ test("operation mocks validate values, fail, throw and record calls", async () => {
53
+ const transport = new MockTransport();
54
+ const mock = new OperationMock("getOrder", transport.route("GET", "/orders/{id}"), decodeOrder);
55
+
56
+ assert.throws(() => mock.returns({ id: 1 } as never), (error: unknown) => error instanceof DecodeError && error.path === "$.id");
57
+ assert.equal(mock.then, mock);
58
+ mock.returns({ id: "a" }).then.fails(404, { message: "no" }).then.throws(new Error("boom"));
59
+
60
+ assert.deepEqual(await (await transport.send(get("/orders/1"), {})).json(), { id: "a" });
61
+ const failed = await transport.send(get("/orders/1"), {});
62
+ assert.equal(failed.status, 404);
63
+ assert.deepEqual(await failed.json(), { message: "no" });
64
+ await assert.rejects(transport.send(get("/orders/1"), {}), /boom/);
65
+ assert.equal(mock.calls.length, 3);
66
+ });
67
+
68
+ test("when() answers only the requests it matches", async () => {
69
+ const transport = new MockTransport();
70
+ const mock = new OperationMock("getOrder", transport.route("GET", "/orders/{id}"), decodeOrder);
71
+ mock.returns({ id: "normal" });
72
+ mock.when((request) => request.url.endsWith("/special")).returns({ id: "special" });
73
+
74
+ assert.deepEqual(await (await transport.send(get("/orders/special"), {})).json(), { id: "special" });
75
+ assert.deepEqual(await (await transport.send(get("/orders/1"), {})).json(), { id: "normal" });
76
+ });
77
+
78
+ test("the fake clock moves only when slept or advanced", async () => {
79
+ const clock = new FakeClock();
80
+ assert.equal(clock.now(), 0);
81
+ await clock.sleep(100);
82
+ clock.advance(50);
83
+ assert.equal(clock.now(), 150);
84
+ });
85
+
86
+ test("a route with answers beats a later one without, e.g. /users/me next to /users/{id}", async () => {
87
+ const transport = new MockTransport();
88
+ transport.route("GET", "/users/me").reply({ status: 200, json: { me: true } });
89
+ const byId = transport.route("GET", "/users/{id}");
90
+
91
+ assert.equal((await transport.send(get("/users/me"), {})).status, 200);
92
+ await assert.rejects(transport.send(get("/users/7"), {}), /mock for GET \/users\/\{id\} has no answer/);
93
+ byId.reply({ status: 204 });
94
+ assert.equal((await transport.send(get("/users/me"), {})).status, 204, "the later route wins once both have answers");
95
+ });
96
+
97
+ test("a {+name} route matches one or more segments", async () => {
98
+ const transport = new MockTransport();
99
+ transport.route("GET", "/files/{+path}/meta").reply({ status: 200 });
100
+
101
+ assert.equal((await transport.send(get("/files/a/b%20c/meta"), {})).status, 200);
102
+ await assert.rejects(transport.send(get("/files/meta"), {}), /no mock/);
103
+ });
@@ -0,0 +1,127 @@
1
+ // @requirement SDKL-HTTP-004
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
5
+ import { TransportError } from "../src/errors.ts";
6
+ import { HttpRequest } from "../src/http.ts";
7
+ import { fetchTransport } from "../src/transport.ts";
8
+
9
+ type Handler = (request: IncomingMessage, response: ServerResponse) => void;
10
+
11
+ async function withServer(handler: Handler, run: (baseUrl: string) => Promise<void>): Promise<void> {
12
+ const server = createServer(handler);
13
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", () => resolve()));
14
+ const address = server.address();
15
+ const port = typeof address === "object" && address !== null ? address.port : 0;
16
+ try {
17
+ await run(`http://127.0.0.1:${port}`);
18
+ } finally {
19
+ server.closeAllConnections();
20
+ await new Promise<void>((resolve) => server.close(() => resolve()));
21
+ }
22
+ }
23
+
24
+ function reason(expected: TransportError["reason"]): (error: unknown) => boolean {
25
+ return (error) => error instanceof TransportError && error.reason === expected;
26
+ }
27
+
28
+ test("sends method, headers and body; returns status, headers and body", async () => {
29
+ await withServer(
30
+ (request, response) => {
31
+ const chunks: Uint8Array[] = [];
32
+ request.on("data", (chunk: Uint8Array) => chunks.push(chunk));
33
+ request.on("end", () => {
34
+ response.writeHead(201, { "x-echo": String(request.headers["x-test"]), "x-method": String(request.method) });
35
+ response.end(`got:${chunks.map((chunk) => new TextDecoder().decode(chunk)).join("")}`);
36
+ });
37
+ },
38
+ async (baseUrl) => {
39
+ const request = new HttpRequest("POST", `${baseUrl}/echo`, [["x-test", "1"]], new TextEncoder().encode("hi"));
40
+ const response = await fetchTransport()(request, {});
41
+
42
+ assert.equal(response.status, 201);
43
+ assert.equal(response.header("x-echo"), "1");
44
+ assert.equal(response.header("x-method"), "POST");
45
+ assert.equal(await response.text(), "got:hi");
46
+ },
47
+ );
48
+ });
49
+
50
+ test("collects a stream body before sending it", async () => {
51
+ async function* body(): AsyncGenerator<Uint8Array> {
52
+ yield new TextEncoder().encode("a");
53
+ yield new TextEncoder().encode("b");
54
+ }
55
+ await withServer(
56
+ (request, response) => {
57
+ const chunks: Uint8Array[] = [];
58
+ request.on("data", (chunk: Uint8Array) => chunks.push(chunk));
59
+ request.on("end", () => response.end(chunks.map((chunk) => new TextDecoder().decode(chunk)).join("")));
60
+ },
61
+ async (baseUrl) => {
62
+ const response = await fetchTransport()(new HttpRequest("PUT", `${baseUrl}/`, [], body()), {});
63
+ assert.equal(await response.text(), "ab");
64
+ },
65
+ );
66
+ });
67
+
68
+ test("reports a timeout", async () => {
69
+ await withServer(
70
+ () => {
71
+ /* never answers */
72
+ },
73
+ async (baseUrl) => {
74
+ await assert.rejects(fetchTransport()(new HttpRequest("GET", `${baseUrl}/slow`), { timeoutMs: 50 }), reason("timeout"));
75
+ },
76
+ );
77
+ });
78
+
79
+ test("reports a cancellation", async () => {
80
+ await withServer(
81
+ () => {
82
+ /* never answers */
83
+ },
84
+ async (baseUrl) => {
85
+ const controller = new AbortController();
86
+ const pending = fetchTransport()(new HttpRequest("GET", `${baseUrl}/slow`), { signal: controller.signal });
87
+ controller.abort();
88
+ await assert.rejects(pending, reason("aborted"));
89
+ await assert.rejects(fetchTransport()(new HttpRequest("GET", `${baseUrl}/slow`), { signal: controller.signal }), reason("aborted"));
90
+ },
91
+ );
92
+ });
93
+
94
+ test("reports a network failure", async () => {
95
+ await assert.rejects(fetchTransport()(new HttpRequest("GET", "http://127.0.0.1:1/"), {}), reason("network"));
96
+ });
97
+
98
+ test("stream: a successful body arrives chunk by chunk, past the timeout; an error body is still read whole", async () => {
99
+ let release: () => void = () => undefined;
100
+ const later = new Promise<void>((resolve) => (release = resolve));
101
+ await withServer(
102
+ (request, response) => {
103
+ if (request.url === "/missing") {
104
+ response.writeHead(404, { "content-type": "application/json" });
105
+ response.end('{"error":"no"}');
106
+ return;
107
+ }
108
+ response.writeHead(200, { "content-type": "text/event-stream" });
109
+ response.write("data: one\n\n");
110
+ void later.then(() => response.end("data: two\n\n"));
111
+ },
112
+ async (baseUrl) => {
113
+ const streamed = await fetchTransport()(new HttpRequest("GET", `${baseUrl}/events`), { stream: true, timeoutMs: 50 });
114
+ const chunks = streamed.chunks();
115
+ const first = await chunks.next();
116
+ await new Promise<void>((resolve) => setTimeout(() => resolve(), 80));
117
+ release();
118
+ const rest: string[] = [];
119
+ for await (const chunk of chunks) rest.push(new TextDecoder().decode(chunk));
120
+ const missing = await fetchTransport()(new HttpRequest("GET", `${baseUrl}/missing`), { stream: true });
121
+
122
+ assert.equal(new TextDecoder().decode(first.value ?? new Uint8Array()), "data: one\n\n");
123
+ assert.equal(rest.join(""), "data: two\n\n");
124
+ assert.deepEqual([missing.status, await missing.json()], [404, { error: "no" }]);
125
+ },
126
+ );
127
+ });
@@ -0,0 +1,31 @@
1
+ // @requirement SDKL-WAIT-001
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { FakeClock } from "../src/testing.ts";
5
+ import { waitUntil, WaitTimeoutError } from "../src/wait.ts";
6
+
7
+ test("polls on the clock until the result is done, and returns a result that is done at once without polling", async () => {
8
+ const clock = new FakeClock();
9
+ const states = ["running", "running", "done"];
10
+ const polled: string[] = [];
11
+ const result = await waitUntil({ status: "pending" }, async () => {
12
+ const status = states.shift() ?? "done";
13
+ polled.push(status);
14
+ return { status };
15
+ }, (current) => current.status === "done", clock, 500, 10_000);
16
+ const immediate = await waitUntil({ status: "done" }, async (): Promise<{ status: string }> => {
17
+ throw new Error("polled");
18
+ }, (current) => current.status === "done", clock, 500, 10_000);
19
+
20
+ assert.deepEqual([result, polled, clock.now()], [{ status: "done" }, ["running", "running", "done"], 1500]);
21
+ assert.deepEqual(immediate, { status: "done" });
22
+ });
23
+
24
+ test("fails with WaitTimeoutError, keeping the last result, when the next poll would pass the deadline", async () => {
25
+ const clock = new FakeClock();
26
+ let polls = 0;
27
+ const waiting = waitUntil({ status: "pending" }, async () => ({ status: `running ${++polls}` }), () => false, clock, 400, 1000);
28
+
29
+ await assert.rejects(waiting, (error: unknown) => error instanceof WaitTimeoutError && error.name === "WaitTimeoutError" && (error.last as { status: string }).status === "running 2");
30
+ assert.equal(clock.now(), 800);
31
+ });
@@ -0,0 +1,53 @@
1
+ // @requirement SDKL-HOOK-001
2
+ import { test } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { hmacSha256, sha256, verifyWebhook, WebhookSignatureError, type WebhookSignature } from "../src/webhooks.ts";
5
+
6
+ const hex = (bytes: Uint8Array): string => [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
7
+ const text = (value: string): Uint8Array => new TextEncoder().encode(value);
8
+
9
+ test("SHA-256 and HMAC-SHA256 match FIPS 180 and RFC 4231", () => {
10
+ assert.equal(hex(sha256(text("abc"))), "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
11
+ assert.equal(hex(sha256(new Uint8Array(1_000_000).fill(0x61))), "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0");
12
+ assert.equal(hex(hmacSha256(new Uint8Array(20).fill(0x0b), text("Hi There"))), "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7");
13
+ assert.equal(hex(hmacSha256(text("Jefe"), text("what do ya want for nothing?"))), "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843");
14
+ assert.equal(hex(hmacSha256(new Uint8Array(131).fill(0xaa), text("Test Using Larger Than Block-Size Key - Hash Key First"))), "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54");
15
+ });
16
+
17
+ const STANDARD: WebhookSignature = {
18
+ header: "webhook-signature",
19
+ encoding: "base64",
20
+ prefix: "v1,",
21
+ separator: " ",
22
+ signed: "{webhook-id}.{webhook-timestamp}.{body}",
23
+ timestamp: { header: "webhook-timestamp", toleranceSeconds: 300 },
24
+ secret: "base64",
25
+ secretPrefix: "whsec_",
26
+ };
27
+ const SECRET = "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw";
28
+ const BODY = '{"test": 2432232314}';
29
+ const HEADERS = { "Webhook-Id": "msg_p5jXN8AQM9LWM0D4loKWxJek", "webhook-timestamp": "1614265330", "webhook-signature": "v1,bad v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=" };
30
+
31
+ test("verifies the Standard Webhooks example: any signature in the list, header names in any case", () => {
32
+ assert.doesNotThrow(() => verifyWebhook(STANDARD, BODY, HEADERS, SECRET, 1614265330));
33
+ assert.doesNotThrow(() => verifyWebhook(STANDARD, text(BODY), new Headers(HEADERS), SECRET, 1614265330 + 300));
34
+ });
35
+
36
+ test("refuses a changed body, a wrong secret, an old or future timestamp and missing headers", () => {
37
+ const refuses = (run: () => void, message: RegExp): void => assert.throws(run, (error: unknown) => error instanceof WebhookSignatureError && error.name === "WebhookSignatureError" && message.test(error.message));
38
+ refuses(() => verifyWebhook(STANDARD, BODY.replace("2", "3"), HEADERS, SECRET, 1614265330), /no signature matches/);
39
+ refuses(() => verifyWebhook(STANDARD, BODY, HEADERS, "whsec_AAAA", 1614265330), /no signature matches/);
40
+ refuses(() => verifyWebhook(STANDARD, BODY, HEADERS, SECRET, 1614265330 + 301), /more than 300 s from now/);
41
+ refuses(() => verifyWebhook(STANDARD, BODY, HEADERS, SECRET, 1614265330 - 301), /more than 300 s from now/);
42
+ refuses(() => verifyWebhook(STANDARD, BODY, { ...HEADERS, "webhook-signature": undefined }, SECRET, 1614265330), /missing webhook-signature header/);
43
+ refuses(() => verifyWebhook(STANDARD, BODY, { "webhook-signature": "v1,x" }, SECRET, 1614265330), /missing or invalid webhook-timestamp header/);
44
+ });
45
+
46
+ test("verifies a hex signature of the body alone with a text secret (GitHub style)", () => {
47
+ const github: WebhookSignature = { header: "x-hub-signature-256", encoding: "hex", prefix: "sha256=", signed: "{body}", secret: "text" };
48
+ const body = '{"zen":"Design for failure."}';
49
+ const signature = "sha256=" + hex(hmacSha256(text("It is a secret"), text(body)));
50
+
51
+ assert.doesNotThrow(() => verifyWebhook(github, body, { "x-hub-signature-256": signature }, "It is a secret", 0));
52
+ assert.throws(() => verifyWebhook(github, body, { "x-hub-signature-256": signature.replace("sha256=", "sha1=") }, "It is a secret", 0), (error: unknown) => error instanceof WebhookSignatureError);
53
+ });
@@ -0,0 +1,15 @@
1
+ {
2
+ "default": {
3
+ "range": ">=18",
4
+ "test": [
5
+ "18",
6
+ "24"
7
+ ]
8
+ },
9
+ "notes": {
10
+ "18": {
11
+ "text": "End of life since 2025-04-30 in the Node.js release schedule.",
12
+ "source": "https://github.com/nodejs/Release/blob/main/schedule.json"
13
+ }
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "sdkloom",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Write your API SDK once in TypeScript: zero-dependency SDKs for TypeScript, Python, Java, Go, Rust and C#, tested to behave the same. OpenAPI import, breaking-change detection per language, packaging for every registry.",
4
+ "bin": {
5
+ "sdkloom": "packages/cli/src/main.js"
6
+ },
7
+ "exports": {
8
+ ".": "./packages/cli/src/run.js"
9
+ },
10
+ "dependencies": {
11
+ "@sdkloom/core": "0.1.0"
12
+ },
13
+ "version": "0.1.0",
14
+ "type": "module",
15
+ "license": "Apache-2.0",
16
+ "homepage": "https://sdkloom.atanur.dev",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Atanur/sdkloom.git"
20
+ },
21
+ "bugs": "https://github.com/Atanur/sdkloom/issues",
22
+ "keywords": [
23
+ "sdk",
24
+ "sdk-generator",
25
+ "api-client",
26
+ "openapi",
27
+ "openapi-generator",
28
+ "code-generation",
29
+ "typescript",
30
+ "python",
31
+ "java",
32
+ "go",
33
+ "rust",
34
+ "csharp"
35
+ ],
36
+ "engines": {
37
+ "node": ">=24"
38
+ }
39
+ }
@@ -0,0 +1,16 @@
1
+ // Recipe: apiKeyHeader — sends an API key in a header, `x-api-key` unless you choose another one.
2
+ // Added by `sdkloom recipe add apiKeyHeader`. This file is yours now: change it as you need.
3
+
4
+ import { middleware, t } from "@sdkloom/core";
5
+
6
+ export const apiKeyHeader = middleware(
7
+ "apiKeyHeader",
8
+ {
9
+ doc: "Sends the API key in a header.",
10
+ config: {
11
+ apiKey: t.secret({ doc: "API key." }),
12
+ apiKeyHeader: t.optional(t.string({ doc: 'Header name. Defaults to "x-api-key".' })),
13
+ },
14
+ },
15
+ async (req, next, ctx) => next(req.withHeader(ctx.config.apiKeyHeader ?? "x-api-key", ctx.config.apiKey)),
16
+ );
@@ -0,0 +1,16 @@
1
+ // Recipe: apiVersionHeader — pins the API version the SDK was written for, Stripe-Version style.
2
+ // Added by `sdkloom recipe add apiVersionHeader`. This file is yours now: change it as you need.
3
+
4
+ import { middleware, t } from "@sdkloom/core";
5
+
6
+ export const apiVersionHeader = middleware(
7
+ "apiVersionHeader",
8
+ {
9
+ doc: "Sends the API version in a header.",
10
+ config: {
11
+ apiVersion: t.string({ doc: 'API version, e.g. "2026-12-05".' }),
12
+ apiVersionHeader: t.optional(t.string({ doc: 'Header name. Defaults to "api-version".' })),
13
+ },
14
+ },
15
+ async (req, next, ctx) => next(req.withHeader(ctx.config.apiVersionHeader ?? "api-version", ctx.config.apiVersion)),
16
+ );
@@ -0,0 +1,13 @@
1
+ // Recipe: basic — HTTP Basic authentication (RFC 7617): `Authorization: Basic base64(user:password)`.
2
+ // Added by `sdkloom recipe add basic`. This file is yours now: change it as you need.
3
+
4
+ import { middleware, t } from "@sdkloom/core";
5
+
6
+ export const basic = middleware(
7
+ "basic",
8
+ {
9
+ doc: "Sends the user name and password with HTTP Basic authentication.",
10
+ config: { username: t.string({ doc: "User name." }), password: t.secret({ doc: "Password." }) },
11
+ },
12
+ async (req, next, ctx) => next(req.withHeader("authorization", `Basic ${btoa(`${ctx.config.username}:${ctx.config.password}`)}`)),
13
+ );
@@ -0,0 +1,10 @@
1
+ // Recipe: bearer — sends `Authorization: Bearer <token>` on every request.
2
+ // Added by `sdkloom recipe add bearer`. This file is yours now: change it as you need.
3
+
4
+ import { middleware, t } from "@sdkloom/core";
5
+
6
+ export const bearer = middleware(
7
+ "bearer",
8
+ { doc: "Sends the token as `Authorization: Bearer <token>`.", config: { token: t.secret({ doc: "API token." }) } },
9
+ async (req, next, ctx) => next(req.withHeader("authorization", `Bearer ${ctx.config.token}`)),
10
+ );
@@ -0,0 +1,23 @@
1
+ // Recipe: hmacSign — signs every request with HMAC-SHA256 over its timestamp, method, URL and body.
2
+ // Added by `sdkloom recipe add hmacSign`. This file is yours now: change the signed text and headers to what your API
3
+ // expects (the signed text here is "<timestamp>\n<METHOD>\n<url>\n<body>", the signature lower-case hex).
4
+
5
+ import { hmacSha256Hex, middleware, t } from "@sdkloom/core";
6
+
7
+ export const hmacSign = middleware(
8
+ "hmacSign",
9
+ {
10
+ doc: "Signs each request with HMAC-SHA256 and sends the signature and its timestamp in headers.",
11
+ config: {
12
+ signingSecret: t.secret({ doc: "The shared secret the API gave you." }),
13
+ signatureHeader: t.optional(t.string({ doc: 'Header for the signature. Defaults to "x-signature".' })),
14
+ timestampHeader: t.optional(t.string({ doc: 'Header for the Unix time in seconds. Defaults to "x-timestamp".' })),
15
+ },
16
+ },
17
+ async (req, next, ctx) => {
18
+ const timestamp = String(Math.floor(ctx.clock.now() / 1000));
19
+ const signed = timestamp + "\n" + req.method + "\n" + req.url + "\n" + req.text();
20
+ const signature = hmacSha256Hex(ctx.config.signingSecret, signed);
21
+ return next(req.withHeader(ctx.config.timestampHeader ?? "x-timestamp", timestamp).withHeader(ctx.config.signatureHeader ?? "x-signature", signature));
22
+ },
23
+ );
@@ -0,0 +1,19 @@
1
+ // Recipe: idempotencyKey — gives every POST and PATCH a random Idempotency-Key, so a retried create runs once.
2
+ // Added by `sdkloom recipe add idempotencyKey`. This file is yours now: change it as you need.
3
+ // Put it before retry in `use`: the key is set once and every retry of the call sends the same one.
4
+
5
+ import { middleware, randomUUID, t } from "@sdkloom/core";
6
+
7
+ export const idempotencyKey = middleware(
8
+ "idempotencyKey",
9
+ {
10
+ doc: "Sends a random Idempotency-Key with every POST and PATCH that has none, so retrying it is safe.",
11
+ config: { idempotencyHeader: t.optional(t.string({ doc: 'Header name. Defaults to "idempotency-key".' })) },
12
+ },
13
+ async (req, next, ctx) => {
14
+ const name = ctx.config.idempotencyHeader ?? "idempotency-key";
15
+ if (req.method !== "POST" && req.method !== "PATCH") return next(req);
16
+ if (req.header(name) !== undefined) return next(req);
17
+ return next(req.withHeader(name, randomUUID()));
18
+ },
19
+ );
@@ -0,0 +1,50 @@
1
+ // Recipe: oauthClientCredentials — OAuth 2.0 client credentials (RFC 6749 section 4.4). Fetches an access token from
2
+ // tokenUrl with the client's id and secret (HTTP Basic, which every authorization server must accept, section 2.3.1),
3
+ // keeps it until 30 seconds before it expires, sends it as a bearer token, and on a 401 fetches a new one and tries once
4
+ // more. The token is kept per client, so every call made through one client shares it.
5
+ // Added by `sdkloom recipe add oauthClientCredentials`. This file is yours now: change it as you need.
6
+
7
+ import { middleware, t } from "@sdkloom/core";
8
+
9
+ export const oauthClientCredentials = middleware(
10
+ "oauthClientCredentials",
11
+ {
12
+ doc: "Gets OAuth 2.0 access tokens with the client credentials grant and sends them as bearer tokens.",
13
+ config: {
14
+ clientId: t.string({ doc: "OAuth client id." }),
15
+ clientSecret: t.secret({ doc: "OAuth client secret." }),
16
+ tokenUrl: t.string({ doc: "The authorization server's token endpoint." }),
17
+ scope: t.optional(t.string({ doc: "Space-separated scopes to ask for; the server's default when not set." })),
18
+ },
19
+ },
20
+ async (req, next, ctx) => {
21
+ for (let attempt = 1; attempt <= 2; attempt += 1) {
22
+ let token = ctx.state.get("oauthClientCredentials.token");
23
+ if (token === undefined) {
24
+ // The client id and secret are form-encoded before Basic encoding (RFC 6749 section 2.3.1).
25
+ const credentials = btoa(encodeURIComponent(ctx.config.clientId) + ":" + encodeURIComponent(ctx.config.clientSecret));
26
+ let form = "grant_type=client_credentials";
27
+ if (ctx.config.scope !== undefined) form += "&scope=" + encodeURIComponent(ctx.config.scope);
28
+ const tokenRequest = ctx
29
+ .request("POST", ctx.config.tokenUrl)
30
+ .withHeader("authorization", `Basic ${credentials}`)
31
+ .withHeader("content-type", "application/x-www-form-urlencoded")
32
+ .withHeader("accept", "application/json")
33
+ .withBody(form);
34
+ const answer = await ctx.send(tokenRequest);
35
+ if (answer.status !== 200) throw new Error(`oauthClientCredentials: the token endpoint answered ${answer.status}: ${await answer.text()}`);
36
+ const granted = await answer.json();
37
+ token = granted.access_token;
38
+ if (token === undefined) throw new Error("oauthClientCredentials: the token response has no access_token");
39
+ // expires_in is optional (section 5.1); without it the token is kept for an hour.
40
+ const lifetimeSeconds = Number(String(granted.expires_in ?? 3600));
41
+ ctx.state.set("oauthClientCredentials.token", token, { ttlMs: Math.max(0, Math.floor((lifetimeSeconds - 30) * 1000)) });
42
+ }
43
+ const response = await next(req.withHeader("authorization", `Bearer ${token}`));
44
+ if (response.status !== 401 || attempt === 2) return response;
45
+ // The token was revoked or expired early: forget it and try once more with a new one.
46
+ ctx.state.delete("oauthClientCredentials.token");
47
+ }
48
+ throw new Error("oauthClientCredentials: no response");
49
+ },
50
+ );
@@ -0,0 +1,42 @@
1
+ // Recipe: retry — retries 429 and 5xx responses with exponential backoff and full jitter, honours `Retry-After`
2
+ // (in seconds, capped like every wait at retryMaxWaitMs), and only retries requests that are safe to repeat: everything except POST and PATCH, unless the
3
+ // request carries an `idempotency-key` header.
4
+ // Added by `sdkloom recipe add retry`. This file is yours now: change it as you need.
5
+
6
+ import { middleware, t } from "@sdkloom/core";
7
+
8
+ export const retry = middleware(
9
+ "retry",
10
+ {
11
+ doc: "Retries 429 and 5xx responses with exponential backoff.",
12
+ config: {
13
+ maxRetries: t.optional(t.int({ doc: "Retries after the first attempt. Defaults to 2." })),
14
+ retryBaseMs: t.optional(t.int({ doc: "Wait before the first retry, doubled for each one. Defaults to 100." })),
15
+ retryJitter: t.optional(t.bool({ doc: "Wait a random part of the backoff, so clients do not retry in step. Defaults to true." })),
16
+ retryMaxWaitMs: t.optional(t.int({ doc: "Longest wait before a retry, also for Retry-After. Defaults to 30000." })),
17
+ },
18
+ },
19
+ async (req, next, ctx) => {
20
+ const maxRetries = ctx.config.maxRetries ?? 2;
21
+ const baseMs = ctx.config.retryBaseMs ?? 100;
22
+ const jitter = ctx.config.retryJitter ?? true;
23
+ const maxWaitMs = ctx.config.retryMaxWaitMs ?? 30000;
24
+ const repeatable = (req.method !== "POST" && req.method !== "PATCH") || req.header("idempotency-key") !== undefined;
25
+ let response = await next(req);
26
+ for (let attempt = 1; repeatable && attempt <= maxRetries && (response.status === 429 || response.status >= 500); attempt += 1) {
27
+ let waitMs = baseMs * 2 ** (attempt - 1);
28
+ const retryAfter = response.header("retry-after") ?? "";
29
+ const seconds = Number(retryAfter);
30
+ if (retryAfter !== "" && seconds >= 0) {
31
+ waitMs = seconds * 1000;
32
+ } else if (jitter) {
33
+ waitMs = Math.random() * waitMs;
34
+ }
35
+ waitMs = Math.min(waitMs, maxWaitMs);
36
+ ctx.emit("retry", { operation: ctx.operation.name, attempt, status: response.status, waitMs: Math.floor(waitMs) });
37
+ await ctx.clock.sleep(waitMs);
38
+ response = await next(req);
39
+ }
40
+ return response;
41
+ },
42
+ );
@@ -0,0 +1,12 @@
1
+ // Recipe: timing — emits `http.request` with the operation, status and duration of every call.
2
+ // Connect it to your logs or metrics with the client's `onEvent` option.
3
+ // Added by `sdkloom recipe add timing`. This file is yours now: change it as you need.
4
+
5
+ import { middleware } from "@sdkloom/core";
6
+
7
+ export const timing = middleware("timing", { doc: "Emits http.request with the status and duration of every call." }, async (req, next, ctx) => {
8
+ const start = ctx.clock.now();
9
+ const response = await next(req);
10
+ ctx.emit("http.request", { operation: ctx.operation.name, method: req.method, status: response.status, ms: ctx.clock.now() - start });
11
+ return response;
12
+ });
@@ -0,0 +1,8 @@
1
+ // Recipe: userAgent — identifies the SDK in `User-Agent`, e.g. `acme-payments/1.2.0 (python)`.
2
+ // Added by `sdkloom recipe add userAgent`. This file is yours now: change it as you need.
3
+
4
+ import { middleware } from "@sdkloom/core";
5
+
6
+ export const userAgent = middleware("userAgent", { doc: "Identifies the SDK, its version and language in User-Agent." }, async (req, next, ctx) =>
7
+ next(req.withHeader("user-agent", `${ctx.sdk.name}/${ctx.sdk.version} (${ctx.sdk.language})`)),
8
+ );