@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
|
@@ -45,6 +45,7 @@ public final class TelemetryFeature: BaseFeature {
|
|
|
45
45
|
let span = VMap()
|
|
46
46
|
span.entries["traceId"] = .string(id("trace"))
|
|
47
47
|
span.entries["spanId"] = .string(id("span"))
|
|
48
|
+
span.entries["correlationId"] = .string(ctx.id)
|
|
48
49
|
span.entries["name"] = .string(entity + "." + opname)
|
|
49
50
|
span.entries["start"] = .int(foptNow(options)())
|
|
50
51
|
ctx.out[TelemetryFeature.spanKey] = span
|
|
@@ -135,6 +135,10 @@ private func sendOnce(_ fullurl: String, _ fetchdef: VMap) throws -> Value {
|
|
|
135
135
|
|
|
136
136
|
var req = URLRequest(url: url)
|
|
137
137
|
req.httpMethod = gp(fetchdef, "method").asString ?? "GET"
|
|
138
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
139
|
+
if let ms = gp(fetchdef, "timeout").asDouble, ms > 0 {
|
|
140
|
+
req.timeoutInterval = ms / 1000
|
|
141
|
+
}
|
|
138
142
|
|
|
139
143
|
let body = gp(fetchdef, "body")
|
|
140
144
|
if let text = body.asString, text != "" {
|
|
@@ -69,8 +69,7 @@ func makeOptionsUtil(_ ctx: Context) -> VMap {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
let cleancfg = makeCleanConfig(merge(.list(cleanlayers)))
|
|
72
|
-
let cleanctx = Context(
|
|
73
|
-
["options": vm(("__derived__", .map(vm(("clean", .nat(cleancfg))))))], nil)
|
|
72
|
+
let cleanctx = Context(["cleancfg": cleancfg], nil)
|
|
74
73
|
cleanAddOptions(cleanctx, cleanOmit(opts, ["clean"]))
|
|
75
74
|
let cleanvalues = cleanSplitValues(gpath(cfgopts, "clean", "values"))
|
|
76
75
|
+ cleanSplitValues(gpath(opts, "clean", "values"))
|
|
@@ -176,12 +175,14 @@ func makeOptionsUtil(_ ctx: Context) -> VMap {
|
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
let derived = VMap()
|
|
179
|
-
derived.entries["clean"] = .nat(cleancfg)
|
|
180
178
|
derived.entries["featureorder"] = .list(VList(featureorder))
|
|
181
179
|
result.entries["__derived__"] = .map(derived)
|
|
182
180
|
|
|
181
|
+
// Beside the options, not in them: optionsMap hands them to callers.
|
|
182
|
+
ctx.cleancfg = cleancfg
|
|
183
|
+
|
|
183
184
|
// Again over the merged result: the config's own defaults can carry one.
|
|
184
|
-
cleanAddOptions(
|
|
185
|
+
cleanAddOptions(cleanctx, cleanOmit(result, ["clean", "__derived__"]))
|
|
185
186
|
|
|
186
187
|
return result
|
|
187
188
|
}
|
|
@@ -134,9 +134,8 @@ func transformResponseUtil(_ ctx: Context) -> Value {
|
|
|
134
134
|
// stays raw, so a hook can still read the header it must add to. See
|
|
135
135
|
// docs/explanation/secret-redaction.md.
|
|
136
136
|
|
|
137
|
-
// The
|
|
138
|
-
// values later.
|
|
139
|
-
// which JSON.stringify prints as "<function>" rather than as the registry.
|
|
137
|
+
// The clean registry, MUTABLE after makeOptions since features register
|
|
138
|
+
// values later. Held on the context beside the options, never in them.
|
|
140
139
|
// Nested in Utility, whose registry it is, so no entity type can collide
|
|
141
140
|
// with it.
|
|
142
141
|
extension Utility {
|
|
@@ -247,10 +246,10 @@ func makeCleanConfig(_ cleanopts: Value) -> Utility.CleanConfig {
|
|
|
247
246
|
return cfg
|
|
248
247
|
}
|
|
249
248
|
|
|
250
|
-
// A context without
|
|
249
|
+
// A context without a registry (makeError accepts a bare one) still masks by
|
|
251
250
|
// the schema defaults.
|
|
252
251
|
func cleanConfigOf(_ ctx: Context) -> Utility.CleanConfig {
|
|
253
|
-
if let cfg =
|
|
252
|
+
if let cfg = ctx.cleancfg {
|
|
254
253
|
return cfg
|
|
255
254
|
}
|
|
256
255
|
return makeCleanConfig(gp(SdkSchema.optspec, "clean"))
|
|
@@ -602,6 +602,61 @@ final class FeatureCacheTest: XCTestCase {
|
|
|
602
602
|
_ = h.op(FhOpSpec(op: "load", path: "/x"))
|
|
603
603
|
XCTAssertEqual(rec.calls.count, 2)
|
|
604
604
|
}
|
|
605
|
+
|
|
606
|
+
func testKeysOnRequestHeaders() {
|
|
607
|
+
if Fh.skipWithout("cache") { return }
|
|
608
|
+
let rec = FhRecorder()
|
|
609
|
+
let h = Fh.make(rec.fetch, (CacheFeature(), vm(("ttl", .int(10000)))))
|
|
610
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w/1", headers: vm(("x-tenant", .string("tenant-a")))))
|
|
611
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w/1", headers: vm(("X-Tenant", .string("tenant-b")))))
|
|
612
|
+
XCTAssertEqual(rec.calls.count, 2, "a second tenant was served the first tenant's entry")
|
|
613
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w/1", headers: vm(("x-tenant", .string("tenant-b")))))
|
|
614
|
+
XCTAssertEqual(rec.calls.count, 2, "the same headers did not share an entry")
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
func testAWriteDropsItsCollection() {
|
|
618
|
+
if Fh.skipWithout("cache") { return }
|
|
619
|
+
let rec = FhRecorder()
|
|
620
|
+
let f = CacheFeature()
|
|
621
|
+
let h = Fh.make(rec.fetch, (f, vm(("ttl", .int(10000)))))
|
|
622
|
+
let paths = ["/w/1", "/w", "/w/1/part", "/other/1", "/w/2"]
|
|
623
|
+
for p in paths { _ = h.op(FhOpSpec(op: "load", path: p)) }
|
|
624
|
+
_ = h.op(FhOpSpec(op: "update", method: "PUT", path: "/w/1"))
|
|
625
|
+
for p in paths { _ = h.op(FhOpSpec(op: "load", path: p)) }
|
|
626
|
+
XCTAssertEqual(rec.calls.count, 9)
|
|
627
|
+
XCTAssertEqual(f.hit, 2)
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
func testCacheControlPreventsStoring() {
|
|
631
|
+
if Fh.skipWithout("cache") { return }
|
|
632
|
+
for control in ["no-store", "private", "No-Cache", "max-age=60, private"] {
|
|
633
|
+
let rec = FhRecorder()
|
|
634
|
+
rec.reply = { _, _ in
|
|
635
|
+
Fh.response(200, mapv(("ok", .bool(true))), vm(("Cache-Control", .string(control))))
|
|
636
|
+
}
|
|
637
|
+
let h = Fh.make(rec.fetch, (CacheFeature(), vm(("ttl", .int(10000)))))
|
|
638
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w"))
|
|
639
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w"))
|
|
640
|
+
XCTAssertEqual(rec.calls.count, 2, control + " was stored")
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
func testMaxAgeCapsTheTtl() {
|
|
645
|
+
if Fh.skipWithout("cache") { return }
|
|
646
|
+
let clock = FhClock()
|
|
647
|
+
let rec = FhRecorder()
|
|
648
|
+
rec.reply = { _, _ in
|
|
649
|
+
Fh.response(200, mapv(("ok", .bool(true))), vm(("cache-control", .string("max-age=1"))))
|
|
650
|
+
}
|
|
651
|
+
let h = Fh.make(rec.fetch, (CacheFeature(), vm(("ttl", .int(10000)), ("now", .nat(clock.now)))))
|
|
652
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w"))
|
|
653
|
+
clock.advance(500)
|
|
654
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w"))
|
|
655
|
+
XCTAssertEqual(rec.calls.count, 1, "expected a hit inside max-age")
|
|
656
|
+
clock.advance(600)
|
|
657
|
+
_ = h.op(FhOpSpec(op: "load", path: "/w"))
|
|
658
|
+
XCTAssertEqual(rec.calls.count, 2, "expected max-age=1 to expire the entry before the ttl")
|
|
659
|
+
}
|
|
605
660
|
}
|
|
606
661
|
|
|
607
662
|
// --- idempotency -------------------------------------------------------------
|
|
@@ -887,6 +942,30 @@ final class FeatureAuditTest: XCTestCase {
|
|
|
887
942
|
}
|
|
888
943
|
}
|
|
889
944
|
|
|
945
|
+
// --- one call, one id --------------------------------------------------------
|
|
946
|
+
|
|
947
|
+
final class FeatureCorrelationTest: XCTestCase {
|
|
948
|
+
func testTelemetryDebugAndAuditCarryOneCallsContextId() {
|
|
949
|
+
if Fh.skipWithout("telemetry", "debug", "audit") { return }
|
|
950
|
+
let telemetry = TelemetryFeature()
|
|
951
|
+
let debug = DebugFeature()
|
|
952
|
+
let audit = AuditFeature()
|
|
953
|
+
let h = Fh.make(nil, (telemetry, nil), (debug, nil), (audit, nil))
|
|
954
|
+
_ = h.op(FhOpSpec(op: "load"))
|
|
955
|
+
_ = h.op(FhOpSpec(op: "list"))
|
|
956
|
+
func ids(_ recs: [VMap]) -> [Value?] { recs.map { $0.entries["correlationId"] } }
|
|
957
|
+
let calls = ids(audit.records)
|
|
958
|
+
guard calls.count == 2 else {
|
|
959
|
+
XCTFail("expected one audit record per call, got \(calls.count)")
|
|
960
|
+
return
|
|
961
|
+
}
|
|
962
|
+
XCTAssertTrue(calls.allSatisfy { ($0?.asString ?? "") != "" }, "context ids: \(calls)")
|
|
963
|
+
XCTAssertNotEqual(calls[0], calls[1])
|
|
964
|
+
XCTAssertEqual(ids(telemetry.spans), calls)
|
|
965
|
+
XCTAssertEqual(ids(debug.entries), calls)
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
890
969
|
// --- clienttrack -------------------------------------------------------------
|
|
891
970
|
|
|
892
971
|
final class FeatureClienttrackTest: XCTestCase {
|
|
@@ -40,6 +40,9 @@ class Context {
|
|
|
40
40
|
entopts: Record<string, any>
|
|
41
41
|
options: Record<string, any>
|
|
42
42
|
|
|
43
|
+
// The clean registry, which holds every registered credential in plain form.
|
|
44
|
+
cleancfg?: any
|
|
45
|
+
|
|
43
46
|
opmap: Record<string, Operation>
|
|
44
47
|
|
|
45
48
|
response?: Response
|
|
@@ -73,6 +76,7 @@ class Context {
|
|
|
73
76
|
this.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
|
|
74
77
|
this.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
|
|
75
78
|
this.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
|
|
79
|
+
this.cleancfg = getprop(ctxmap, 'cleancfg', getprop(basectx, 'cleancfg'))
|
|
76
80
|
|
|
77
81
|
this.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
|
|
78
82
|
this.shared = getprop(ctxmap, 'shared', getprop(basectx, 'shared'))
|
|
@@ -14,6 +14,7 @@ class CacheFeature extends BaseFeature {
|
|
|
14
14
|
_client?: ProjectNameSDK
|
|
15
15
|
_options: any = {}
|
|
16
16
|
_store: Map<string, any> = new Map()
|
|
17
|
+
_key?: Promise<any>
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
init(ctx: Context, options: FeatureOptions): void | Promise<any> {
|
|
@@ -26,6 +27,7 @@ class CacheFeature extends BaseFeature {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
this._store = new Map()
|
|
30
|
+
this._key = cacheKey()
|
|
29
31
|
|
|
30
32
|
const self = this
|
|
31
33
|
const utility = ctx.utility
|
|
@@ -42,10 +44,18 @@ class CacheFeature extends BaseFeature {
|
|
|
42
44
|
const methods = this._options.methods || ['GET']
|
|
43
45
|
|
|
44
46
|
if (methods.indexOf(method) < 0) {
|
|
45
|
-
|
|
47
|
+
if (SAFE_METHODS.indexOf(method) >= 0) {
|
|
48
|
+
return inner(ctx, url, fetchdef)
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return await inner(ctx, url, fetchdef)
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
this._invalidate(url)
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
const key = method + ' ' + url
|
|
58
|
+
const key = method + ' ' + url + ' ' + await this._digest(fetchdef && fetchdef.headers)
|
|
49
59
|
const now = this._now()
|
|
50
60
|
const hit = this._store.get(key)
|
|
51
61
|
|
|
@@ -72,9 +82,16 @@ class CacheFeature extends BaseFeature {
|
|
|
72
82
|
return this._replay(snapshot)
|
|
73
83
|
}
|
|
74
84
|
|
|
75
|
-
const ttl =
|
|
85
|
+
const ttl = cacheLifetime(snapshot.headers,
|
|
86
|
+
null == this._options.ttl ? 5000 : this._options.ttl)
|
|
87
|
+
if (ttl <= 0) {
|
|
88
|
+
this._track('bypass')
|
|
89
|
+
return this._replay(snapshot)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this._store.delete(key)
|
|
76
93
|
this._evict()
|
|
77
|
-
this._store.set(key, { expiry: now + ttl, snapshot })
|
|
94
|
+
this._store.set(key, { expiry: now + ttl, scope: urlScope(url), snapshot })
|
|
78
95
|
this._track('miss')
|
|
79
96
|
return this._replay(snapshot)
|
|
80
97
|
}
|
|
@@ -84,6 +101,25 @@ class CacheFeature extends BaseFeature {
|
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
|
|
104
|
+
async _digest(this: any, headers: any): Promise<string> {
|
|
105
|
+
const subtle = globalThis.crypto.subtle
|
|
106
|
+
const mac = await subtle.sign('HMAC', await this._key,
|
|
107
|
+
new TextEncoder().encode(headerText(headers)))
|
|
108
|
+
return Array.from(new Uint8Array(mac), (b: number) => b.toString(16).padStart(2, '0')).join('')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
_invalidate(this: any, url: string) {
|
|
113
|
+
const path = urlScope(url)
|
|
114
|
+
const collection = urlParent(path)
|
|
115
|
+
for (const [key, entry] of this._store) {
|
|
116
|
+
if (scopeUnder(entry.scope, path) || entry.scope === collection) {
|
|
117
|
+
this._store.delete(key)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
87
123
|
_cacheable(this: any, res: any): boolean {
|
|
88
124
|
if (null == res || res instanceof Error) {
|
|
89
125
|
return false
|
|
@@ -182,6 +218,81 @@ class CacheFeature extends BaseFeature {
|
|
|
182
218
|
}
|
|
183
219
|
|
|
184
220
|
|
|
221
|
+
const SAFE_METHODS = ['GET', 'HEAD']
|
|
222
|
+
|
|
223
|
+
const UNSTORED = ['no-store', 'private', 'no-cache']
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
// A fresh random secret per client: the key holds a digest of the headers,
|
|
227
|
+
// never a header value.
|
|
228
|
+
function cacheKey(): Promise<any> {
|
|
229
|
+
const crypto = globalThis.crypto
|
|
230
|
+
return crypto.subtle.importKey('raw', crypto.getRandomValues(new Uint8Array(32)),
|
|
231
|
+
{ name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
function headerText(headers: any): string {
|
|
236
|
+
const pairs: string[][] = []
|
|
237
|
+
for (const name of Object.keys(headers || {})) {
|
|
238
|
+
if (null != headers[name]) {
|
|
239
|
+
pairs.push([name.toLowerCase(), String(headers[name])])
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
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)
|
|
243
|
+
return pairs.map((p) => p[0] + ':' + p[1] + '\n').join('')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
// The configured ttl, capped by the response's Cache-Control; zero when the
|
|
248
|
+
// response may not be stored.
|
|
249
|
+
function cacheLifetime(headers: Record<string, any>, ttl: number): number {
|
|
250
|
+
let control = ''
|
|
251
|
+
for (const name of Object.keys(headers || {})) {
|
|
252
|
+
if ('cache-control' === name.toLowerCase()) {
|
|
253
|
+
control = String(headers[name])
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let life = ttl
|
|
257
|
+
for (const part of control.toLowerCase().split(',')) {
|
|
258
|
+
const directive = part.trim()
|
|
259
|
+
if (UNSTORED.indexOf(directive) >= 0) {
|
|
260
|
+
return 0
|
|
261
|
+
}
|
|
262
|
+
const age = directive.match(/^max-age\s*=\s*"?(\d+)"?$/)
|
|
263
|
+
if (null != age) {
|
|
264
|
+
life = Math.min(life, Number(age[1]) * 1000)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return life
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
function urlScope(url: string): string {
|
|
272
|
+
let scope = String(url).split(/[?#]/)[0]
|
|
273
|
+
while (scope.endsWith('/')) {
|
|
274
|
+
scope = scope.slice(0, -1)
|
|
275
|
+
}
|
|
276
|
+
return scope
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
function urlParent(scope: string): string {
|
|
281
|
+
const scheme = scope.indexOf('://')
|
|
282
|
+
const root = scheme < 0 ? 0 : scope.indexOf('/', scheme + 3)
|
|
283
|
+
if (root < 0) {
|
|
284
|
+
return scope
|
|
285
|
+
}
|
|
286
|
+
const cut = scope.lastIndexOf('/')
|
|
287
|
+
return scope.slice(0, cut < root ? root : cut)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
function scopeUnder(scope: string, prefix: string): boolean {
|
|
292
|
+
return scope === prefix || scope.startsWith(prefix + '/')
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
185
296
|
export {
|
|
186
297
|
CacheFeature
|
|
187
298
|
}
|
|
@@ -29,8 +29,9 @@ class CostFeature extends BaseFeature {
|
|
|
29
29
|
client._cost = {
|
|
30
30
|
currency: this._options.currency || 'USD',
|
|
31
31
|
total: { calls: 0, attempts: 0, amount: 0, reported: 0, estimated: 0 },
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Keyed by a caller's string, so no prototype to collide with.
|
|
33
|
+
ops: Object.create(null),
|
|
34
|
+
actors: Object.create(null),
|
|
34
35
|
budget: { limit, spent: 0, remaining: limit, exceeded: false },
|
|
35
36
|
last: undefined,
|
|
36
37
|
}
|
|
@@ -32,6 +32,7 @@ class DebugFeature extends BaseFeature {
|
|
|
32
32
|
const spec = ctx.spec || {}
|
|
33
33
|
const entry = {
|
|
34
34
|
op: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
35
|
+
correlationId: ctx.id,
|
|
35
36
|
method: spec.method,
|
|
36
37
|
url: spec.url || spec.path,
|
|
37
38
|
headers: this._redact(ctx, spec.headers),
|
|
@@ -176,17 +176,17 @@ class PagingFeature extends BaseFeature {
|
|
|
176
176
|
const afterVar = this._options.afterVar || 'after'
|
|
177
177
|
const firstVar = this._options.firstVar || 'first'
|
|
178
178
|
|
|
179
|
-
const declared
|
|
179
|
+
const declared = new Set<string>()
|
|
180
180
|
for (const v of ((point.graphql && point.graphql.vars) || [])) {
|
|
181
|
-
declared
|
|
181
|
+
declared.add(v.name)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
if (null != paging.cursor && declared
|
|
184
|
+
if (null != paging.cursor && declared.has(afterVar)) {
|
|
185
185
|
vars[afterVar] = paging.cursor
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
if (null != this._options.limit && null == vars[firstVar] &&
|
|
189
|
-
declared
|
|
189
|
+
declared.has(firstVar)) {
|
|
190
190
|
vars[firstVar] = this._options.limit
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -12,7 +12,7 @@ class RbacFeature extends BaseFeature {
|
|
|
12
12
|
|
|
13
13
|
_client?: ProjectNameSDK
|
|
14
14
|
_options: any = {}
|
|
15
|
-
_granted:
|
|
15
|
+
_granted: Set<string> = new Set()
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
init(ctx: Context, options: FeatureOptions): void | Promise<any> {
|
|
@@ -20,10 +20,10 @@ class RbacFeature extends BaseFeature {
|
|
|
20
20
|
this._options = options || {}
|
|
21
21
|
this.active = (options as any).active
|
|
22
22
|
|
|
23
|
-
this._granted =
|
|
23
|
+
this._granted = new Set()
|
|
24
24
|
const perms = this._options.permissions || []
|
|
25
25
|
for (const p of perms) {
|
|
26
|
-
this._granted
|
|
26
|
+
this._granted.add(p)
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -41,7 +41,7 @@ class RbacFeature extends BaseFeature {
|
|
|
41
41
|
return
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (this._granted
|
|
44
|
+
if (this._granted.has('*') || this._granted.has(required)) {
|
|
45
45
|
this._track(ctx, required, true)
|
|
46
46
|
return
|
|
47
47
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context, FeatureOptions } from '../../types'
|
|
2
2
|
|
|
3
3
|
import { BaseFeature } from '../base/BaseFeature'
|
|
4
|
+
import { fetcher } from '../../utility/FetcherUtility'
|
|
4
5
|
import { Sekreto, envkey } from './sekreto'
|
|
5
6
|
// The plugin DEFINITIONS the model selected for this feature, emitted by
|
|
6
7
|
// Config generically from the catalogue's active `plugin.def` entries.
|
|
@@ -261,9 +262,20 @@ class SecretsFeature extends BaseFeature {
|
|
|
261
262
|
body: JSON.stringify({ [x.request]: this._refresh }),
|
|
262
263
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
263
264
|
redirect: 'manual',
|
|
265
|
+
// Its own bound: the timeout feature's wrapper is above it.
|
|
266
|
+
signal: AbortSignal.timeout(30000),
|
|
264
267
|
}
|
|
265
268
|
|
|
266
|
-
|
|
269
|
+
// The SDK transport beneath every wrapper; its GET-only refusal fails the op.
|
|
270
|
+
const send = async (at: string) => {
|
|
271
|
+
const sent: any = await fetcher(this._client._rootctx, at, fetchdef)
|
|
272
|
+
if (sent instanceof Error) {
|
|
273
|
+
throw sent
|
|
274
|
+
}
|
|
275
|
+
return sent
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let res = await send(url)
|
|
267
279
|
|
|
268
280
|
// By option alone, and only while the exchange stays on its own origin.
|
|
269
281
|
let at = url
|
|
@@ -273,7 +285,7 @@ class SecretsFeature extends BaseFeature {
|
|
|
273
285
|
break
|
|
274
286
|
}
|
|
275
287
|
at = next
|
|
276
|
-
res = await
|
|
288
|
+
res = await send(at)
|
|
277
289
|
}
|
|
278
290
|
|
|
279
291
|
const status = null == res ? 0 : res.status
|
|
@@ -34,6 +34,7 @@ class TelemetryFeature extends BaseFeature {
|
|
|
34
34
|
const span = {
|
|
35
35
|
traceId: this._id('trace'),
|
|
36
36
|
spanId: this._id('span'),
|
|
37
|
+
correlationId: ctx.id,
|
|
37
38
|
name: ((ctx.op && ctx.op.entity) || '_') + '.' + ((ctx.op && ctx.op.name) || '_'),
|
|
38
39
|
start: this._now(),
|
|
39
40
|
end: undefined as any,
|
|
@@ -131,7 +131,8 @@ class ValidateFeature extends BaseFeature {
|
|
|
131
131
|
|
|
132
132
|
|
|
133
133
|
_entitySpec(this: any, ctx: any): any {
|
|
134
|
-
|
|
134
|
+
const name = entname(ctx)
|
|
135
|
+
return Object.prototype.hasOwnProperty.call(this._spec, name) ? this._spec[name] : undefined
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
|
|
@@ -67,7 +67,7 @@ function count(val: any, dflt: number): number {
|
|
|
67
67
|
// A context without options (makeError accepts a bare one) still masks by
|
|
68
68
|
// the schema defaults.
|
|
69
69
|
function cleanConfig(ctx: any): CleanConfig {
|
|
70
|
-
const derived = ctx?.
|
|
70
|
+
const derived = ctx?.cleancfg
|
|
71
71
|
if (null != derived) {
|
|
72
72
|
return derived
|
|
73
73
|
}
|
|
@@ -26,7 +26,7 @@ function makeOptions(ctx: Context) {
|
|
|
26
26
|
const layer = (b: any) => null != b && 'object' === typeof b && !Array.isArray(b) ? b : {}
|
|
27
27
|
const cleancfg = makeCleanConfig(merge([{}, (OPTSPEC as any).clean,
|
|
28
28
|
struct.clone(layer(cfgopts.clean)), layer(opts.clean)]))
|
|
29
|
-
const cleanctx: any = {
|
|
29
|
+
const cleanctx: any = { cleancfg }
|
|
30
30
|
cleanAddSensitive(cleanctx, settings(opts))
|
|
31
31
|
for (const raw of [...splitvalues(cfgopts.clean?.values), ...splitvalues(opts.clean?.values)]) {
|
|
32
32
|
cleanAdd(cleanctx, raw)
|
|
@@ -111,13 +111,13 @@ function makeOptions(ctx: Context) {
|
|
|
111
111
|
featureorder = names
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
opts.__derived__ = {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
opts.__derived__ = { featureorder }
|
|
115
|
+
|
|
116
|
+
// Beside the options, not in them: options() hands them to callers.
|
|
117
|
+
ctx.cleancfg = cleancfg
|
|
118
118
|
|
|
119
119
|
// Again over the merged result: the config's own defaults can carry one.
|
|
120
|
-
cleanAddSensitive(
|
|
120
|
+
cleanAddSensitive(cleanctx, settings(opts))
|
|
121
121
|
|
|
122
122
|
return opts
|
|
123
123
|
}
|