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.
- package/LICENSE +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"default": {
|
|
3
|
+
"range": ">=3.8",
|
|
4
|
+
"test": [
|
|
5
|
+
"3.8",
|
|
6
|
+
"3.15"
|
|
7
|
+
],
|
|
8
|
+
"strategies": {
|
|
9
|
+
"syntax": "py3"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"variants": {
|
|
13
|
+
"py27": {
|
|
14
|
+
"range": ">=2.7 <3",
|
|
15
|
+
"test": [
|
|
16
|
+
"2.7"
|
|
17
|
+
],
|
|
18
|
+
"strategies": {
|
|
19
|
+
"syntax": "py27"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"notes": {
|
|
24
|
+
"2.7": {
|
|
25
|
+
"text": "End of life: \"Support officially stopped January 1 2020\". The transport needs 2.7.9 or later, the first 2.7 release with ssl.create_default_context (TLS 1.2, SNI and certificate checks).",
|
|
26
|
+
"source": "https://peps.python.org/pep-0373/"
|
|
27
|
+
},
|
|
28
|
+
"3.8": {
|
|
29
|
+
"text": "End of life since 2024-10-07.",
|
|
30
|
+
"source": "https://devguide.python.org/versions/"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// sdkloom Rust kit: calling one operation.
|
|
2
|
+
|
|
3
|
+
use super::context::{Clock, Context, EventListener, OperationInfo, SdkInfo, State};
|
|
4
|
+
use super::errors::{Error, ErrorFactory};
|
|
5
|
+
use super::http::{build_url, scalar, Request, Response};
|
|
6
|
+
use super::json::Json;
|
|
7
|
+
use super::transport::{SendOptions, Transport};
|
|
8
|
+
use std::collections::HashMap;
|
|
9
|
+
use std::sync::Arc;
|
|
10
|
+
|
|
11
|
+
// @block client.call
|
|
12
|
+
// @summary Sends one operation: refuses one newer than the pinned API version, builds URL, headers (with the API version) and body, runs the middleware chain, sends it and turns a non-2xx response into the declared error.
|
|
13
|
+
// @versions >=1.70
|
|
14
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.5
|
|
15
|
+
// @quote [1] "The 4xx (Client Error) class of status code indicates that the client seems to have erred."
|
|
16
|
+
// @source [2] https://doc.rust-lang.org/std/sync/struct.Arc.html
|
|
17
|
+
// @quote [2] "A thread-safe reference-counting pointer."
|
|
18
|
+
// @retrieved 2026-12-05
|
|
19
|
+
// @tests tests/client.rs
|
|
20
|
+
// @requirement SDKL-ERR-001
|
|
21
|
+
// @requirement SDKL-PIPE-001
|
|
22
|
+
|
|
23
|
+
/// Sends a request on to the rest of the chain.
|
|
24
|
+
pub type Next<'a> = &'a dyn Fn(Request) -> Result<Response, Error>;
|
|
25
|
+
|
|
26
|
+
/// Wraps every call: change the request, call next zero or more times, change the response.
|
|
27
|
+
pub type Middleware = Arc<dyn Fn(Request, Next, &Context) -> Result<Response, Error> + Send + Sync>;
|
|
28
|
+
|
|
29
|
+
/// A middleware with its configuration bound.
|
|
30
|
+
#[derive(Clone)]
|
|
31
|
+
pub struct MiddlewareEntry {
|
|
32
|
+
pub name: String,
|
|
33
|
+
pub run: Middleware,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Binds a middleware function to its configuration.
|
|
37
|
+
pub fn entry(name: &str, middleware: fn(Request, Next, &Context) -> Result<Response, Error>, config: Vec<(String, Json)>) -> MiddlewareEntry {
|
|
38
|
+
MiddlewareEntry { name: name.to_string(), run: Arc::new(move |request, next, ctx| middleware(request, next, &ctx.with_config(config.clone()))) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// What a request body or result is.
|
|
42
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
43
|
+
pub enum Kind {
|
|
44
|
+
Json,
|
|
45
|
+
Bytes,
|
|
46
|
+
Stream,
|
|
47
|
+
/// Server-sent events, read with EventStream.
|
|
48
|
+
Events,
|
|
49
|
+
/// A multipart/form-data body (MultipartForm::to_body).
|
|
50
|
+
Multipart,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// What generated code knows about one operation.
|
|
54
|
+
pub struct OperationSpec {
|
|
55
|
+
pub name: &'static str,
|
|
56
|
+
pub method: &'static str,
|
|
57
|
+
pub path: &'static str,
|
|
58
|
+
pub body: Option<Kind>,
|
|
59
|
+
pub result: Option<Kind>,
|
|
60
|
+
pub errors: &'static [(u16, ErrorFactory)],
|
|
61
|
+
pub uses: &'static [&'static str],
|
|
62
|
+
/// The first API version that has the operation; None for every version.
|
|
63
|
+
pub since: Option<&'static str>,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// One call's parameters; Null query and header values are left out.
|
|
67
|
+
#[derive(Default)]
|
|
68
|
+
pub struct Args<'a> {
|
|
69
|
+
pub path: Vec<(&'a str, Json)>,
|
|
70
|
+
pub query: Vec<(&'a str, Json)>,
|
|
71
|
+
pub headers: Vec<(&'a str, Json)>,
|
|
72
|
+
pub body: Option<Vec<u8>>,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Changes one call.
|
|
76
|
+
#[derive(Clone, Debug, Default)]
|
|
77
|
+
pub struct CallOptions {
|
|
78
|
+
pub timeout_ms: Option<i64>,
|
|
79
|
+
pub headers: Vec<(String, String)>,
|
|
80
|
+
pub base_url: Option<String>,
|
|
81
|
+
/// Called instead of the URL the path and query make (the next page a Link header named); see resolve_url.
|
|
82
|
+
pub url: Option<String>,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Everything a client shares between calls. Thread-safe.
|
|
86
|
+
#[derive(Clone)]
|
|
87
|
+
pub struct Runtime {
|
|
88
|
+
pub base_url: String,
|
|
89
|
+
pub transport: Arc<dyn Transport>,
|
|
90
|
+
pub clock: Arc<dyn Clock>,
|
|
91
|
+
pub state: Arc<State>,
|
|
92
|
+
pub middleware: Vec<MiddlewareEntry>,
|
|
93
|
+
pub registry: HashMap<String, MiddlewareEntry>,
|
|
94
|
+
pub user_middleware: Vec<MiddlewareEntry>,
|
|
95
|
+
pub listeners: Vec<EventListener>,
|
|
96
|
+
pub timeout_ms: Option<i64>,
|
|
97
|
+
pub sdk: SdkInfo,
|
|
98
|
+
/// The API version the client is pinned to, or None when the API has none.
|
|
99
|
+
pub api_version: Option<ApiVersion>,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// The API version a client is pinned to (value), the header that carries it and every version, oldest first.
|
|
103
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
104
|
+
pub struct ApiVersion {
|
|
105
|
+
pub header: String,
|
|
106
|
+
pub value: String,
|
|
107
|
+
pub values: Vec<String>,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
impl ApiVersion {
|
|
111
|
+
/// Refuses an operation newer than the pinned version, or a version the SDK does not know.
|
|
112
|
+
pub fn check(&self, operation: &str, since: Option<&str>) -> Result<(), Error> {
|
|
113
|
+
let pinned = self.values.iter().position(|value| *value == self.value).ok_or_else(|| Error::Argument(format!("unknown API version {}; this SDK knows {}", self.value, self.values.join(", "))))?;
|
|
114
|
+
if let Some(since) = since {
|
|
115
|
+
if self.values.iter().position(|value| value == since).map(|at| at > pinned).unwrap_or(false) {
|
|
116
|
+
return Err(Error::Argument(format!("{} needs API version {} or later; this client uses {}", operation, since, self.value)));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
Ok(())
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// A call's decoded data and the response it came from.
|
|
124
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
125
|
+
pub struct RawResult<T> {
|
|
126
|
+
pub data: T,
|
|
127
|
+
pub response: Response,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fn build_request(runtime: &Runtime, spec: &OperationSpec, args: Args, options: &CallOptions) -> Result<Request, Error> {
|
|
131
|
+
let base = options.base_url.as_deref().unwrap_or(&runtime.base_url);
|
|
132
|
+
let url = match &options.url {
|
|
133
|
+
Some(url) => super::pagination::resolve_url(base, url),
|
|
134
|
+
None => build_url(base, spec.path, &args.path, &args.query)?,
|
|
135
|
+
};
|
|
136
|
+
let accept = match spec.result {
|
|
137
|
+
Some(Kind::Events) => "text/event-stream",
|
|
138
|
+
Some(Kind::Bytes) | Some(Kind::Stream) => "*/*",
|
|
139
|
+
_ => "application/json",
|
|
140
|
+
};
|
|
141
|
+
let mut request = Request::new(spec.method, &url).with_header("accept", accept);
|
|
142
|
+
if let Some(version) = &runtime.api_version {
|
|
143
|
+
request = request.with_header(&version.header, &version.value);
|
|
144
|
+
}
|
|
145
|
+
if let Some(kind) = spec.body {
|
|
146
|
+
if args.body.is_some() {
|
|
147
|
+
let content_type = match kind {
|
|
148
|
+
Kind::Json => "application/json".to_string(),
|
|
149
|
+
Kind::Multipart => format!("multipart/form-data; boundary={}", super::multipart::boundary_of(args.body.as_deref().unwrap_or(&[]))),
|
|
150
|
+
_ => "application/octet-stream".to_string(),
|
|
151
|
+
};
|
|
152
|
+
request = request.with_header("content-type", &content_type);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (name, value) in &args.headers {
|
|
156
|
+
if !value.is_null() {
|
|
157
|
+
request = request.with_header(name, &scalar(value));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (name, value) in &options.headers {
|
|
161
|
+
request = request.with_header(name, value);
|
|
162
|
+
}
|
|
163
|
+
Ok(request.with_body(args.body))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fn error_for(spec: &OperationSpec, response: Response) -> Error {
|
|
167
|
+
let body = response.json().unwrap_or_else(|_| Json::String(response.text()));
|
|
168
|
+
match spec.errors.iter().find(|(status, _)| *status == response.status) {
|
|
169
|
+
Some((status, factory)) => factory(*status, body, response),
|
|
170
|
+
None => Error::api_error("ApiError", response.status, body, response),
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn run_chain(handlers: &[Middleware], index: usize, request: Request, ctx: &Context, last: Next) -> Result<Response, Error> {
|
|
175
|
+
match handlers.get(index) {
|
|
176
|
+
None => last(request),
|
|
177
|
+
Some(handler) => handler(request, &|next| run_chain(handlers, index + 1, next, ctx, last), ctx),
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/// Sends one operation through the middleware chain; returns the 2xx response, or the error for any other.
|
|
182
|
+
pub fn call(runtime: &Runtime, spec: &OperationSpec, args: Args, options: &CallOptions) -> Result<Response, Error> {
|
|
183
|
+
if let Some(version) = &runtime.api_version {
|
|
184
|
+
version.check(spec.name, spec.since)?;
|
|
185
|
+
}
|
|
186
|
+
let request = build_request(runtime, spec, args, options)?;
|
|
187
|
+
let send_options = SendOptions { timeout_ms: options.timeout_ms.or(runtime.timeout_ms), stream: matches!(spec.result, Some(Kind::Events)) };
|
|
188
|
+
let transport = runtime.transport.clone();
|
|
189
|
+
let send = move |current: Request| transport.send(¤t, &send_options);
|
|
190
|
+
let ctx = Context {
|
|
191
|
+
config: Vec::new(),
|
|
192
|
+
operation: OperationInfo { name: spec.name.to_string(), method: spec.method.to_string(), path: spec.path.to_string() },
|
|
193
|
+
clock: runtime.clock.clone(),
|
|
194
|
+
state: runtime.state.clone(),
|
|
195
|
+
sdk: runtime.sdk.clone(),
|
|
196
|
+
listeners: runtime.listeners.clone(),
|
|
197
|
+
send: Arc::new(send.clone()),
|
|
198
|
+
};
|
|
199
|
+
let mut handlers: Vec<Middleware> = runtime.middleware.iter().map(|entry| entry.run.clone()).collect();
|
|
200
|
+
for name in spec.uses {
|
|
201
|
+
let found = runtime.registry.get(*name).ok_or_else(|| Error::thrown(format!("unknown middleware {}", name)))?;
|
|
202
|
+
handlers.push(found.run.clone());
|
|
203
|
+
}
|
|
204
|
+
handlers.extend(runtime.user_middleware.iter().map(|entry| entry.run.clone()));
|
|
205
|
+
let response = run_chain(&handlers, 0, request, &ctx, &send)?;
|
|
206
|
+
if !(200..=299).contains(&response.status) {
|
|
207
|
+
return Err(error_for(spec, response));
|
|
208
|
+
}
|
|
209
|
+
Ok(response)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// @end
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// sdkloom Rust kit: the capabilities a middleware receives as ctx.
|
|
2
|
+
|
|
3
|
+
use super::errors::Error;
|
|
4
|
+
use super::http::{Request, Response};
|
|
5
|
+
use super::json::Json;
|
|
6
|
+
use std::collections::HashMap;
|
|
7
|
+
use std::sync::{Arc, Mutex};
|
|
8
|
+
use std::time::{Duration, Instant};
|
|
9
|
+
|
|
10
|
+
// @block context.create
|
|
11
|
+
// @summary The capabilities a middleware gets through ctx: a clock, thread-safe per-client state with expiry, and events whose listeners can never break a call.
|
|
12
|
+
// @versions >=1.70
|
|
13
|
+
// @source [1] https://doc.rust-lang.org/std/time/struct.Instant.html
|
|
14
|
+
// @quote [1] "A measurement of a monotonically nondecreasing clock."
|
|
15
|
+
// @source [2] https://doc.rust-lang.org/std/sync/struct.Mutex.html
|
|
16
|
+
// @quote [2] "A mutual exclusion primitive useful for protecting shared data"
|
|
17
|
+
// @source [3] https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
|
|
18
|
+
// @quote [3] "Invokes a closure, capturing the cause of an unwinding panic if one occurs."
|
|
19
|
+
// @retrieved 2026-12-05
|
|
20
|
+
// @tests tests/client.rs
|
|
21
|
+
// @requirement SDKL-PIPE-002
|
|
22
|
+
|
|
23
|
+
/// Time in milliseconds and a way to wait; tests use FakeClock.
|
|
24
|
+
pub trait Clock: Send + Sync {
|
|
25
|
+
fn now(&self) -> i64;
|
|
26
|
+
fn sleep(&self, ms: i64);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Milliseconds on the monotonic clock.
|
|
30
|
+
pub struct SystemClock {
|
|
31
|
+
start: Instant,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl SystemClock {
|
|
35
|
+
pub fn new() -> SystemClock {
|
|
36
|
+
SystemClock { start: Instant::now() }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
impl Default for SystemClock {
|
|
41
|
+
fn default() -> SystemClock {
|
|
42
|
+
SystemClock::new()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
impl Clock for SystemClock {
|
|
47
|
+
fn now(&self) -> i64 {
|
|
48
|
+
self.start.elapsed().as_millis() as i64
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn sleep(&self, ms: i64) {
|
|
52
|
+
std::thread::sleep(Duration::from_millis(ms.max(0) as u64));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Per-client storage shared by all calls, e.g. for a cached token. Thread-safe.
|
|
57
|
+
pub struct State {
|
|
58
|
+
clock: Arc<dyn Clock>,
|
|
59
|
+
entries: Mutex<HashMap<String, (Json, Option<i64>)>>,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
impl State {
|
|
63
|
+
pub fn new(clock: Arc<dyn Clock>) -> State {
|
|
64
|
+
State { clock, entries: Mutex::new(HashMap::new()) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fn lock(&self) -> std::sync::MutexGuard<'_, HashMap<String, (Json, Option<i64>)>> {
|
|
68
|
+
self.entries.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// The value, or null when it is absent or expired.
|
|
72
|
+
pub fn get(&self, key: &str) -> Json {
|
|
73
|
+
let mut entries = self.lock();
|
|
74
|
+
match entries.get(key) {
|
|
75
|
+
Some((_, Some(expires))) if self.clock.now() >= *expires => {
|
|
76
|
+
entries.remove(key);
|
|
77
|
+
Json::Null
|
|
78
|
+
}
|
|
79
|
+
Some((value, _)) => value.clone(),
|
|
80
|
+
None => Json::Null,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
pub fn set(&self, key: &str, value: Json, ttl_ms: Option<i64>) {
|
|
85
|
+
let expires = ttl_ms.map(|ttl| self.clock.now() + ttl);
|
|
86
|
+
self.lock().insert(key.to_string(), (value, expires));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
pub fn delete(&self, key: &str) {
|
|
90
|
+
self.lock().remove(key);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// Receives every event a middleware emits.
|
|
95
|
+
pub type EventListener = Arc<dyn Fn(&str, &Json) + Send + Sync>;
|
|
96
|
+
|
|
97
|
+
/// The event that reports a listener that panicked; it is never delivered to that listener.
|
|
98
|
+
pub const LISTENER_ERROR: &str = "sdkloom.listener_error";
|
|
99
|
+
|
|
100
|
+
fn panic_text(cause: &(dyn std::any::Any + Send)) -> String {
|
|
101
|
+
cause.downcast_ref::<&str>().map(|text| text.to_string()).or_else(|| cause.downcast_ref::<String>().cloned()).unwrap_or_else(|| "panic".to_string())
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// Delivers an event to every listener; a listener that panics is reported, never propagated.
|
|
105
|
+
pub fn emit(listeners: &[EventListener], name: &str, fields: &Json) {
|
|
106
|
+
deliver(listeners, name, fields, None);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn deliver(listeners: &[EventListener], name: &str, fields: &Json, skip: Option<usize>) {
|
|
110
|
+
let mut failures = Vec::new();
|
|
111
|
+
for (index, listener) in listeners.iter().enumerate() {
|
|
112
|
+
if Some(index) == skip {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if let Err(cause) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| listener(name, fields))) {
|
|
116
|
+
failures.push((index, panic_text(cause.as_ref())));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if name == LISTENER_ERROR {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (index, message) in failures {
|
|
123
|
+
deliver(listeners, LISTENER_ERROR, &Json::object(vec![("event", Json::str(name)), ("error", Json::String(message))]), Some(index));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// Names the operation being called.
|
|
128
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
129
|
+
pub struct OperationInfo {
|
|
130
|
+
pub name: String,
|
|
131
|
+
pub method: String,
|
|
132
|
+
pub path: String,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// Which generated SDK a middleware runs in, e.g. for a User-Agent such as "acme-rust/1.2.0".
|
|
136
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
137
|
+
pub struct SdkInfo {
|
|
138
|
+
pub name: String,
|
|
139
|
+
pub version: String,
|
|
140
|
+
pub language: String,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// Sends a request without the middleware chain.
|
|
144
|
+
pub type SendFn = Arc<dyn Fn(Request) -> Result<Response, Error> + Send + Sync>;
|
|
145
|
+
|
|
146
|
+
/// What a middleware gets as ctx.
|
|
147
|
+
#[derive(Clone)]
|
|
148
|
+
pub struct Context {
|
|
149
|
+
pub config: Vec<(String, Json)>,
|
|
150
|
+
pub operation: OperationInfo,
|
|
151
|
+
pub clock: Arc<dyn Clock>,
|
|
152
|
+
pub state: Arc<State>,
|
|
153
|
+
pub sdk: SdkInfo,
|
|
154
|
+
pub listeners: Vec<EventListener>,
|
|
155
|
+
pub send: SendFn,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
impl Context {
|
|
159
|
+
/// A config value; null when the field is not set.
|
|
160
|
+
pub fn config(&self, name: &str) -> Json {
|
|
161
|
+
self.config.iter().find(|(key, _)| key == name).map(|(_, value)| value.clone()).unwrap_or(Json::Null)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
pub fn emit(&self, name: &str, fields: Json) {
|
|
165
|
+
emit(&self.listeners, name, &fields);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Sends a request through the transport, without the middleware chain (e.g. to fetch a token).
|
|
169
|
+
pub fn send(&self, request: Request) -> Result<Response, Error> {
|
|
170
|
+
(self.send)(request)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
pub fn request(&self, method: &str, url: &str) -> Request {
|
|
174
|
+
Request::new(method, url)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
pub fn with_config(&self, config: Vec<(String, Json)>) -> Context {
|
|
178
|
+
Context { config, ..self.clone() }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// @end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// sdkloom Rust kit: SHA-256 and HMAC-SHA256, which the standard library does not offer.
|
|
2
|
+
|
|
3
|
+
// @block crypto.hmac_sha256
|
|
4
|
+
// @summary SHA-256 (FIPS 180-4) and HMAC-SHA256 (RFC 2104) in plain Rust, for verifying webhook signatures without a dependency; checked against the RFC 4231 test vectors.
|
|
5
|
+
// @versions >=1.70
|
|
6
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc2104#section-2
|
|
7
|
+
// @quote [1] "H(K XOR opad, H(K XOR ipad, text))"
|
|
8
|
+
// @source [2] https://www.rfc-editor.org/rfc/rfc4231#section-4.2
|
|
9
|
+
// @quote [2] "Test Case 1"
|
|
10
|
+
// @retrieved 2026-12-05
|
|
11
|
+
// @tests tests/webhooks.rs
|
|
12
|
+
// @requirement SDKL-HOOK-001
|
|
13
|
+
|
|
14
|
+
const ROUND: [u32; 64] = [
|
|
15
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe,
|
|
16
|
+
0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
17
|
+
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
18
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
19
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/// The SHA-256 digest of the bytes.
|
|
23
|
+
pub fn sha256(data: &[u8]) -> [u8; 32] {
|
|
24
|
+
let mut state: [u32; 8] = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
|
|
25
|
+
let mut message = data.to_vec();
|
|
26
|
+
message.push(0x80);
|
|
27
|
+
while message.len() % 64 != 56 {
|
|
28
|
+
message.push(0);
|
|
29
|
+
}
|
|
30
|
+
message.extend_from_slice(&((data.len() as u64).wrapping_mul(8)).to_be_bytes());
|
|
31
|
+
for block in message.chunks(64) {
|
|
32
|
+
let mut words = [0u32; 64];
|
|
33
|
+
for (index, word) in block.chunks(4).enumerate() {
|
|
34
|
+
words[index] = u32::from_be_bytes([word[0], word[1], word[2], word[3]]);
|
|
35
|
+
}
|
|
36
|
+
for index in 16..64 {
|
|
37
|
+
let s0 = words[index - 15].rotate_right(7) ^ words[index - 15].rotate_right(18) ^ (words[index - 15] >> 3);
|
|
38
|
+
let s1 = words[index - 2].rotate_right(17) ^ words[index - 2].rotate_right(19) ^ (words[index - 2] >> 10);
|
|
39
|
+
words[index] = words[index - 16].wrapping_add(s0).wrapping_add(words[index - 7]).wrapping_add(s1);
|
|
40
|
+
}
|
|
41
|
+
let [mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h] = state;
|
|
42
|
+
for index in 0..64 {
|
|
43
|
+
let s1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25);
|
|
44
|
+
let choice = (e & f) ^ (!e & g);
|
|
45
|
+
let first = h.wrapping_add(s1).wrapping_add(choice).wrapping_add(ROUND[index]).wrapping_add(words[index]);
|
|
46
|
+
let s0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22);
|
|
47
|
+
let majority = (a & b) ^ (a & c) ^ (b & c);
|
|
48
|
+
let second = s0.wrapping_add(majority);
|
|
49
|
+
h = g;
|
|
50
|
+
g = f;
|
|
51
|
+
f = e;
|
|
52
|
+
e = d.wrapping_add(first);
|
|
53
|
+
d = c;
|
|
54
|
+
c = b;
|
|
55
|
+
b = a;
|
|
56
|
+
a = first.wrapping_add(second);
|
|
57
|
+
}
|
|
58
|
+
for (slot, value) in state.iter_mut().zip([a, b, c, d, e, f, g, h]) {
|
|
59
|
+
*slot = slot.wrapping_add(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let mut digest = [0u8; 32];
|
|
63
|
+
for (index, word) in state.iter().enumerate() {
|
|
64
|
+
digest[index * 4..index * 4 + 4].copy_from_slice(&word.to_be_bytes());
|
|
65
|
+
}
|
|
66
|
+
digest
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// The HMAC-SHA256 of the message with the key.
|
|
70
|
+
pub fn hmac_sha256(key: &[u8], message: &[u8]) -> [u8; 32] {
|
|
71
|
+
let mut block = [0u8; 64];
|
|
72
|
+
if key.len() > 64 {
|
|
73
|
+
block[..32].copy_from_slice(&sha256(key));
|
|
74
|
+
} else {
|
|
75
|
+
block[..key.len()].copy_from_slice(key);
|
|
76
|
+
}
|
|
77
|
+
let mut inner: Vec<u8> = block.iter().map(|byte| byte ^ 0x36).collect();
|
|
78
|
+
inner.extend_from_slice(message);
|
|
79
|
+
let mut outer: Vec<u8> = block.iter().map(|byte| byte ^ 0x5c).collect();
|
|
80
|
+
outer.extend_from_slice(&sha256(&inner));
|
|
81
|
+
sha256(&outer)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// @end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// sdkloom Rust kit: errors.
|
|
2
|
+
|
|
3
|
+
use super::http::Response;
|
|
4
|
+
use super::json::Json;
|
|
5
|
+
use std::fmt;
|
|
6
|
+
|
|
7
|
+
// @block errors.api_error
|
|
8
|
+
// @summary One error type for every failure: an HTTP error response (with status, decoded body, request id and whether a retry may succeed), a failed request, an unexpected response body, an argument the SDK cannot send, a webhook whose signature does not match, a wait that timed out, or an error a middleware threw.
|
|
9
|
+
// @versions >=1.70
|
|
10
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.5
|
|
11
|
+
// @quote [1] "The 4xx (Client Error) class of status code indicates that the client seems to have erred."
|
|
12
|
+
// @source [2] https://www.rfc-editor.org/rfc/rfc9110#section-15.6
|
|
13
|
+
// @quote [2] "The 5xx (Server Error) class of status code indicates that the server is aware that it has erred or is incapable of performing the requested method."
|
|
14
|
+
// @source [3] https://doc.rust-lang.org/std/error/trait.Error.html
|
|
15
|
+
// @quote [3] "Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>."
|
|
16
|
+
// @retrieved 2026-12-05
|
|
17
|
+
// @tests tests/client.rs
|
|
18
|
+
// @requirement SDKL-ERR-001
|
|
19
|
+
|
|
20
|
+
const TOO_MANY_REQUESTS: u16 = 429;
|
|
21
|
+
const FIRST_SERVER_ERROR: u16 = 500;
|
|
22
|
+
|
|
23
|
+
/// A non-2xx response. `name` is the declared error's name, e.g. "PaymentNotFound", or "ApiError".
|
|
24
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
25
|
+
pub struct ApiError {
|
|
26
|
+
pub name: String,
|
|
27
|
+
pub status: u16,
|
|
28
|
+
pub body: Json,
|
|
29
|
+
pub response: Response,
|
|
30
|
+
pub request_id: Option<String>,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
impl ApiError {
|
|
34
|
+
pub fn new(name: &str, status: u16, body: Json, response: Response) -> ApiError {
|
|
35
|
+
let request_id = response.header("x-request-id");
|
|
36
|
+
ApiError { name: name.to_string(), status, body, response, request_id }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// True for 429 and 5xx: sending the same request again may succeed.
|
|
40
|
+
pub fn retryable(&self) -> bool {
|
|
41
|
+
self.status == TOO_MANY_REQUESTS || self.status >= FIRST_SERVER_ERROR
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// A request that got no response; `reason` is "timeout" or "network".
|
|
46
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
47
|
+
pub struct TransportError {
|
|
48
|
+
pub reason: String,
|
|
49
|
+
pub cause: String,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// A JSON value that did not match the expected type, e.g. at "$.items[0].amount".
|
|
53
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
54
|
+
pub struct DecodeError {
|
|
55
|
+
pub path: String,
|
|
56
|
+
pub message: String,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
impl DecodeError {
|
|
60
|
+
pub fn new(path: &str, message: &str) -> DecodeError {
|
|
61
|
+
DecodeError { path: path.to_string(), message: message.to_string() }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Every way a call can fail.
|
|
66
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
67
|
+
pub enum Error {
|
|
68
|
+
/// Boxed: an HTTP error carries its response, and errors travel in every Result.
|
|
69
|
+
Api(Box<ApiError>),
|
|
70
|
+
Transport(TransportError),
|
|
71
|
+
Decode(DecodeError),
|
|
72
|
+
/// An error a middleware threw, with its message.
|
|
73
|
+
Thrown(String),
|
|
74
|
+
/// A call argument the SDK cannot send (a missing path parameter, a path parameter of "." or ".."), found before
|
|
75
|
+
/// any request is made.
|
|
76
|
+
Argument(String),
|
|
77
|
+
/// A webhook that was not signed with the secret, or is too old or too new.
|
|
78
|
+
WebhookSignature(String),
|
|
79
|
+
/// A long-running operation that did not finish within its wait's timeout.
|
|
80
|
+
WaitTimeout(String),
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
impl Error {
|
|
84
|
+
pub fn transport(reason: &str, cause: impl fmt::Display) -> Error {
|
|
85
|
+
Error::Transport(TransportError { reason: reason.to_string(), cause: cause.to_string() })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// The error for an HTTP error response.
|
|
89
|
+
pub fn api_error(name: &str, status: u16, body: Json, response: Response) -> Error {
|
|
90
|
+
Error::Api(Box::new(ApiError::new(name, status, body, response)))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pub fn thrown(message: impl Into<String>) -> Error {
|
|
94
|
+
Error::Thrown(message.into())
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// The declared error's name for an HTTP error, else the kind of error: "TransportError", "DecodeError", "ArgumentError", "WebhookSignatureError", "WaitTimeoutError" or "Error".
|
|
98
|
+
pub fn name(&self) -> &str {
|
|
99
|
+
match self {
|
|
100
|
+
Error::Api(error) => &error.name,
|
|
101
|
+
Error::Transport(_) => "TransportError",
|
|
102
|
+
Error::Decode(_) => "DecodeError",
|
|
103
|
+
Error::Thrown(_) => "Error",
|
|
104
|
+
Error::Argument(_) => "ArgumentError",
|
|
105
|
+
Error::WebhookSignature(_) => "WebhookSignatureError",
|
|
106
|
+
Error::WaitTimeout(_) => "WaitTimeoutError",
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// The HTTP error, if this is one.
|
|
111
|
+
pub fn api(&self) -> Option<&ApiError> {
|
|
112
|
+
match self {
|
|
113
|
+
Error::Api(error) => Some(error.as_ref()),
|
|
114
|
+
_ => None,
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Whether this is the HTTP error with the declared name, e.g. "PaymentNotFound".
|
|
119
|
+
pub fn is(&self, name: &str) -> bool {
|
|
120
|
+
matches!(self, Error::Api(error) if error.name == name)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
impl fmt::Display for Error {
|
|
125
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
126
|
+
match self {
|
|
127
|
+
Error::Api(error) => write!(f, "{}: HTTP {}", error.name, error.status),
|
|
128
|
+
Error::Transport(error) if error.cause.is_empty() => write!(f, "TransportError: request failed: {}", error.reason),
|
|
129
|
+
Error::Transport(error) => write!(f, "TransportError: request failed: {} ({})", error.reason, error.cause),
|
|
130
|
+
Error::Decode(error) => write!(f, "{}: {}", error.path, error.message),
|
|
131
|
+
Error::Thrown(message) | Error::Argument(message) | Error::WebhookSignature(message) | Error::WaitTimeout(message) => f.write_str(message),
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
impl std::error::Error for Error {}
|
|
137
|
+
|
|
138
|
+
impl From<DecodeError> for Error {
|
|
139
|
+
fn from(error: DecodeError) -> Error {
|
|
140
|
+
Error::Decode(error)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Builds the declared error for a status.
|
|
145
|
+
pub type ErrorFactory = fn(status: u16, body: Json, response: Response) -> Error;
|
|
146
|
+
|
|
147
|
+
// @end
|