@voxgig/sdkgen 4.49.1 → 4.51.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/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/cache.aontu +6 -4
- package/project/.sdk/model/target/lua.aontu +6 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
- package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
- package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
- package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
- package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
- package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
- package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
- package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
- package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
- package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
- package/project/.sdk/tm/c/core/context.c +1 -0
- package/project/.sdk/tm/c/core/sdk.h +7 -4
- package/project/.sdk/tm/c/feature/cache.c +243 -13
- package/project/.sdk/tm/c/feature/debug.c +1 -0
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/feature/telemetry.c +1 -0
- package/project/.sdk/tm/c/tests/feature_test.c +142 -0
- package/project/.sdk/tm/c/utility/clean.c +26 -33
- package/project/.sdk/tm/c/utility/make_options.c +9 -8
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
- package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
- package/project/.sdk/tm/cpp/Makefile +5 -0
- package/project/.sdk/tm/cpp/core/types.hpp +11 -4
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
- package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
- package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
- package/project/.sdk/tm/csharp/core/Context.cs +4 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
- package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
- package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
- package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
- package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
- package/project/.sdk/tm/go/core/context.go +6 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
- package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +101 -0
- package/project/.sdk/tm/go/utility/clean.go +5 -7
- package/project/.sdk/tm/go/utility/fetcher.go +11 -0
- package/project/.sdk/tm/go/utility/make_options.go +5 -7
- package/project/.sdk/tm/java/core/Context.java +9 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
- package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
- package/project/.sdk/tm/java/utility/Clean.java +6 -10
- package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
- package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
- package/project/.sdk/tm/js/src/Context.js +4 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
- package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
- package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
- package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
- package/project/.sdk/tm/js/test/feature/harness.js +3 -3
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
- package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
- package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
- package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
- package/project/.sdk/tm/lua/core/context.lua +6 -0
- package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
- package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
- package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
- package/project/.sdk/tm/lua/utility/clean.lua +6 -9
- package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
- package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
- package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
- package/project/.sdk/tm/perl/core/context.pm +3 -0
- package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
- package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
- package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
- package/project/.sdk/tm/perl/t/feature.t +86 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
- package/project/.sdk/tm/perl/utility/clean.pm +6 -8
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
- package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
- package/project/.sdk/tm/php/core/Context.php +4 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
- package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
- package/project/.sdk/tm/php/utility/Clean.php +3 -10
- package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
- package/project/.sdk/tm/py/pkg/core/context.py +4 -0
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
- package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
- package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
- package/project/.sdk/tm/py/test/test_feature.py +73 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
- package/project/.sdk/tm/rb/core/context.rb +4 -1
- package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
- package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
- package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
- package/project/.sdk/tm/rb/utility/clean.rb +6 -7
- package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
- package/project/.sdk/tm/rust/core/context.rs +8 -0
- package/project/.sdk/tm/rust/feature/cache.rs +120 -3
- package/project/.sdk/tm/rust/feature/debug.rs +1 -0
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
- package/project/.sdk/tm/rust/utility/clean.rs +35 -43
- package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
- package/project/.sdk/tm/scala/core/Context.scala +4 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
- package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
- package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
- package/project/.sdk/tm/scala/utility/Make.scala +3 -1
- package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
- package/project/.sdk/tm/ts/src/Context.ts +4 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
- package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
- package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
- package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
- package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
- package/project/.sdk/tm/zig/core/context.zig +5 -0
- package/project/.sdk/tm/zig/core/utility.zig +11 -9
- package/project/.sdk/tm/zig/feature/cache.zig +144 -13
- package/project/.sdk/tm/zig/feature/debug.zig +1 -0
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
- package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -487,6 +487,66 @@ public class FeatureTest {
|
|
|
487
487
|
assertEquals(3, rec.calls.size(), "expected 3 calls");
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
+
@Test
|
|
491
|
+
public void cache_keysOnRequestHeaders() {
|
|
492
|
+
assumeFeatures("cache");
|
|
493
|
+
FhRecorder rec = new FhRecorder();
|
|
494
|
+
FhHarness h = fhMake(rec::fetch, fhF(new CacheFeature(), fhMap("ttl", 10000)));
|
|
495
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("x-tenant", "tenant-a")));
|
|
496
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("X-Tenant", "tenant-b")));
|
|
497
|
+
assertEquals(2, rec.calls.size(), "a second tenant was served the first tenant's entry");
|
|
498
|
+
h.op(fhOp("load").path("/w/1").headers(fhMap("x-tenant", "tenant-b")));
|
|
499
|
+
assertEquals(2, rec.calls.size(), "the same headers did not share an entry");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
@Test
|
|
503
|
+
public void cache_aWriteDropsItsCollection() {
|
|
504
|
+
assumeFeatures("cache");
|
|
505
|
+
FhRecorder rec = new FhRecorder();
|
|
506
|
+
CacheFeature f = new CacheFeature();
|
|
507
|
+
FhHarness h = fhMake(rec::fetch, fhF(f, fhMap("ttl", 10000)));
|
|
508
|
+
String[] paths = {"/w/1", "/w", "/w/1/part", "/other/1", "/w/2"};
|
|
509
|
+
for (String p : paths) {
|
|
510
|
+
h.op(fhOp("load").path(p));
|
|
511
|
+
}
|
|
512
|
+
h.op(fhOp("update").method("PUT").path("/w/1"));
|
|
513
|
+
for (String p : paths) {
|
|
514
|
+
h.op(fhOp("load").path(p));
|
|
515
|
+
}
|
|
516
|
+
assertEquals(9, rec.calls.size(), "expected the collection refetched and /other cached");
|
|
517
|
+
assertEquals(2, f.hit, "expected /other served from cache");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
@Test
|
|
521
|
+
public void cache_cacheControlPreventsStoring() {
|
|
522
|
+
assumeFeatures("cache");
|
|
523
|
+
for (String control : new String[] {"no-store", "private", "No-Cache", "max-age=60, private"}) {
|
|
524
|
+
FhRecorder rec = new FhRecorder();
|
|
525
|
+
rec.reply = (n, fetchdef) -> fhResponse(200, fhMap("ok", true), fhMap("Cache-Control", control));
|
|
526
|
+
FhHarness h = fhMake(rec::fetch, fhF(new CacheFeature(), fhMap("ttl", 10000)));
|
|
527
|
+
h.op(fhOp("load").path("/w"));
|
|
528
|
+
h.op(fhOp("load").path("/w"));
|
|
529
|
+
assertEquals(2, rec.calls.size(), control + " was stored");
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
@Test
|
|
534
|
+
public void cache_maxAgeCapsTheTtl() {
|
|
535
|
+
assumeFeatures("cache");
|
|
536
|
+
FhClock clock = new FhClock();
|
|
537
|
+
FhRecorder rec = new FhRecorder();
|
|
538
|
+
rec.reply = (n, fetchdef) -> fhResponse(200, fhMap("ok", true), fhMap("cache-control", "max-age=1"));
|
|
539
|
+
FhHarness h = fhMake(rec::fetch, fhF(new CacheFeature(),
|
|
540
|
+
fhMap("ttl", 10000, "now", (LongSupplier) clock::now)));
|
|
541
|
+
h.op(fhOp("load").path("/w"));
|
|
542
|
+
clock.advance(500);
|
|
543
|
+
h.op(fhOp("load").path("/w"));
|
|
544
|
+
assertEquals(1, rec.calls.size(), "expected a hit inside max-age");
|
|
545
|
+
clock.advance(600);
|
|
546
|
+
h.op(fhOp("load").path("/w"));
|
|
547
|
+
assertEquals(2, rec.calls.size(), "expected max-age=1 to expire the entry before the ttl");
|
|
548
|
+
}
|
|
549
|
+
|
|
490
550
|
@Test
|
|
491
551
|
public void cache_inactiveDoesNotWrap() {
|
|
492
552
|
assumeFeatures("cache");
|
|
@@ -830,6 +890,34 @@ public class FeatureTest {
|
|
|
830
890
|
assertEquals(0, f.records.size(), "expected no records");
|
|
831
891
|
}
|
|
832
892
|
|
|
893
|
+
// --- one call, one id -----------------------------------------------------------
|
|
894
|
+
|
|
895
|
+
@Test
|
|
896
|
+
public void correlation_telemetryDebugAndAuditCarryOneCallsContextId() {
|
|
897
|
+
assumeFeatures("telemetry", "debug", "audit");
|
|
898
|
+
TelemetryFeature telemetry = new TelemetryFeature();
|
|
899
|
+
DebugFeature debug = new DebugFeature();
|
|
900
|
+
AuditFeature audit = new AuditFeature();
|
|
901
|
+
FhHarness h = fhMake(null, fhF(telemetry, null), fhF(debug, null), fhF(audit, null));
|
|
902
|
+
h.op(fhOp("load"));
|
|
903
|
+
h.op(fhOp("list"));
|
|
904
|
+
Function<List<Map<String, Object>>, List<Object>> ids = (recs) -> {
|
|
905
|
+
List<Object> out = new ArrayList<>();
|
|
906
|
+
for (Map<String, Object> rec : recs) {
|
|
907
|
+
out.add(rec.get("correlationId"));
|
|
908
|
+
}
|
|
909
|
+
return out;
|
|
910
|
+
};
|
|
911
|
+
List<Object> calls = ids.apply(audit.records);
|
|
912
|
+
assertEquals(2, calls.size(), "expected one audit record per call");
|
|
913
|
+
for (Object id : calls) {
|
|
914
|
+
assertTrue(id instanceof String && !"".equals(id), "expected a context id, got " + calls);
|
|
915
|
+
}
|
|
916
|
+
assertNotEquals(calls.get(0), calls.get(1), "expected a different id per call");
|
|
917
|
+
assertEquals(calls, ids.apply(telemetry.spans), "expected the spans to carry the audit ids");
|
|
918
|
+
assertEquals(calls, ids.apply(debug.entries), "expected the debug entries to carry the audit ids");
|
|
919
|
+
}
|
|
920
|
+
|
|
833
921
|
// --- clienttrack ----------------------------------------------------------------
|
|
834
922
|
|
|
835
923
|
@Test
|
|
@@ -40,8 +40,8 @@ import JAVAPACKAGE.utility.struct.Struct;
|
|
|
40
40
|
// sensitive KEY name is masked whatever it holds. Inside the pipeline data
|
|
41
41
|
// stays raw, so a hook can still read the header it must add to.
|
|
42
42
|
//
|
|
43
|
-
// The configuration is the
|
|
44
|
-
// (`
|
|
43
|
+
// The configuration is the registry MakeOptions builds beside the options
|
|
44
|
+
// (`ctx.cleancfg`): active, keys, values, mask, hint, min. It
|
|
45
45
|
// is a map so the registry can grow after construction - the auth step and
|
|
46
46
|
// the features register what they handle later.
|
|
47
47
|
@SuppressWarnings({"unchecked"})
|
|
@@ -74,16 +74,12 @@ final class Clean {
|
|
|
74
74
|
|
|
75
75
|
private Clean() {}
|
|
76
76
|
|
|
77
|
-
// A context without
|
|
78
|
-
// back to the schema defaults, so nothing leaves raw for want of a
|
|
77
|
+
// A context without a registry (makeError is reached with a bare one)
|
|
78
|
+
// falls back to the schema defaults, so nothing leaves raw for want of a
|
|
79
79
|
// constructor.
|
|
80
80
|
static Map<String, Object> cleanConfig(Context ctx) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
derived = Struct.getpath(ctx.options, List.of("__derived__", "clean"));
|
|
84
|
-
}
|
|
85
|
-
if (derived instanceof Map) {
|
|
86
|
-
return (Map<String, Object>) derived;
|
|
81
|
+
if (ctx != null && ctx.cleancfg != null) {
|
|
82
|
+
return ctx.cleancfg;
|
|
87
83
|
}
|
|
88
84
|
return makeCleanConfig(Helpers.toMapAny(Schema.optspec().get("clean")));
|
|
89
85
|
}
|
|
@@ -226,6 +226,10 @@ public final class Fetcher {
|
|
|
226
226
|
catch (RuntimeException e) {
|
|
227
227
|
throw new RuntimeException("fetch: invalid url: " + fullurl, e);
|
|
228
228
|
}
|
|
229
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
230
|
+
if (fetchdef.get("timeout") instanceof Number && 0 < ((Number) fetchdef.get("timeout")).longValue()) {
|
|
231
|
+
reqb.timeout(java.time.Duration.ofMillis(((Number) fetchdef.get("timeout")).longValue()));
|
|
232
|
+
}
|
|
229
233
|
|
|
230
234
|
boolean hasUA = false;
|
|
231
235
|
Object headersRaw = fetchdef.get("headers");
|
|
@@ -379,7 +383,7 @@ public final class Fetcher {
|
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
static Object fetcher(Context ctx, String fullurl, Map<String, Object> fetchdef) {
|
|
386
|
+
public static Object fetcher(Context ctx, String fullurl, Map<String, Object> fetchdef) {
|
|
383
387
|
if (!"live".equals(ctx.client.mode)) {
|
|
384
388
|
throw ctx.makeError("fetch_mode_block",
|
|
385
389
|
"Request blocked by mode: \"" + ctx.client.mode
|
|
@@ -266,10 +266,12 @@ final class MakeOptions {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
Map<String, Object> derived = new LinkedHashMap<>();
|
|
269
|
-
derived.put("clean", cleancfg);
|
|
270
269
|
derived.put("featureorder", featureorder);
|
|
271
270
|
opts.put("__derived__", derived);
|
|
272
271
|
|
|
272
|
+
// Beside the options, not in them: optionsMap hands them to callers.
|
|
273
|
+
ctx.cleancfg = cleancfg;
|
|
274
|
+
|
|
273
275
|
// Again over the merged result: the config's own defaults can carry one.
|
|
274
276
|
Clean.addSensitiveOptions(cleancfg, without(opts, "clean", "__derived__"));
|
|
275
277
|
|
|
@@ -39,6 +39,9 @@ class Context {
|
|
|
39
39
|
entopts
|
|
40
40
|
options
|
|
41
41
|
|
|
42
|
+
// The clean registry, which holds every registered credential in plain form.
|
|
43
|
+
cleancfg
|
|
44
|
+
|
|
42
45
|
opmap
|
|
43
46
|
|
|
44
47
|
response
|
|
@@ -72,6 +75,7 @@ class Context {
|
|
|
72
75
|
this.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
|
|
73
76
|
this.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
|
|
74
77
|
this.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
|
|
78
|
+
this.cleancfg = getprop(ctxmap, 'cleancfg', getprop(basectx, 'cleancfg'))
|
|
75
79
|
|
|
76
80
|
this.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
|
|
77
81
|
this.shared = getprop(ctxmap, 'shared', getprop(basectx, 'shared'))
|
|
@@ -5,13 +5,9 @@ const { headerValue, isJsonMedia } = require('../../utility/MediaUtility')
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
// Response caching for safe (read) requests. Wraps the active transport and
|
|
8
|
-
// serves a
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// cache is bounded (`max` entries, oldest evicted) and every hit/miss is
|
|
12
|
-
// recorded on `client._cache` for inspection. One-shot response bodies are
|
|
13
|
-
// normalised on capture so both the current caller and later hits can read
|
|
14
|
-
// the JSON body repeatedly.
|
|
8
|
+
// serves a cached snapshot for a repeat of the same method, URL and headers.
|
|
9
|
+
// The store is per client and bounded; see the features reference for the
|
|
10
|
+
// key, the write invalidation and the Cache-Control rules.
|
|
15
11
|
class CacheFeature extends BaseFeature {
|
|
16
12
|
version = '0.0.1'
|
|
17
13
|
name = 'cache'
|
|
@@ -20,6 +16,7 @@ class CacheFeature extends BaseFeature {
|
|
|
20
16
|
_client
|
|
21
17
|
_options = {}
|
|
22
18
|
_store = new Map()
|
|
19
|
+
_key = undefined
|
|
23
20
|
|
|
24
21
|
|
|
25
22
|
init(ctx, options) {
|
|
@@ -32,6 +29,7 @@ class CacheFeature extends BaseFeature {
|
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
this._store = new Map()
|
|
32
|
+
this._key = cacheKey()
|
|
35
33
|
|
|
36
34
|
const self = this
|
|
37
35
|
const utility = ctx.utility
|
|
@@ -48,10 +46,18 @@ class CacheFeature extends BaseFeature {
|
|
|
48
46
|
const methods = this._options.methods || ['GET']
|
|
49
47
|
|
|
50
48
|
if (methods.indexOf(method) < 0) {
|
|
51
|
-
|
|
49
|
+
if (SAFE_METHODS.indexOf(method) >= 0) {
|
|
50
|
+
return inner(ctx, url, fetchdef)
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return await inner(ctx, url, fetchdef)
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
this._invalidate(url)
|
|
57
|
+
}
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
const key = method + ' ' + url
|
|
60
|
+
const key = method + ' ' + url + ' ' + await this._digest(fetchdef && fetchdef.headers)
|
|
55
61
|
const now = this._now()
|
|
56
62
|
const hit = this._store.get(key)
|
|
57
63
|
|
|
@@ -78,9 +84,16 @@ class CacheFeature extends BaseFeature {
|
|
|
78
84
|
return this._replay(snapshot)
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
const ttl =
|
|
87
|
+
const ttl = cacheLifetime(snapshot.headers,
|
|
88
|
+
null == this._options.ttl ? 5000 : this._options.ttl)
|
|
89
|
+
if (ttl <= 0) {
|
|
90
|
+
this._track('bypass')
|
|
91
|
+
return this._replay(snapshot)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this._store.delete(key)
|
|
82
95
|
this._evict()
|
|
83
|
-
this._store.set(key, { expiry: now + ttl, snapshot })
|
|
96
|
+
this._store.set(key, { expiry: now + ttl, scope: urlScope(url), snapshot })
|
|
84
97
|
this._track('miss')
|
|
85
98
|
return this._replay(snapshot)
|
|
86
99
|
}
|
|
@@ -90,6 +103,25 @@ class CacheFeature extends BaseFeature {
|
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
|
|
106
|
+
async _digest(headers) {
|
|
107
|
+
const subtle = globalThis.crypto.subtle
|
|
108
|
+
const mac = await subtle.sign('HMAC', await this._key,
|
|
109
|
+
new TextEncoder().encode(headerText(headers)))
|
|
110
|
+
return Array.from(new Uint8Array(mac), (b) => b.toString(16).padStart(2, '0')).join('')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
_invalidate(url) {
|
|
115
|
+
const path = urlScope(url)
|
|
116
|
+
const collection = urlParent(path)
|
|
117
|
+
for (const [key, entry] of this._store) {
|
|
118
|
+
if (scopeUnder(entry.scope, path) || entry.scope === collection) {
|
|
119
|
+
this._store.delete(key)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
93
125
|
_cacheable(res) {
|
|
94
126
|
if (null == res || res instanceof Error) {
|
|
95
127
|
return false
|
|
@@ -188,6 +220,81 @@ class CacheFeature extends BaseFeature {
|
|
|
188
220
|
}
|
|
189
221
|
|
|
190
222
|
|
|
223
|
+
const SAFE_METHODS = ['GET', 'HEAD']
|
|
224
|
+
|
|
225
|
+
const UNSTORED = ['no-store', 'private', 'no-cache']
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
// A fresh random secret per client: the key holds a digest of the headers,
|
|
229
|
+
// never a header value.
|
|
230
|
+
function cacheKey() {
|
|
231
|
+
const crypto = globalThis.crypto
|
|
232
|
+
return crypto.subtle.importKey('raw', crypto.getRandomValues(new Uint8Array(32)),
|
|
233
|
+
{ name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
function headerText(headers) {
|
|
238
|
+
const pairs = []
|
|
239
|
+
for (const name of Object.keys(headers || {})) {
|
|
240
|
+
if (null != headers[name]) {
|
|
241
|
+
pairs.push([name.toLowerCase(), String(headers[name])])
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
pairs.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0)
|
|
245
|
+
return pairs.map((p) => p[0] + ':' + p[1] + '\n').join('')
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
// The configured ttl, capped by the response's Cache-Control; zero when the
|
|
250
|
+
// response may not be stored.
|
|
251
|
+
function cacheLifetime(headers, ttl) {
|
|
252
|
+
let control = ''
|
|
253
|
+
for (const name of Object.keys(headers || {})) {
|
|
254
|
+
if ('cache-control' === name.toLowerCase()) {
|
|
255
|
+
control = String(headers[name])
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
let life = ttl
|
|
259
|
+
for (const part of control.toLowerCase().split(',')) {
|
|
260
|
+
const directive = part.trim()
|
|
261
|
+
if (UNSTORED.indexOf(directive) >= 0) {
|
|
262
|
+
return 0
|
|
263
|
+
}
|
|
264
|
+
const age = directive.match(/^max-age\s*=\s*"?(\d+)"?$/)
|
|
265
|
+
if (null != age) {
|
|
266
|
+
life = Math.min(life, Number(age[1]) * 1000)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return life
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
function urlScope(url) {
|
|
274
|
+
let scope = String(url).split(/[?#]/)[0]
|
|
275
|
+
while (scope.endsWith('/')) {
|
|
276
|
+
scope = scope.slice(0, -1)
|
|
277
|
+
}
|
|
278
|
+
return scope
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
function urlParent(scope) {
|
|
283
|
+
const scheme = scope.indexOf('://')
|
|
284
|
+
const root = scheme < 0 ? 0 : scope.indexOf('/', scheme + 3)
|
|
285
|
+
if (root < 0) {
|
|
286
|
+
return scope
|
|
287
|
+
}
|
|
288
|
+
const cut = scope.lastIndexOf('/')
|
|
289
|
+
return scope.slice(0, cut < root ? root : cut)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
function scopeUnder(scope, prefix) {
|
|
294
|
+
return scope === prefix || scope.startsWith(prefix + '/')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
191
298
|
module.exports = {
|
|
192
299
|
CacheFeature
|
|
193
300
|
}
|
|
@@ -51,8 +51,9 @@ class CostFeature extends BaseFeature {
|
|
|
51
51
|
client._cost = {
|
|
52
52
|
currency: this._options.currency || 'USD',
|
|
53
53
|
total: { calls: 0, attempts: 0, amount: 0, reported: 0, estimated: 0 },
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// Keyed by a caller's string, so no prototype to collide with.
|
|
55
|
+
ops: Object.create(null),
|
|
56
|
+
actors: Object.create(null),
|
|
56
57
|
budget: { limit, spent: 0, remaining: limit, exceeded: false },
|
|
57
58
|
last: undefined,
|
|
58
59
|
}
|
|
@@ -36,6 +36,7 @@ class DebugFeature extends BaseFeature {
|
|
|
36
36
|
const spec = ctx.spec || {}
|
|
37
37
|
const entry = {
|
|
38
38
|
op: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
39
|
+
correlationId: ctx.id,
|
|
39
40
|
method: spec.method,
|
|
40
41
|
url: spec.url || spec.path,
|
|
41
42
|
headers: this._redact(ctx, spec.headers),
|
|
@@ -189,17 +189,17 @@ class PagingFeature extends BaseFeature {
|
|
|
189
189
|
|
|
190
190
|
// Only bind variables the operation actually declares, or the server
|
|
191
191
|
// rejects the document.
|
|
192
|
-
const declared =
|
|
192
|
+
const declared = new Set()
|
|
193
193
|
for (const v of ((point.graphql && point.graphql.vars) || [])) {
|
|
194
|
-
declared
|
|
194
|
+
declared.add(v.name)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
if (null != paging.cursor && declared
|
|
197
|
+
if (null != paging.cursor && declared.has(afterVar)) {
|
|
198
198
|
vars[afterVar] = paging.cursor
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
if (null != this._options.limit && null == vars[firstVar] &&
|
|
202
|
-
declared
|
|
202
|
+
declared.has(firstVar)) {
|
|
203
203
|
vars[firstVar] = this._options.limit
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -18,7 +18,7 @@ class RbacFeature extends BaseFeature {
|
|
|
18
18
|
|
|
19
19
|
_client
|
|
20
20
|
_options = {}
|
|
21
|
-
_granted =
|
|
21
|
+
_granted = new Set()
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
init(ctx, options) {
|
|
@@ -26,10 +26,10 @@ class RbacFeature extends BaseFeature {
|
|
|
26
26
|
this._options = options || {}
|
|
27
27
|
this.active = options.active
|
|
28
28
|
|
|
29
|
-
this._granted =
|
|
29
|
+
this._granted = new Set()
|
|
30
30
|
const perms = this._options.permissions || []
|
|
31
31
|
for (const p of perms) {
|
|
32
|
-
this._granted
|
|
32
|
+
this._granted.add(p)
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -48,7 +48,7 @@ class RbacFeature extends BaseFeature {
|
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
if (this._granted
|
|
51
|
+
if (this._granted.has('*') || this._granted.has(required)) {
|
|
52
52
|
this._track(ctx, required, true)
|
|
53
53
|
return
|
|
54
54
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
const { BaseFeature } = require('../base/BaseFeature')
|
|
3
|
+
const { fetcher } = require('../../utility/FetcherUtility')
|
|
3
4
|
const { Sekreto, envkey } = require('./sekreto')
|
|
4
5
|
|
|
5
6
|
|
|
@@ -367,19 +368,28 @@ class SecretsFeature extends BaseFeature {
|
|
|
367
368
|
throw new Error('secrets: no fetch implementation for the token exchange')
|
|
368
369
|
}
|
|
369
370
|
|
|
370
|
-
// Deliberately NOT the SDK transport. The transport is what this
|
|
371
|
-
// feature wraps, and sending the token request back through it would
|
|
372
|
-
// recurse on the first 401 — and would route the exchange through the
|
|
373
|
-
// test mock, which knows nothing about it.
|
|
374
371
|
const fetchdef = {
|
|
375
372
|
method: x.method,
|
|
376
373
|
headers: { 'content-type': 'application/json' },
|
|
377
374
|
body: JSON.stringify({ [x.request]: this._refresh }),
|
|
378
375
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
379
376
|
redirect: 'manual',
|
|
377
|
+
// Its own bound: the timeout feature's wrapper is above it.
|
|
378
|
+
signal: AbortSignal.timeout(30000),
|
|
380
379
|
}
|
|
381
380
|
|
|
382
|
-
|
|
381
|
+
// The SDK's own transport, beneath every feature's wrapper: the wrapped
|
|
382
|
+
// one would recurse on the first 401 and reach the test mock. It applies
|
|
383
|
+
// the GET-only guard, and its refusal is the operation's error.
|
|
384
|
+
const send = async (at) => {
|
|
385
|
+
const sent = await fetcher(this._client._rootctx, at, fetchdef)
|
|
386
|
+
if (sent instanceof Error) {
|
|
387
|
+
throw sent
|
|
388
|
+
}
|
|
389
|
+
return sent
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let res = await send(url)
|
|
383
393
|
|
|
384
394
|
// By option alone, and only while the exchange stays on its own origin.
|
|
385
395
|
let at = url
|
|
@@ -389,7 +399,7 @@ class SecretsFeature extends BaseFeature {
|
|
|
389
399
|
break
|
|
390
400
|
}
|
|
391
401
|
at = next
|
|
392
|
-
res = await
|
|
402
|
+
res = await send(at)
|
|
393
403
|
}
|
|
394
404
|
|
|
395
405
|
const status = null == res ? 0 : res.status
|
|
@@ -39,6 +39,7 @@ class TelemetryFeature extends BaseFeature {
|
|
|
39
39
|
const span = {
|
|
40
40
|
traceId: this._id('trace'),
|
|
41
41
|
spanId: this._id('span'),
|
|
42
|
+
correlationId: ctx.id,
|
|
42
43
|
name: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
43
44
|
start: this._now(),
|
|
44
45
|
end: undefined,
|
|
@@ -202,7 +202,8 @@ class ValidateFeature extends BaseFeature {
|
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
_entitySpec(ctx) {
|
|
205
|
-
|
|
205
|
+
const name = entname(ctx)
|
|
206
|
+
return Object.prototype.hasOwnProperty.call(this._spec, name) ? this._spec[name] : undefined
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
|
|
@@ -54,7 +54,7 @@ function count(val, dflt) {
|
|
|
54
54
|
// is reached with a bare one) falls back to the schema defaults, so nothing
|
|
55
55
|
// leaves raw for want of a constructor.
|
|
56
56
|
function cleanConfig(ctx) {
|
|
57
|
-
const derived = ctx?.
|
|
57
|
+
const derived = ctx?.cleancfg
|
|
58
58
|
if (null != derived) {
|
|
59
59
|
return derived
|
|
60
60
|
}
|
|
@@ -43,7 +43,7 @@ function makeOptions(ctx) {
|
|
|
43
43
|
const layer = (b) => null != b && 'object' === typeof b && !Array.isArray(b) ? b : {}
|
|
44
44
|
const cleancfg = makeCleanConfig(merge([{}, OPTSPEC.clean,
|
|
45
45
|
struct.clone(layer(cfgopts.clean)), layer(opts.clean)]))
|
|
46
|
-
const cleanctx = {
|
|
46
|
+
const cleanctx = { cleancfg }
|
|
47
47
|
cleanAddSensitive(cleanctx, settings(opts))
|
|
48
48
|
for (const raw of [...splitvalues(cfgopts.clean?.values), ...splitvalues(opts.clean?.values)]) {
|
|
49
49
|
cleanAdd(cleanctx, raw)
|
|
@@ -164,13 +164,13 @@ function makeOptions(ctx) {
|
|
|
164
164
|
featureorder = names
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
opts.__derived__ = {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
opts.__derived__ = { featureorder }
|
|
168
|
+
|
|
169
|
+
// Beside the options, not in them: options() hands them to callers.
|
|
170
|
+
ctx.cleancfg = cleancfg
|
|
171
171
|
|
|
172
172
|
// Again over the merged result: the config's own defaults can carry one.
|
|
173
|
-
cleanAddSensitive(
|
|
173
|
+
cleanAddSensitive(cleanctx, settings(opts))
|
|
174
174
|
|
|
175
175
|
return opts
|
|
176
176
|
}
|