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,116 @@
|
|
|
1
|
+
// sdkloom Java kit: building request URLs.
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.UnsupportedEncodingException;
|
|
5
|
+
import java.math.BigDecimal;
|
|
6
|
+
import java.net.URLEncoder;
|
|
7
|
+
import java.util.ArrayList;
|
|
8
|
+
import java.util.Collections;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
import java.util.regex.Matcher;
|
|
12
|
+
import java.util.regex.Pattern;
|
|
13
|
+
|
|
14
|
+
// @block http.url
|
|
15
|
+
// @summary Builds a request URL: percent-encodes path parameters and appends query parameters in order, exactly like the TypeScript and Python kits. A path parameter of "." or ".." is refused with an ArgumentError: URL parsers read it as a step up the path, even percent-encoded. A {+name} placeholder (RFC 6570 reserved expansion, limited to "/") takes a value that spans segments, each encoded on its own.
|
|
16
|
+
// @versions >=8
|
|
17
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc3986#section-2.1
|
|
18
|
+
// @quote [1] "A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component."
|
|
19
|
+
// @source [2] https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URLEncoder.html
|
|
20
|
+
// @quote [2] "The special characters ".", "-", "*", and "_" remain the same."
|
|
21
|
+
// @source [3] https://www.rfc-editor.org/rfc/rfc3986#section-3.3
|
|
22
|
+
// @quote [3] "also known as dot-segments, are defined for relative reference within the path name hierarchy."
|
|
23
|
+
// @source [4] https://www.rfc-editor.org/rfc/rfc6570#section-3.2.3
|
|
24
|
+
// @quote [4] "is identical to simple string expansion except that the substituted values may also contain pct-encoded triplets and characters in the reserved set."
|
|
25
|
+
// @retrieved 2026-12-05
|
|
26
|
+
// @tests tests/dev/sdkloom/runtime/HttpTest.java
|
|
27
|
+
// @requirement SDKL-HTTP-002
|
|
28
|
+
public final class Urls {
|
|
29
|
+
private static final Pattern PLACEHOLDER = Pattern.compile("\\{([^{}]+)\\}");
|
|
30
|
+
|
|
31
|
+
private Urls() {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static String scalar(Object value) {
|
|
35
|
+
if (value instanceof BigDecimal) {
|
|
36
|
+
return ((BigDecimal) value).toPlainString();
|
|
37
|
+
}
|
|
38
|
+
if (value instanceof Double || value instanceof Float) {
|
|
39
|
+
// String(number) as JavaScript writes it: 2 (not 2.0), 1e-7 (not 1.0E-7), the shortest digits.
|
|
40
|
+
return Js.number(((Number) value).doubleValue());
|
|
41
|
+
}
|
|
42
|
+
return String.valueOf(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** application/x-www-form-urlencoded as browsers write it: space is "+", "~" is encoded, "*" is not. */
|
|
46
|
+
static String form(String text) {
|
|
47
|
+
try {
|
|
48
|
+
return URLEncoder.encode(text, "UTF-8");
|
|
49
|
+
} catch (UnsupportedEncodingException error) {
|
|
50
|
+
throw new IllegalStateException("UTF-8 is always supported", error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Like encodeURIComponent: also keeps ! ' ( ) ~ and writes space as %20. */
|
|
55
|
+
static String pathSegment(String text) {
|
|
56
|
+
return form(text)
|
|
57
|
+
.replace("+", "%20")
|
|
58
|
+
.replace("%21", "!")
|
|
59
|
+
.replace("%27", "'")
|
|
60
|
+
.replace("%28", "(")
|
|
61
|
+
.replace("%29", ")")
|
|
62
|
+
.replace("%7E", "~");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A path parameter as one encoded segment. "." and ".." are refused: URL parsers treat them, even percent-encoded, as
|
|
67
|
+
* steps up the path, so the request would reach another resource.
|
|
68
|
+
*/
|
|
69
|
+
static String pathParameter(String name, String text) {
|
|
70
|
+
if (".".equals(text) || "..".equals(text)) {
|
|
71
|
+
throw new ArgumentException("path parameter " + name + " cannot be \"" + text + "\": a URL would read it as a step up the path");
|
|
72
|
+
}
|
|
73
|
+
return pathSegment(text);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public static String build(String base, String template, Map<String, ?> pathParams, List<Map.Entry<String, ?>> query) {
|
|
77
|
+
Matcher matcher = PLACEHOLDER.matcher(template);
|
|
78
|
+
StringBuffer path = new StringBuffer();
|
|
79
|
+
while (matcher.find()) {
|
|
80
|
+
// {+name} (RFC 6570 reserved expansion, limited to "/"): the value may span segments, each encoded on its own.
|
|
81
|
+
boolean reserved = matcher.group(1).startsWith("+");
|
|
82
|
+
String name = reserved ? matcher.group(1).substring(1) : matcher.group(1);
|
|
83
|
+
if (!pathParams.containsKey(name) || pathParams.get(name) == null) {
|
|
84
|
+
throw new ArgumentException("missing path parameter " + name);
|
|
85
|
+
}
|
|
86
|
+
String value = scalar(pathParams.get(name));
|
|
87
|
+
String encoded;
|
|
88
|
+
if (reserved) {
|
|
89
|
+
List<String> segments = new ArrayList<>();
|
|
90
|
+
for (String segment : value.split("/", -1)) {
|
|
91
|
+
segments.add(pathParameter(name, segment));
|
|
92
|
+
}
|
|
93
|
+
encoded = String.join("/", segments);
|
|
94
|
+
} else {
|
|
95
|
+
encoded = pathParameter(name, value);
|
|
96
|
+
}
|
|
97
|
+
matcher.appendReplacement(path, Matcher.quoteReplacement(encoded));
|
|
98
|
+
}
|
|
99
|
+
matcher.appendTail(path);
|
|
100
|
+
|
|
101
|
+
List<String> pairs = new ArrayList<>();
|
|
102
|
+
for (Map.Entry<String, ?> entry : query) {
|
|
103
|
+
Object value = entry.getValue();
|
|
104
|
+
if (value == null) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
List<?> items = value instanceof List ? (List<?>) value : Collections.singletonList(value);
|
|
108
|
+
for (Object item : items) {
|
|
109
|
+
pairs.add(form(entry.getKey()) + "=" + form(scalar(item)));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
String trimmed = base.endsWith("/") ? base.replaceAll("/+$", "") : base;
|
|
113
|
+
return trimmed + path + (pairs.isEmpty() ? "" : "?" + String.join("&", pairs));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// @end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// sdkloom Java kit: waiting for a long-running operation.
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import java.util.function.Function;
|
|
5
|
+
import java.util.function.Predicate;
|
|
6
|
+
|
|
7
|
+
// @block lro.wait
|
|
8
|
+
// @summary Waits for a long-running operation: polls until the result says the work is done, sleeping on the client's clock between polls, and throws WaitTimeoutException when the next poll would come after the deadline.
|
|
9
|
+
// @versions >=8
|
|
10
|
+
// @source [1] https://www.rfc-editor.org/rfc/rfc9110#section-15.3.3
|
|
11
|
+
// @quote [1] "The 202 (Accepted) status code indicates that the request has been accepted for processing, but the processing has not been completed."
|
|
12
|
+
// @retrieved 2026-12-06
|
|
13
|
+
// @tests tests/dev/sdkloom/runtime/WaitsTest.java
|
|
14
|
+
// @requirement SDKL-WAIT-001
|
|
15
|
+
public final class Waits {
|
|
16
|
+
private Waits() {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The work did not finish within the wait's timeout; last() is the last result read. */
|
|
20
|
+
public static final class WaitTimeoutException extends RuntimeException {
|
|
21
|
+
private static final long serialVersionUID = 1L;
|
|
22
|
+
private final transient Object last;
|
|
23
|
+
|
|
24
|
+
public WaitTimeoutException(String message, Object last) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.last = last;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public Object last() {
|
|
30
|
+
return last;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The name the other languages use for this error. */
|
|
34
|
+
public String name() {
|
|
35
|
+
return "WaitTimeoutError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Polls until done(result); the first result comes from starting the work. */
|
|
40
|
+
public static <R> R until(R first, Function<R, R> poll, Predicate<R> done, Clock clock, long intervalMs, long timeoutMs) {
|
|
41
|
+
long deadline = clock.now() + timeoutMs;
|
|
42
|
+
R current = first;
|
|
43
|
+
while (!done.test(current)) {
|
|
44
|
+
if (clock.now() + intervalMs > deadline) {
|
|
45
|
+
throw new WaitTimeoutException("the work did not finish within " + timeoutMs + " ms", current);
|
|
46
|
+
}
|
|
47
|
+
clock.sleep(intervalMs);
|
|
48
|
+
current = poll.apply(current);
|
|
49
|
+
}
|
|
50
|
+
return current;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// @end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// sdkloom Java kit: the error for a webhook that fails verification.
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
// @block webhooks.error
|
|
5
|
+
// @summary The webhook was not signed with the secret, or is too old or too new; named WebhookSignatureError like in the other languages.
|
|
6
|
+
// @versions >=8
|
|
7
|
+
// @source [1] https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md
|
|
8
|
+
// @quote [1] "has a timestamp that is within some allowable tolerance of the current timestamp to prevent replay attacks."
|
|
9
|
+
// @retrieved 2026-12-05
|
|
10
|
+
// @tests tests/dev/sdkloom/runtime/WebhooksTest.java
|
|
11
|
+
// @requirement SDKL-HOOK-001
|
|
12
|
+
public final class WebhookSignatureException extends RuntimeException {
|
|
13
|
+
private static final long serialVersionUID = 1L;
|
|
14
|
+
|
|
15
|
+
public WebhookSignatureException(String message) {
|
|
16
|
+
super(message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The name the other languages use for this error. */
|
|
20
|
+
public String name() {
|
|
21
|
+
return "WebhookSignatureError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// @end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// sdkloom Java kit: verifying the signature of a webhook the API sent.
|
|
2
|
+
package dev.sdkloom.runtime;
|
|
3
|
+
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.nio.charset.StandardCharsets;
|
|
6
|
+
import java.security.GeneralSecurityException;
|
|
7
|
+
import java.security.MessageDigest;
|
|
8
|
+
import java.util.Base64;
|
|
9
|
+
import java.util.Locale;
|
|
10
|
+
import java.util.Map;
|
|
11
|
+
import java.util.regex.Matcher;
|
|
12
|
+
import java.util.regex.Pattern;
|
|
13
|
+
import javax.crypto.Mac;
|
|
14
|
+
import javax.crypto.spec.SecretKeySpec;
|
|
15
|
+
|
|
16
|
+
// @block webhooks.verify
|
|
17
|
+
// @summary Verifies a webhook's HMAC-SHA256 signature as the definition describes it (signed text from the body and headers, several signatures in one header, an optional timestamp tolerance against replays), comparing in constant time, and throws WebhookSignatureException.
|
|
18
|
+
// @versions >=8
|
|
19
|
+
// @source [1] https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md
|
|
20
|
+
// @quote [1] "When verifying symmetric signatures, use a constant time comparison function to compare the calculated with the expected signature."
|
|
21
|
+
// @quote [1] "The signature header is a space delimited list of signatures associated with this webhook."
|
|
22
|
+
// @source [2] https://docs.oracle.com/javase/8/docs/api/javax/crypto/Mac.html
|
|
23
|
+
// @quote [2] "This class provides the functionality of a "Message Authentication Code" (MAC) algorithm."
|
|
24
|
+
// @retrieved 2026-12-05
|
|
25
|
+
// @tests tests/dev/sdkloom/runtime/WebhooksTest.java
|
|
26
|
+
// @requirement SDKL-HOOK-001
|
|
27
|
+
public final class Webhooks {
|
|
28
|
+
private static final Pattern PLACEHOLDER = Pattern.compile("\\{([^{}]*)\\}");
|
|
29
|
+
private static final Pattern TIMESTAMP = Pattern.compile("[0-9]{1,15}");
|
|
30
|
+
|
|
31
|
+
private Webhooks() {
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** How a webhook is signed; the same fields as the definition's hmacSignature(). Null for absent options. */
|
|
35
|
+
public static final class Signature {
|
|
36
|
+
final String header;
|
|
37
|
+
final String encoding;
|
|
38
|
+
final String prefix;
|
|
39
|
+
final String separator;
|
|
40
|
+
final String signed;
|
|
41
|
+
final String timestampHeader;
|
|
42
|
+
final long toleranceSeconds;
|
|
43
|
+
final String secret;
|
|
44
|
+
final String secretPrefix;
|
|
45
|
+
|
|
46
|
+
public Signature(String header, String encoding, String prefix, String separator, String signed, String timestampHeader, long toleranceSeconds, String secret, String secretPrefix) {
|
|
47
|
+
this.header = header;
|
|
48
|
+
this.encoding = encoding;
|
|
49
|
+
this.prefix = prefix == null ? "" : prefix;
|
|
50
|
+
this.separator = separator;
|
|
51
|
+
this.signed = signed;
|
|
52
|
+
this.timestampHeader = timestampHeader;
|
|
53
|
+
this.toleranceSeconds = toleranceSeconds;
|
|
54
|
+
this.secret = secret;
|
|
55
|
+
this.secretPrefix = secretPrefix;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private static String header(Map<String, String> headers, String name) {
|
|
60
|
+
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
61
|
+
if (entry.getKey() != null && entry.getKey().toLowerCase(Locale.ROOT).equals(name)) {
|
|
62
|
+
return entry.getValue();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private static byte[] hmacSha256(byte[] key, byte[] message) {
|
|
69
|
+
try {
|
|
70
|
+
Mac mac = Mac.getInstance("HmacSHA256");
|
|
71
|
+
mac.init(new SecretKeySpec(key, "HmacSHA256"));
|
|
72
|
+
return mac.doFinal(message);
|
|
73
|
+
} catch (GeneralSecurityException impossible) {
|
|
74
|
+
throw new IllegalStateException("HmacSHA256 is not available", impossible);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private static String hex(byte[] bytes) {
|
|
79
|
+
StringBuilder out = new StringBuilder();
|
|
80
|
+
for (byte value : bytes) {
|
|
81
|
+
out.append(String.format(Locale.ROOT, "%02x", value & 0xff));
|
|
82
|
+
}
|
|
83
|
+
return out.toString();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Throws WebhookSignatureException unless one of the header's signatures is the HMAC of the signed text, made in time. */
|
|
87
|
+
public static void verify(Signature signature, byte[] body, Map<String, String> headers, String secret, long nowSeconds) {
|
|
88
|
+
if (signature.timestampHeader != null) {
|
|
89
|
+
String stamp = header(headers, signature.timestampHeader);
|
|
90
|
+
stamp = stamp == null ? "" : stamp.trim();
|
|
91
|
+
if (!TIMESTAMP.matcher(stamp).matches()) {
|
|
92
|
+
throw new WebhookSignatureException("missing or invalid " + signature.timestampHeader + " header");
|
|
93
|
+
}
|
|
94
|
+
if (Math.abs(nowSeconds - Long.parseLong(stamp)) > signature.toleranceSeconds) {
|
|
95
|
+
throw new WebhookSignatureException("the webhook was signed at " + stamp + ", more than " + signature.toleranceSeconds + " s from now");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
String given = header(headers, signature.header);
|
|
99
|
+
if (given == null) {
|
|
100
|
+
throw new WebhookSignatureException("missing " + signature.header + " header");
|
|
101
|
+
}
|
|
102
|
+
ByteArrayOutputStream message = new ByteArrayOutputStream();
|
|
103
|
+
Matcher matcher = PLACEHOLDER.matcher(signature.signed);
|
|
104
|
+
int last = 0;
|
|
105
|
+
while (matcher.find()) {
|
|
106
|
+
byte[] literal = signature.signed.substring(last, matcher.start()).getBytes(StandardCharsets.UTF_8);
|
|
107
|
+
message.write(literal, 0, literal.length);
|
|
108
|
+
String name = matcher.group(1);
|
|
109
|
+
byte[] value;
|
|
110
|
+
if (name.equals("body")) {
|
|
111
|
+
value = body;
|
|
112
|
+
} else {
|
|
113
|
+
String found = header(headers, name);
|
|
114
|
+
if (found == null) {
|
|
115
|
+
throw new WebhookSignatureException("missing " + name + " header");
|
|
116
|
+
}
|
|
117
|
+
value = found.getBytes(StandardCharsets.UTF_8);
|
|
118
|
+
}
|
|
119
|
+
message.write(value, 0, value.length);
|
|
120
|
+
last = matcher.end();
|
|
121
|
+
}
|
|
122
|
+
byte[] tail = signature.signed.substring(last).getBytes(StandardCharsets.UTF_8);
|
|
123
|
+
message.write(tail, 0, tail.length);
|
|
124
|
+
String keyText = signature.secretPrefix != null && secret.startsWith(signature.secretPrefix) ? secret.substring(signature.secretPrefix.length()) : secret;
|
|
125
|
+
byte[] key;
|
|
126
|
+
try {
|
|
127
|
+
key = signature.secret.equals("base64") ? Base64.getDecoder().decode(keyText) : keyText.getBytes(StandardCharsets.UTF_8);
|
|
128
|
+
} catch (IllegalArgumentException invalid) {
|
|
129
|
+
throw new WebhookSignatureException("the secret is not valid base64");
|
|
130
|
+
}
|
|
131
|
+
byte[] digest = hmacSha256(key, message.toByteArray());
|
|
132
|
+
byte[] expected = (signature.encoding.equals("hex") ? hex(digest) : Base64.getEncoder().encodeToString(digest)).getBytes(StandardCharsets.US_ASCII);
|
|
133
|
+
String[] candidates = signature.separator == null ? new String[] {given} : given.split(Pattern.quote(signature.separator), -1);
|
|
134
|
+
boolean matched = false;
|
|
135
|
+
for (String candidate : candidates) {
|
|
136
|
+
if (candidate.startsWith(signature.prefix)) {
|
|
137
|
+
// MessageDigest.isEqual compares in constant time.
|
|
138
|
+
matched |= MessageDigest.isEqual(candidate.substring(signature.prefix.length()).getBytes(StandardCharsets.UTF_8), expected);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!matched) {
|
|
142
|
+
throw new WebhookSignatureException("no signature matches: the webhook was not signed with this secret, or was changed after signing");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// @end
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// @requirement SDKL-ERR-001
|
|
2
|
+
// @requirement SDKL-VERSION-001
|
|
3
|
+
// @requirement SDKL-PIPE-001
|
|
4
|
+
// @requirement SDKL-PIPE-002
|
|
5
|
+
package dev.sdkloom.runtime;
|
|
6
|
+
|
|
7
|
+
import static dev.sdkloom.runtime.TestData.entry;
|
|
8
|
+
import static dev.sdkloom.runtime.TestData.mapOf;
|
|
9
|
+
import static dev.sdkloom.runtime.TestData.listOf;
|
|
10
|
+
import static dev.sdkloom.runtime.Assert.assertEquals;
|
|
11
|
+
import static dev.sdkloom.runtime.Assert.assertNull;
|
|
12
|
+
import static dev.sdkloom.runtime.Assert.assertThrows;
|
|
13
|
+
import static dev.sdkloom.runtime.Assert.assertTrue;
|
|
14
|
+
|
|
15
|
+
import java.io.ByteArrayInputStream;
|
|
16
|
+
import java.io.InputStream;
|
|
17
|
+
import java.nio.charset.StandardCharsets;
|
|
18
|
+
import java.util.ArrayList;
|
|
19
|
+
import java.util.HashMap;
|
|
20
|
+
import java.util.List;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
23
|
+
|
|
24
|
+
public class ClientTest {
|
|
25
|
+
private final MockTransport transport = new MockTransport();
|
|
26
|
+
private final FakeClock clock = new FakeClock();
|
|
27
|
+
private final List<String> events = new ArrayList<>();
|
|
28
|
+
|
|
29
|
+
private static final OperationSpec GET_ITEM = OperationSpec.builder("getItem", "GET", "/items/{id}")
|
|
30
|
+
.param("id", "path")
|
|
31
|
+
.param("expand", "query")
|
|
32
|
+
.param("x-trace", "header")
|
|
33
|
+
.result("json")
|
|
34
|
+
.decode(Decode.mapOf(Decode.STRING))
|
|
35
|
+
.error(404, (status, body, response) -> new ApiException(status, body, response, "NotFound"))
|
|
36
|
+
.build();
|
|
37
|
+
|
|
38
|
+
private ClientRuntime runtime(List<MiddlewareEntry> middleware, Map<String, MiddlewareEntry> registry, List<MiddlewareEntry> user) {
|
|
39
|
+
return new ClientRuntime("https://api.test/v1", transport, clock, middleware, registry, user,
|
|
40
|
+
listOf((name, fields) -> events.add(name)), 1000L);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private ClientRuntime runtime() {
|
|
44
|
+
return runtime(listOf(), mapOf(), listOf());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private static Map<String, Object> args(Object... pairs) {
|
|
48
|
+
Map<String, Object> result = new HashMap<>();
|
|
49
|
+
for (int i = 0; i < pairs.length; i += 2) {
|
|
50
|
+
result.put((String) pairs[i], pairs[i + 1]);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test
|
|
56
|
+
public void middlewareLearnsWhichSdkItRunsIn() {
|
|
57
|
+
List<SdkInfo> seen = new ArrayList<>();
|
|
58
|
+
Middleware spy = (request, next, ctx) -> {
|
|
59
|
+
seen.add(ctx.sdk());
|
|
60
|
+
return next.call(request);
|
|
61
|
+
};
|
|
62
|
+
OperationSpec spec = OperationSpec.builder("op", "GET", "/op").build();
|
|
63
|
+
transport.route("GET", "/v1/op").replyJson(204, null);
|
|
64
|
+
|
|
65
|
+
new ClientRuntime("https://api.test/v1", transport, clock, listOf(MiddlewareEntry.of("spy", spy)), mapOf(), listOf(), listOf(), 1000L,
|
|
66
|
+
new SdkInfo("payments", "1.2.3", "java")).call(spec, args());
|
|
67
|
+
runtime(listOf(MiddlewareEntry.of("spy", spy)), mapOf(), listOf()).call(spec, args());
|
|
68
|
+
|
|
69
|
+
assertEquals("payments 1.2.3 java", seen.get(0).name() + " " + seen.get(0).version() + " " + seen.get(0).language());
|
|
70
|
+
assertEquals(" java", seen.get(1).name() + seen.get(1).version() + " " + seen.get(1).language());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
public void buildsTheRequestAndDecodesTheResult() {
|
|
75
|
+
transport.route("GET", "/v1/items/{id}").replyJson(200, mapOf("name", "a"));
|
|
76
|
+
|
|
77
|
+
RawResult<Map<String, String>> result = runtime().call(GET_ITEM, args("id", "a 1", "expand", listOf("x", "y"), "x-trace", "t1"));
|
|
78
|
+
|
|
79
|
+
assertEquals(mapOf("name", "a"), result.data());
|
|
80
|
+
HttpRequest sent = transport.calls().get(0);
|
|
81
|
+
assertEquals("https://api.test/v1/items/a%201?expand=x&expand=y", sent.url());
|
|
82
|
+
assertEquals("t1", sent.header("x-trace"));
|
|
83
|
+
assertEquals("application/json", sent.header("accept"));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Test
|
|
87
|
+
public void sendsAJsonBody() {
|
|
88
|
+
OperationSpec spec = OperationSpec.builder("create", "POST", "/items").body("json").build();
|
|
89
|
+
transport.route("POST", "/v1/items").replyJson(201, null);
|
|
90
|
+
|
|
91
|
+
runtime().call(spec, args("body", mapOf("name", "ş")));
|
|
92
|
+
|
|
93
|
+
HttpRequest sent = transport.calls().get(0);
|
|
94
|
+
assertEquals("{\"name\":\"ş\"}", new String(sent.body(), StandardCharsets.UTF_8));
|
|
95
|
+
assertEquals("application/json", sent.header("content-type"));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Test
|
|
99
|
+
public void mapsStatusesToErrors() {
|
|
100
|
+
transport.route("GET", "/v1/items/{id}").replyJson(404, mapOf("message", "no"));
|
|
101
|
+
transport.route("GET", "/v1/items/busy").replyJson(503, null);
|
|
102
|
+
transport.route("GET", "/v1/items/teapot").replyText(418, "not json");
|
|
103
|
+
|
|
104
|
+
ApiException notFound = assertThrows(ApiException.class, () -> runtime().call(GET_ITEM, args("id", "x")));
|
|
105
|
+
assertEquals("NotFound", notFound.name());
|
|
106
|
+
assertEquals(404, notFound.status());
|
|
107
|
+
assertEquals(Json.parse("{\"message\":\"no\"}"), notFound.body());
|
|
108
|
+
assertTrue(!notFound.retryable());
|
|
109
|
+
|
|
110
|
+
ApiException busy = assertThrows(ApiException.class, () -> runtime().call(GET_ITEM, args("id", "busy")));
|
|
111
|
+
assertEquals("ApiError", busy.name());
|
|
112
|
+
assertTrue(busy.retryable());
|
|
113
|
+
|
|
114
|
+
assertEquals("not json", assertThrows(ApiException.class, () -> runtime().call(GET_ITEM, args("id", "teapot"))).body());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Test
|
|
118
|
+
public void errorsCarryTheRequestId() {
|
|
119
|
+
HttpResponse response = new HttpResponse(500, listOf(entry("X-Request-Id", "req_1")), new byte[0]);
|
|
120
|
+
|
|
121
|
+
assertEquals("req_1", new ApiException(500, null, response).requestId());
|
|
122
|
+
assertNull(new ApiException(500, null, null).requestId());
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Test
|
|
126
|
+
public void aResultWithTheWrongShapeFailsWithItsPath() {
|
|
127
|
+
transport.route("GET", "/v1/items/{id}").replyJson(200, mapOf("name", 1));
|
|
128
|
+
|
|
129
|
+
DecodeException error = assertThrows(DecodeException.class, () -> runtime().call(GET_ITEM, args("id", "x")));
|
|
130
|
+
|
|
131
|
+
assertEquals("$.name: expected a string, got number 1", error.getMessage());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
public void runsMiddlewareInOrderAroundTheTransport() {
|
|
136
|
+
List<String> order = new ArrayList<>();
|
|
137
|
+
Middleware tag = (request, next, ctx) -> {
|
|
138
|
+
order.add((String) ctx.config().get("label"));
|
|
139
|
+
return next.call(request.withHeader("x-order", String.join(",", order)));
|
|
140
|
+
};
|
|
141
|
+
OperationSpec spec = OperationSpec.builder("op", "GET", "/op").use("operation").build();
|
|
142
|
+
transport.route("GET", "/v1/op").replyJson(200, null);
|
|
143
|
+
|
|
144
|
+
runtime(listOf(MiddlewareEntry.of("sdk", tag, mapOf("label", "sdk"))),
|
|
145
|
+
mapOf("operation", MiddlewareEntry.of("operation", tag, mapOf("label", "operation"))),
|
|
146
|
+
listOf(MiddlewareEntry.of("user", tag, mapOf("label", "user"))))
|
|
147
|
+
.call(spec, args());
|
|
148
|
+
|
|
149
|
+
assertEquals("sdk,operation,user", transport.calls().get(0).header("x-order"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Test
|
|
153
|
+
public void middlewareMayCallNextTwiceAndSeesTheOperation() {
|
|
154
|
+
transport.route("GET", "/v1/items/{id}").replyJson(503, null).replyJson(200, mapOf("name", "ok"));
|
|
155
|
+
Middleware retryOnce = (request, next, ctx) -> {
|
|
156
|
+
HttpResponse first = next.call(request);
|
|
157
|
+
if (first.status() != 503) {
|
|
158
|
+
return first;
|
|
159
|
+
}
|
|
160
|
+
ctx.emit("retry", mapOf("operation", ctx.operation().name()));
|
|
161
|
+
return next.call(request);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
RawResult<Map<String, String>> result = runtime(listOf(MiddlewareEntry.of("retry", retryOnce)), mapOf(), listOf()).call(GET_ITEM, args("id", "x"));
|
|
165
|
+
|
|
166
|
+
assertEquals("ok", result.data().get("name"));
|
|
167
|
+
assertEquals(2, transport.calls().size());
|
|
168
|
+
assertEquals(listOf("retry"), events);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@Test
|
|
172
|
+
public void aMiddlewareMayAnswerWithoutCallingNext() {
|
|
173
|
+
Middleware cached = (request, next, ctx) -> new HttpResponse(200, listOf(), "{\"name\":\"cached\"}".getBytes(StandardCharsets.UTF_8));
|
|
174
|
+
|
|
175
|
+
RawResult<Map<String, String>> result = runtime(listOf(MiddlewareEntry.of("cache", cached)), mapOf(), listOf()).call(GET_ITEM, args("id", "x"));
|
|
176
|
+
|
|
177
|
+
assertEquals("cached", result.data().get("name"));
|
|
178
|
+
assertEquals(0, transport.calls().size());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@Test
|
|
182
|
+
public void aThrowingListenerNeverBreaksTheCall() {
|
|
183
|
+
List<String> seen = new ArrayList<>();
|
|
184
|
+
Emitter emitter = new Emitter(listOf(
|
|
185
|
+
(name, fields) -> {
|
|
186
|
+
throw new IllegalStateException("boom");
|
|
187
|
+
},
|
|
188
|
+
(name, fields) -> seen.add(name + " " + fields.getOrDefault("error", ""))));
|
|
189
|
+
|
|
190
|
+
emitter.emit("http.request", mapOf());
|
|
191
|
+
|
|
192
|
+
assertEquals(listOf("http.request ", "sdkloom.listener_error boom"), seen);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@Test
|
|
196
|
+
public void returnsBytesAndStreamsAndCollectsStreamBodies() throws Exception {
|
|
197
|
+
transport.route("GET", "/v1/file").replyBytes(200, new byte[] {1, 2});
|
|
198
|
+
transport.route("POST", "/v1/upload").replyJson(204, null);
|
|
199
|
+
OperationSpec bytes = OperationSpec.builder("file", "GET", "/file").result("bytes").build();
|
|
200
|
+
OperationSpec stream = OperationSpec.builder("file", "GET", "/file").result("stream").build();
|
|
201
|
+
OperationSpec upload = OperationSpec.builder("upload", "POST", "/upload").body("stream").build();
|
|
202
|
+
|
|
203
|
+
assertEquals(new byte[] {1, 2}, runtime().<byte[]>call(bytes, args()).data());
|
|
204
|
+
assertEquals(new byte[] {1, 2}, TestData.readAll(runtime().<InputStream>call(stream, args()).data()));
|
|
205
|
+
runtime().call(upload, args("body", new ByteArrayInputStream(new byte[] {7})));
|
|
206
|
+
assertEquals(new byte[] {7}, transport.calls().get(2).body());
|
|
207
|
+
assertEquals("*/*", transport.calls().get(0).header("accept"));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@Test
|
|
211
|
+
public void stateEntriesExpireAfterTheirTimeToLive() {
|
|
212
|
+
State state = new State(clock);
|
|
213
|
+
state.set("token", "t", 100);
|
|
214
|
+
state.set("forever", "f");
|
|
215
|
+
|
|
216
|
+
clock.advance(99);
|
|
217
|
+
assertEquals("t", state.get("token"));
|
|
218
|
+
clock.advance(1);
|
|
219
|
+
assertNull(state.get("token"));
|
|
220
|
+
assertEquals("f", state.get("forever"));
|
|
221
|
+
state.delete("forever");
|
|
222
|
+
assertNull(state.get("forever"));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@Test
|
|
226
|
+
public void stateIsSafeToShareBetweenThreads() throws InterruptedException {
|
|
227
|
+
State state = new State(clock);
|
|
228
|
+
AtomicInteger done = new AtomicInteger();
|
|
229
|
+
List<Thread> threads = new ArrayList<>();
|
|
230
|
+
for (int i = 0; i < 8; i++) {
|
|
231
|
+
int id = i;
|
|
232
|
+
Thread thread = new Thread(() -> {
|
|
233
|
+
for (int j = 0; j < 500; j++) {
|
|
234
|
+
state.set("k" + id, j);
|
|
235
|
+
state.get("k" + id);
|
|
236
|
+
}
|
|
237
|
+
done.incrementAndGet();
|
|
238
|
+
});
|
|
239
|
+
threads.add(thread);
|
|
240
|
+
thread.start();
|
|
241
|
+
}
|
|
242
|
+
for (Thread thread : threads) {
|
|
243
|
+
thread.join();
|
|
244
|
+
}
|
|
245
|
+
assertEquals(8, done.get());
|
|
246
|
+
assertEquals(499, state.get("k3"));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@Test
|
|
250
|
+
public void theSystemClockReadsTimeAndSleeps() {
|
|
251
|
+
Clock system = Clock.system();
|
|
252
|
+
long start = system.now();
|
|
253
|
+
system.sleep(5);
|
|
254
|
+
assertTrue(system.now() - start >= 4, "the clock moved");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@Test
|
|
258
|
+
public void anOperationNewerThanThePinnedApiVersionIsRefusedAndUnknownVersionsToo() {
|
|
259
|
+
ClientRuntime.ApiVersion version = new ClientRuntime.ApiVersion("api-version", "2024-06-20", java.util.Arrays.asList("2024-06-20", "2025-01-01"));
|
|
260
|
+
version.check("getOrder", "2024-06-20");
|
|
261
|
+
version.check("getOrder", null);
|
|
262
|
+
assertEquals("refundOrder needs API version 2025-01-01 or later; this client uses 2024-06-20",
|
|
263
|
+
Assert.assertThrows(ArgumentException.class, () -> version.check("refundOrder", "2025-01-01")).getMessage());
|
|
264
|
+
Assert.assertThrows(ArgumentException.class, () -> new ClientRuntime.ApiVersion("api-version", "1999", java.util.Arrays.asList("2024-06-20")).check("getOrder", null));
|
|
265
|
+
}
|
|
266
|
+
}
|