@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.
Files changed (218) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/debug.c +1 -0
  30. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  31. package/project/.sdk/tm/c/feature/telemetry.c +1 -0
  32. package/project/.sdk/tm/c/tests/feature_test.c +142 -0
  33. package/project/.sdk/tm/c/utility/clean.c +26 -33
  34. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  35. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  36. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  37. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  38. package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
  39. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
  40. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  41. package/project/.sdk/tm/cpp/Makefile +5 -0
  42. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  43. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  44. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  45. package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
  46. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  47. package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
  48. package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
  49. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  50. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  51. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  52. package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
  53. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  54. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
  55. package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
  56. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  57. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  58. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  59. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  60. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  61. package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
  62. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  63. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
  64. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  65. package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
  66. package/project/.sdk/tm/go/core/context.go +6 -0
  67. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  68. package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
  69. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  70. package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
  71. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  72. package/project/.sdk/tm/go/test/feature_test.go +101 -0
  73. package/project/.sdk/tm/go/utility/clean.go +5 -7
  74. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  75. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  76. package/project/.sdk/tm/java/core/Context.java +9 -0
  77. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  78. package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
  79. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  80. package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
  81. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  82. package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
  83. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  84. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  85. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  86. package/project/.sdk/tm/js/src/Context.js +4 -0
  87. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  88. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  89. package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
  90. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  91. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  92. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  93. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  94. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
  95. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  96. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  97. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  98. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  99. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  100. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  101. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  102. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  103. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  104. package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
  105. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  106. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
  107. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
  108. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  109. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  110. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  111. package/project/.sdk/tm/lua/core/context.lua +6 -0
  112. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  113. package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
  114. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  115. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
  116. package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
  117. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  118. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  119. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  120. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  121. package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
  122. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  123. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  124. package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
  125. package/project/.sdk/tm/perl/core/context.pm +3 -0
  126. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  127. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  128. package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
  129. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  130. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
  131. package/project/.sdk/tm/perl/t/feature.t +86 -0
  132. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  133. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  134. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  135. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  136. package/project/.sdk/tm/php/core/Context.php +4 -0
  137. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  138. package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
  139. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  140. package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
  141. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  142. package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
  143. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  144. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  145. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  146. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  147. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  148. package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
  149. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  150. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
  151. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  152. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  153. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  154. package/project/.sdk/tm/py/test/test_feature.py +73 -0
  155. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  156. package/project/.sdk/tm/rb/core/context.rb +4 -1
  157. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  158. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  159. package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
  160. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  161. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
  162. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  163. package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
  164. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  165. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  166. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  167. package/project/.sdk/tm/rust/core/context.rs +8 -0
  168. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  169. package/project/.sdk/tm/rust/feature/debug.rs +1 -0
  170. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  171. package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
  172. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  173. package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
  174. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  175. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  176. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  177. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  178. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  179. package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
  180. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  181. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
  182. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
  183. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  184. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  185. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  186. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  187. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  188. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
  189. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  190. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
  191. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  192. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  193. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  194. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
  195. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  196. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  197. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  198. package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
  199. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  200. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  201. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  202. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  203. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
  204. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  205. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  206. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  207. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  208. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  209. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  210. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  211. package/project/.sdk/tm/zig/core/context.zig +5 -0
  212. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  213. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  214. package/project/.sdk/tm/zig/feature/debug.zig +1 -0
  215. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  216. package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
  217. package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
  218. package/project/sdkgen-package.json +1 -1
@@ -262,9 +262,93 @@ let ratelimit_feature () : feature =
262
262
  (* cache *)
263
263
  (* ------------------------------------------------------------------ *)
264
264
 
265
+ (* No HMAC in the stdlib: HMAC-MD5 over Digest separates header sets within
266
+ one client's store without holding a header value. It is not a
267
+ cryptographic commitment. *)
268
+ let cache_hmac (key : string) (msg : string) : string =
269
+ let key = if String.length key > 64 then Digest.string key else key in
270
+ let key = key ^ String.make (64 - String.length key) '\000' in
271
+ let pad c = String.map (fun ch -> Char.chr (Char.code ch lxor c)) key in
272
+ Digest.to_hex (Digest.string (pad 0x5c ^ Digest.string (pad 0x36 ^ msg)))
273
+
274
+ let cache_secret () : string =
275
+ let from_os =
276
+ try
277
+ let ic = open_in_bin "/dev/urandom" in
278
+ Fun.protect ~finally:(fun () -> close_in_noerr ic) (fun () -> Some (really_input_string ic 32))
279
+ with _ -> None in
280
+ match from_os with
281
+ | Some s -> s
282
+ | None ->
283
+ let st = Random.State.make_self_init () in
284
+ String.init 32 (fun _ -> Char.chr (Random.State.int st 256))
285
+
286
+ let cache_header_text (v : value) : string option =
287
+ match v with Noval | Null -> None | Str s -> Some s | _ -> Some (vstr_of v)
288
+
289
+ let cache_digest (secret : string) (headers : value) : string =
290
+ let pairs = match headers with
291
+ | Map _ ->
292
+ List.filter_map (fun k ->
293
+ Option.map (fun t -> (string_lower k, t)) (cache_header_text (getp headers k))) (keysof headers)
294
+ | _ -> [] in
295
+ let text = String.concat "" (List.map (fun (k, v) -> k ^ ":" ^ v ^ "\n") (List.sort compare pairs)) in
296
+ cache_hmac secret text
297
+
298
+ (* The configured ttl capped by the response's Cache-Control; zero when the
299
+ response may not be stored. *)
300
+ let cache_lifetime (headers : value) (ttl : float) : float =
301
+ let control = match headers with
302
+ | Map _ ->
303
+ List.fold_left (fun acc k ->
304
+ if string_lower k = "cache-control" then
305
+ (match cache_header_text (getp headers k) with Some t -> string_lower t | None -> acc)
306
+ else acc) "" (keysof headers)
307
+ | _ -> "" in
308
+ let directives = List.map String.trim (String.split_on_char ',' control) in
309
+ if List.exists (fun d -> List.mem d ["no-store"; "private"; "no-cache"]) directives then 0.
310
+ else
311
+ List.fold_left (fun life d ->
312
+ let n = String.length d in
313
+ if n > 7 && String.sub d 0 7 = "max-age" then begin
314
+ let rest = String.trim (String.sub d 7 (n - 7)) in
315
+ if String.length rest > 0 && rest.[0] = '=' then begin
316
+ let v = String.trim (String.sub rest 1 (String.length rest - 1)) in
317
+ let lv = String.length v in
318
+ let v = if lv >= 2 && v.[0] = '"' && v.[lv - 1] = '"' then String.sub v 1 (lv - 2) else v in
319
+ let rec digits i = i >= String.length v || (v.[i] >= '0' && v.[i] <= '9' && digits (i + 1)) in
320
+ if v <> "" && digits 0 then
321
+ (match float_of_string_opt v with Some secs -> Float.min life (secs *. 1000.) | None -> life)
322
+ else life
323
+ end else life
324
+ end else life) ttl directives
325
+
326
+ let cache_scope (url : string) : string =
327
+ let n = String.length url in
328
+ let rec cut i = if i >= n then n else (match url.[i] with '?' | '#' -> i | _ -> cut (i + 1)) in
329
+ let rec trim e = if e > 0 && url.[e - 1] = '/' then trim (e - 1) else e in
330
+ String.sub url 0 (trim (cut 0))
331
+
332
+ let cache_parent (scope : string) : string =
333
+ let n = String.length scope in
334
+ let rec find_scheme i = if i + 3 > n then None else if String.sub scope i 3 = "://" then Some i else find_scheme (i + 1) in
335
+ let root = match find_scheme 0 with
336
+ | None -> Some 0
337
+ | Some at -> String.index_from_opt scope (at + 3) '/' in
338
+ match root with
339
+ | None -> scope
340
+ | Some root ->
341
+ let cut = match String.rindex_opt scope '/' with Some c -> c | None -> 0 in
342
+ String.sub scope 0 (max cut root)
343
+
344
+ let cache_under (scope : string) (prefix : string) : bool =
345
+ let lp = String.length prefix in
346
+ scope = prefix || (String.length scope > lp && String.sub scope 0 lp = prefix && scope.[lp] = '/')
347
+
265
348
  let cache_feature () : feature =
266
349
  let options = ref (empty_map ()) in
267
350
  let store = ref [] in
351
+ let secret = ref "" in
268
352
  let f = { f_name = "cache"; f_version = "0.0.1"; f_active = true; f_options = Noval;
269
353
  f_init = (fun _ _ -> ()); f_hook = (fun _ _ -> ()) } in
270
354
  let track ctx kind =
@@ -293,12 +377,20 @@ let cache_feature () : feature =
293
377
  let evict () =
294
378
  let mx = opt_int !options "max" ~default:256 in
295
379
  while List.length !store >= mx do (match !store with _ :: tl -> store := tl | [] -> ()) done in
380
+ let invalidate url =
381
+ let path = cache_scope url in
382
+ let collection = cache_parent path in
383
+ store := List.filter (fun (_, e) ->
384
+ let scope = vstr_of (getp e "scope") in
385
+ not (cache_under scope path || scope = collection)) !store in
296
386
  let through ctx url fetchdef inner =
297
387
  let meth = match getp fetchdef "method" with Str s -> string_upper s | _ -> "GET" in
298
388
  let methods = List.map string_upper (opt_str_list !options "methods" ~default:["GET"]) in
299
- if not (List.mem meth methods) then inner ctx url fetchdef
300
- else begin
301
- let key = meth ^ " " ^ url in
389
+ if not (List.mem meth methods) then begin
390
+ if meth = "GET" || meth = "HEAD" then inner ctx url fetchdef
391
+ else Fun.protect ~finally:(fun () -> invalidate url) (fun () -> inner ctx url fetchdef)
392
+ end else begin
393
+ let key = meth ^ " " ^ url ^ " " ^ cache_digest !secret (getp fetchdef "headers") in
302
394
  let now = now_of !options in
303
395
  match List.assoc_opt key !store with
304
396
  | Some hit when (match getp hit "expiry" with Num e -> e > now | _ -> false) ->
@@ -309,11 +401,16 @@ let cache_feature () : feature =
309
401
  if err = None && cacheable res && not (json res) then (track ctx "bypass"; (res, err))
310
402
  else if err = None && cacheable res then begin
311
403
  let snap = snapshot res in
312
- let ttl = opt_num !options "ttl" ~default:5000. in
313
- evict ();
314
- store := (List.remove_assoc key !store) @ [(key, jo [("expiry", Num (now +. ttl)); ("snapshot", snap)])];
315
- track ctx "miss";
316
- (replay snap, None)
404
+ let ttl = cache_lifetime (getp snap "headers") (opt_num !options "ttl" ~default:5000.) in
405
+ if ttl <= 0. then (track ctx "bypass"; (replay snap, None))
406
+ else begin
407
+ store := List.remove_assoc key !store;
408
+ evict ();
409
+ store := !store @ [(key, jo [("expiry", Num (now +. ttl)); ("scope", Str (cache_scope url));
410
+ ("snapshot", snap)])];
411
+ track ctx "miss";
412
+ (replay snap, None)
413
+ end
317
414
  end else (track ctx "bypass"; (res, err))
318
415
  end in
319
416
  f.f_init <- (fun ctx opts ->
@@ -321,6 +418,7 @@ let cache_feature () : feature =
321
418
  f.f_active <- opt_active opts;
322
419
  if f.f_active then begin
323
420
  store := [];
421
+ secret := cache_secret ();
324
422
  let u = cu ctx in
325
423
  let inner = u.u_fetcher in
326
424
  u.u_fetcher <- (fun fctx url fd -> through fctx url fd inner)
@@ -665,6 +763,7 @@ let telemetry_feature () : feature =
665
763
  let entity = if ctx.c_op.op_entity <> "" then ctx.c_op.op_entity else "_" in
666
764
  let opname = if ctx.c_op.op_name <> "" then ctx.c_op.op_name else "_" in
667
765
  let span = jo [("traceId", Str (gen_id "trace")); ("spanId", Str (gen_id "span"));
766
+ ("correlationId", Str ctx.c_id);
668
767
  ("name", Str (entity ^ "." ^ opname)); ("start", Num (now_of !options));
669
768
  ("end", Noval); ("durationMs", Noval); ("ok", Noval)] in
670
769
  scratch_set ctx "telemetry_span" span;
@@ -733,6 +832,7 @@ let debug_feature () : feature =
733
832
  let opname = (if ctx.c_op.op_entity <> "" then ctx.c_op.op_entity else "_") ^ "." ^ (if ctx.c_op.op_name <> "" then ctx.c_op.op_name else "_") in
734
833
  let entry = jo [
735
834
  ("op", Str opname);
835
+ ("correlationId", Str ctx.c_id);
736
836
  ("method", (match ctx.c_spec with Some s -> Str s.sp_method | None -> Noval));
737
837
  ("url", (match ctx.c_spec with Some s -> Str (if s.sp_url <> "" then s.sp_url else s.sp_path) | None -> Noval));
738
838
  ("headers", redact ctx (match ctx.c_spec with Some s -> s.sp_headers | None -> Noval));
@@ -226,6 +226,7 @@ let make_context_impl (cs : ctxspec) (basectx : ctx option) : ctx =
226
226
  let options =
227
227
  match cs.cs_options with Some (Map _ as m) -> m
228
228
  | _ -> (match basectx with Some b -> b.c_options | None -> Noval) in
229
+ let cleancfg = match basectx with Some b -> b.c_cleancfg | None -> Noval in
229
230
  let entity =
230
231
  match cs.cs_entity with Some _ as e -> e
231
232
  | None -> (match basectx with Some b -> b.c_entity | None -> None) in
@@ -248,6 +249,7 @@ let make_context_impl (cs : ctxspec) (basectx : ctx option) : ctx =
248
249
  c_id = id; c_out = Hashtbl.create 8; c_ctrl = ctrl; c_meta = meta;
249
250
  c_client = client; c_utility = utility; c_op = new_operation (empty_map ());
250
251
  c_point = point; c_config = config; c_entopts = entopts; c_options = options;
252
+ c_cleancfg = cleancfg;
251
253
  c_opmap = opmap; c_response = response; c_result = result; c_spec = spec;
252
254
  c_data = data; c_reqdata = reqdata; c_match = mtch; c_reqmatch = reqmatch;
253
255
  c_entity = entity; c_shared = shared; c_scratch = Hashtbl.create 8;
@@ -302,9 +304,9 @@ let count_opt (v : value) (dflt : int) : int =
302
304
  | _ -> None in
303
305
  match n with Some n when n >= 0. -> int_of_float (Float.floor n) | _ -> dflt
304
306
 
305
- (* The derived clean block: a struct map so it lives in options.__derived__
306
- * and its `values` list stays MUTABLE after make_options - features
307
- * register what they resolve later. *)
307
+ (* The clean registry: a struct map held on the context as c_cleancfg, whose
308
+ * `values` list stays MUTABLE after make_options - features register what
309
+ * they resolve later. *)
308
310
  let make_clean_config (cleanopts : value) : value =
309
311
  jo [("active", Bool (getp cleanopts "active" <> Bool false));
310
312
  ("keys", ja (List.map (fun s -> Str s) (splitkeys (getp cleanopts "keys"))));
@@ -313,10 +315,10 @@ let make_clean_config (cleanopts : value) : value =
313
315
  ("hint", vint_of (count_opt (getp cleanopts "hint") 0));
314
316
  ("min", vint_of (max 1 (count_opt (getp cleanopts "min") 4)))]
315
317
 
316
- (* A context without options (make_error accepts a bare one) still masks by
317
- * the schema defaults. *)
318
+ (* A context without a registry (make_error accepts a bare one) still masks
319
+ * by the schema defaults. *)
318
320
  let clean_config (ctx : ctx) : value =
319
- match getpath_s ctx.c_options "__derived__.clean" with
321
+ match ctx.c_cleancfg with
320
322
  | Map _ as m -> m
321
323
  | _ -> make_clean_config (getp (Sdk_schema.opt_spec_value ()) "clean")
322
324
 
@@ -1776,7 +1778,7 @@ let make_options_util (ctx : ctx) : value =
1776
1778
  | Map _ -> List.iter (fun k -> setp cleanraw k (getp src k)) (keysof src)
1777
1779
  | _ -> ()) [getp optspec "clean"; getp cfgopts "clean"; getp opts "clean"];
1778
1780
  let cleancfg = make_clean_config cleanraw in
1779
- let cleanctx = { ctx with c_options = jo [("__derived__", jo [("clean", cleancfg)])] } in
1781
+ let cleanctx = { ctx with c_cleancfg = cleancfg } in
1780
1782
  clean_add_sensitive cleanctx (secret_scan opts ["clean"]);
1781
1783
  List.iter (fun src -> List.iter (clean_add_util cleanctx) (splitvalues (getpath_s src "clean.values")))
1782
1784
  [cfgopts; opts];
@@ -1857,11 +1859,12 @@ let make_options_util (ctx : ctx) : value =
1857
1859
  if List.mem "test" names
1858
1860
  then "test" :: List.filter (fun n -> n <> "test") names
1859
1861
  else names in
1860
- let derived = jo [("clean", cleancfg);
1861
- ("featureorder", ja (List.map (fun s -> Str s) feature_order))] in
1862
+ let derived = jo [("featureorder", ja (List.map (fun s -> Str s) feature_order))] in
1862
1863
  setp opts "__derived__" derived;
1864
+ (* Beside the options, not in them: options_map hands them to callers. *)
1865
+ ctx.c_cleancfg <- cleancfg;
1863
1866
  (* Again over the merged result: the config's own defaults can carry one. *)
1864
- clean_add_sensitive { ctx with c_options = opts } (secret_scan opts ["clean"; "__derived__"]);
1867
+ clean_add_sensitive cleanctx (secret_scan opts ["clean"; "__derived__"]);
1865
1868
  opts
1866
1869
 
1867
1870
  (* ------------------------------------------------------------------ *)
@@ -263,6 +263,8 @@ and ctx = {
263
263
  mutable c_config : value;
264
264
  mutable c_entopts : value;
265
265
  mutable c_options : value;
266
+ (* The clean registry, beside the options rather than in them. *)
267
+ mutable c_cleancfg : value;
266
268
  (* Shared by every context of one client, so by requests on other domains:
267
269
  * a map replaced whole, never changed in place. *)
268
270
  mutable c_opmap : operation OpMap.t Atomic.t;
@@ -215,7 +215,41 @@ let () =
215
215
  let (srv, calls) = recording_server () in
216
216
  let h = make_client ~server:srv [("cache", jo [("active", Bool false)])] in
217
217
  ignore (op h ~op:"load" ~path:"/x" ()); ignore (op h ~op:"load" ~path:"/x" ());
218
- check_int "calls" (List.length !calls) 2)
218
+ check_int "calls" (List.length !calls) 2);
219
+ test "cache.keys_on_request_headers" (fun () ->
220
+ let (srv, calls) = recording_server () in
221
+ let h = make_client ~server:srv [("cache", jo [("ttl", Num 10000.)])] in
222
+ ignore (op h ~op:"load" ~path:"/w/1" ~headers:[("x-tenant", Str "tenant-a")] ());
223
+ ignore (op h ~op:"load" ~path:"/w/1" ~headers:[("X-Tenant", Str "tenant-b")] ());
224
+ check_int "tenant calls" (List.length !calls) 2;
225
+ ignore (op h ~op:"load" ~path:"/w/1" ~headers:[("x-tenant", Str "tenant-b")] ());
226
+ check_int "same headers calls" (List.length !calls) 2);
227
+ test "cache.write_drops_collection" (fun () ->
228
+ let (srv, calls) = recording_server () in
229
+ let h = make_client ~server:srv [("cache", jo [("ttl", Num 10000.)])] in
230
+ let paths = ["/w/1"; "/w"; "/w/1/part"; "/other/1"; "/w/2"] in
231
+ List.iter (fun p -> ignore (op h ~op:"load" ~path:p ())) paths;
232
+ ignore (op h ~op:"update" ~method_:"PUT" ~path:"/w/1" ());
233
+ List.iter (fun p -> ignore (op h ~op:"load" ~path:p ())) paths;
234
+ check_int "calls" (List.length !calls) 9;
235
+ check_vnum "hit" (getp (track h "cache") "hit") 2.);
236
+ test "cache.control_prevents_storing" (fun () ->
237
+ List.iter (fun control ->
238
+ let (srv, calls) = recording_server
239
+ ~reply:(fun _ _ -> (make_response ~headers:[("Cache-Control", Str control)] 200 (jo [("ok", Bool true)]), None)) () in
240
+ let h = make_client ~server:srv [("cache", jo [("ttl", Num 10000.)])] in
241
+ ignore (op h ~op:"load" ~path:"/w" ()); ignore (op h ~op:"load" ~path:"/w" ());
242
+ check_int control (List.length !calls) 2)
243
+ ["no-store"; "private"; "No-Cache"; "max-age=60, private"]);
244
+ test "cache.max_age_caps_ttl" (fun () ->
245
+ let c = make_clock () in
246
+ let (srv, calls) = recording_server
247
+ ~reply:(fun _ _ -> (make_response ~headers:[("cache-control", Str "max-age=1")] 200 (jo [("ok", Bool true)]), None)) () in
248
+ let h = make_client ~server:srv [("cache", jo [("ttl", Num 10000.); ("now", clock_now_fn c)])] in
249
+ ignore (op h ~op:"load" ~path:"/w" ()); clock_advance c 500.; ignore (op h ~op:"load" ~path:"/w" ());
250
+ check_int "inside max-age" (List.length !calls) 1;
251
+ clock_advance c 600.; ignore (op h ~op:"load" ~path:"/w" ());
252
+ check_int "after max-age" (List.length !calls) 2)
219
253
  end;
220
254
 
221
255
  (* ---------------- idempotency ---------------- *)
@@ -408,6 +442,22 @@ let () =
408
442
  check_int "records" (size (getp (track h "audit") "records")) 0)
409
443
  end;
410
444
 
445
+ (* ---------------- one call, one id ---------------- *)
446
+ if has_feature "telemetry" && has_feature "debug" && has_feature "audit" then begin
447
+ test "telemetry_debug_audit.one_context_id" (fun () ->
448
+ let h = make_client [("telemetry", empty_map ()); ("debug", empty_map ()); ("audit", empty_map ())] in
449
+ ignore (op h ~op:"load" ());
450
+ ignore (op h ~op:"list" ());
451
+ let ids recs = ja (List.init (size recs) (fun i -> getp (getelem recs (Num (float_of_int i))) "correlationId")) in
452
+ let calls = ids (getp (track h "audit") "records") in
453
+ check_int "records" (size calls) 2;
454
+ check ("string ids " ^ stringify calls)
455
+ (List.for_all (function Str s -> s <> "" | _ -> false) (match calls with List r -> !r | _ -> []));
456
+ check "one id per call" (not (veq (getelem calls (Num 0.)) (getelem calls (Num 1.))));
457
+ check "span ids" (veq (ids (getp (track h "telemetry") "spans")) calls);
458
+ check "debug entry ids" (veq (ids (getp (track h "debug") "entries")) calls))
459
+ end;
460
+
411
461
  (* ---------------- clienttrack ---------------- *)
412
462
  if has_feature "clienttrack" then begin
413
463
  test "clienttrack.stable_id_ua" (fun () ->
@@ -65,6 +65,9 @@ sub new {
65
65
  my $o = $gcp->($ctxmap, 'options');
66
66
  $self->{options} = Voxgig::Struct::ismap($o) ? $o : ($basectx ? $basectx->{options} : undef);
67
67
 
68
+ # The clean registry, beside the options rather than in them.
69
+ $self->{cleancfg} = $gcp->($ctxmap, 'cleancfg') // ($basectx ? $basectx->{cleancfg} : undef);
70
+
68
71
  my $e = $gcp->($ctxmap, 'entity');
69
72
  $self->{entity} = defined $e ? $e : ($basectx ? $basectx->{entity} : undef);
70
73
 
@@ -14,7 +14,6 @@ use warnings;
14
14
 
15
15
  use File::Basename ();
16
16
  use Cwd ();
17
- use Scalar::Util ();
18
17
 
19
18
  my $__dir;
20
19
  BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
@@ -36,7 +35,6 @@ sub new {
36
35
  $self->{client} = undef;
37
36
  $self->{options} = {};
38
37
  $self->{seq} = 0;
39
- $self->{seen} = {};
40
38
  return $self;
41
39
  }
42
40
 
@@ -46,7 +44,6 @@ sub init {
46
44
  $self->{options} = Voxgig::Struct::ismap($options) ? $options : {};
47
45
  $self->{active} = ProjectNameHelpers::is_true($self->{options}{active});
48
46
  $self->{seq} = 0;
49
- $self->{seen} = {};
50
47
 
51
48
  return unless $self->{active};
52
49
 
@@ -76,10 +73,10 @@ sub PreUnexpected {
76
73
  sub _emit {
77
74
  my ($self, $ctx, $outcome) = @_;
78
75
  # One record per operation (PreDone + a following PreUnexpected on a
79
- # non-2xx must not double-log).
80
- my $addr = Scalar::Util::refaddr($ctx);
81
- return if exists $self->{seen}{$addr};
82
- $self->{seen}{$addr} = 1;
76
+ # non-2xx must not double-log). The marker lives on the context: a table
77
+ # keyed by refaddr grows per call, and a reused address skips a call.
78
+ return if $ctx->{out}{audit_seen};
79
+ $ctx->{out}{audit_seen} = 1;
83
80
  $self->{seq} += 1;
84
81
 
85
82
  my $record = $ctx->{utility}{clean}->($ctx, {
@@ -1,12 +1,7 @@
1
1
  # ProjectName SDK cache feature
2
2
  #
3
- # Response caching for safe (read) requests. Wraps the active transport and
4
- # serves a fresh cached snapshot instead of hitting the network when the
5
- # same method+URL was fetched within "ttl" ms (default 5000). Only
6
- # successful (2xx) responses to cacheable methods (default: GET) are
7
- # stored, keyed by method+URL. The cache is bounded ("max" entries, default
8
- # 256, oldest evicted first) and every hit/miss/bypass is counted for
9
- # inspection. Replayed responses expose a re-readable "json" body.
3
+ # Response caching for safe (read) requests, per client: see the features
4
+ # reference for the key, the write invalidation and the Cache-Control rules.
10
5
 
11
6
  use strict;
12
7
  use warnings;
@@ -14,6 +9,7 @@ use warnings;
14
9
  use File::Basename ();
15
10
  use Cwd ();
16
11
  use Scalar::Util ();
12
+ use Digest::SHA ();
17
13
 
18
14
  my $__dir;
19
15
  BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
@@ -52,6 +48,7 @@ sub init {
52
48
 
53
49
  $self->{store} = {};
54
50
  $self->{order} = [];
51
+ $self->{secret} = _cache_secret();
55
52
 
56
53
  my $feature = $self;
57
54
  my $utility = $ctx->{utility};
@@ -70,10 +67,18 @@ sub through {
70
67
  ? uc("$fetchdef->{method}") : 'GET';
71
68
  my $methods = $self->{options}{methods} || ['GET'];
72
69
 
73
- return $inner->($ctx, $url, $fetchdef)
74
- unless grep { uc("$_") eq $method } @$methods;
70
+ unless (grep { uc("$_") eq $method } @$methods) {
71
+ return $inner->($ctx, $url, $fetchdef) if $method eq 'GET' || $method eq 'HEAD';
72
+ my @out;
73
+ my $done = eval { @out = $inner->($ctx, $url, $fetchdef); 1 };
74
+ my $failure = $@;
75
+ $self->_invalidate($url);
76
+ die $failure unless $done;
77
+ return @out;
78
+ }
75
79
 
76
- my $key = "$method $url";
80
+ my $headers = Voxgig::Struct::ismap($fetchdef) ? $fetchdef->{headers} : undef;
81
+ my $key = "$method $url " . $self->_digest($headers);
77
82
  my $now = $self->_now;
78
83
  my $hit = $self->{store}{$key};
79
84
 
@@ -92,12 +97,17 @@ sub through {
92
97
 
93
98
  if (!defined $err && $self->_cacheable($res)) {
94
99
  my $snapshot = $self->_snapshot($res);
95
- my $ttl = defined $self->{options}{ttl} ? $self->{options}{ttl} : 5000;
96
- $self->_evict;
97
- if (!exists $self->{store}{$key}) {
98
- push @{ $self->{order} }, $key;
100
+ my $ttl = _cache_lifetime($snapshot->{headers},
101
+ defined $self->{options}{ttl} ? $self->{options}{ttl} : 5000);
102
+ if ($ttl <= 0) {
103
+ $self->_track('bypass');
104
+ return ($self->_replay($snapshot), undef);
99
105
  }
100
- $self->{store}{$key} = { 'expiry' => $now + $ttl, 'snapshot' => $snapshot };
106
+ $self->_drop($key);
107
+ $self->_evict;
108
+ push @{ $self->{order} }, $key;
109
+ $self->{store}{$key} = {
110
+ 'expiry' => $now + $ttl, 'scope' => _cache_scope($url), 'snapshot' => $snapshot };
101
111
  $self->_track('miss');
102
112
  return ($self->_replay($snapshot), undef);
103
113
  }
@@ -106,6 +116,92 @@ sub through {
106
116
  return ($res, $err);
107
117
  }
108
118
 
119
+ sub _digest {
120
+ my ($self, $headers) = @_;
121
+ my @pairs;
122
+ if (Voxgig::Struct::ismap($headers)) {
123
+ for my $name (keys %$headers) {
124
+ next unless defined $headers->{$name};
125
+ push @pairs, [lc($name), "$headers->{$name}"];
126
+ }
127
+ }
128
+ my $text = join('', map { "$_->[0]:$_->[1]\n" }
129
+ sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @pairs);
130
+ return Digest::SHA::hmac_sha256_hex($text, $self->{secret});
131
+ }
132
+
133
+ sub _invalidate {
134
+ my ($self, $url) = @_;
135
+ my $path = _cache_scope($url);
136
+ my $collection = _cache_parent($path);
137
+ for my $key (keys %{ $self->{store} }) {
138
+ my $scope = $self->{store}{$key}{scope};
139
+ $self->_drop($key) if _cache_under($scope, $path) || $scope eq $collection;
140
+ }
141
+ return;
142
+ }
143
+
144
+ sub _drop {
145
+ my ($self, $key) = @_;
146
+ return unless exists $self->{store}{$key};
147
+ delete $self->{store}{$key};
148
+ $self->{order} = [grep { $_ ne $key } @{ $self->{order} }];
149
+ return;
150
+ }
151
+
152
+ # The system's random source where it has one; otherwise Perl's own rand,
153
+ # which is not a cryptographic generator.
154
+ sub _cache_secret {
155
+ my $bytes = '';
156
+ if (open(my $fh, '<:raw', '/dev/urandom')) {
157
+ read($fh, $bytes, 32);
158
+ close($fh);
159
+ }
160
+ $bytes .= pack('N', int(rand(4294967296))) while length($bytes) < 32;
161
+ return $bytes;
162
+ }
163
+
164
+ # The configured ttl capped by the response's Cache-Control; zero when the
165
+ # response may not be stored.
166
+ sub _cache_lifetime {
167
+ my ($headers, $ttl) = @_;
168
+ my $control = '';
169
+ for my $name (keys %{ $headers || {} }) {
170
+ $control = lc("$headers->{$name}") if lc($name) eq 'cache-control';
171
+ }
172
+ my $life = $ttl;
173
+ for my $part (split /,/, $control) {
174
+ (my $directive = $part) =~ s/^\s+|\s+$//g;
175
+ return 0 if grep { $_ eq $directive } ('no-store', 'private', 'no-cache');
176
+ if ($directive =~ /^max-age\s*=\s*"?(\d+)"?$/) {
177
+ $life = $1 * 1000 if $1 * 1000 < $life;
178
+ }
179
+ }
180
+ return $life;
181
+ }
182
+
183
+ sub _cache_scope {
184
+ my ($url) = @_;
185
+ my ($scope) = split /[?#]/, "$url", 2;
186
+ $scope = '' unless defined $scope;
187
+ $scope =~ s{/+$}{};
188
+ return $scope;
189
+ }
190
+
191
+ sub _cache_parent {
192
+ my ($scope) = @_;
193
+ my $scheme = index($scope, '://');
194
+ my $root = $scheme < 0 ? 0 : index($scope, '/', $scheme + 3);
195
+ return $scope if $root < 0;
196
+ my $cut = rindex($scope, '/');
197
+ return substr($scope, 0, $cut < $root ? $root : $cut);
198
+ }
199
+
200
+ sub _cache_under {
201
+ my ($scope, $prefix) = @_;
202
+ return $scope eq $prefix || index($scope, "$prefix/") == 0;
203
+ }
204
+
109
205
  sub _cacheable {
110
206
  my ($self, $res) = @_;
111
207
  return 0 unless Voxgig::Struct::ismap($res);
@@ -67,6 +67,7 @@ sub PreRequest {
67
67
  my $entry = {
68
68
  'op' => ($ctx->{op} ? $ctx->{op}{entity} : '_') . '.'
69
69
  . ($ctx->{op} ? $ctx->{op}{name} : '_'),
70
+ 'correlationId' => $ctx->{id},
70
71
  'method' => $method,
71
72
  'url' => $url,
72
73
  'headers' => $self->_redact($ctx, $headers),
@@ -334,6 +334,7 @@ sub transport {
334
334
  # provider ERROR refuses the request with the provider's own message;
335
335
  # never an unauthenticated send.
336
336
  my $err = $self->resolve();
337
+ return (undef, $err) if Scalar::Util::blessed($err) && $err->isa('ProjectNameError');
337
338
  if (defined $err) {
338
339
  return (undef, $ctx->make_error('secrets_resolve', $err));
339
340
  }
@@ -594,24 +595,12 @@ sub _buy_once {
594
595
  $path =~ s{\A/+}{};
595
596
  my $url = "$base/$path";
596
597
 
597
- # Deliberately NOT the SDK transport. The transport is what this feature
598
- # wraps, and sending the token request back through it would recurse on
599
- # the first expiry - and would route the exchange through the test mock,
600
- # which knows nothing about it. `system.fetch` (the caller's own
601
- # transport seam) when supplied, else the raw HTTP fetch the utility
602
- # registry keeps beside its own fetcher.
603
- my $fetch = ProjectNameHelpers::gpath($options, 'system.fetch');
604
- if (!(defined $fetch && 'CODE' eq ref $fetch)) {
605
- # utility/fetcher.pm keeps the raw HTTP transport as a package global
606
- # BESIDE its registered fetcher, precisely so a caller that must not
607
- # recurse through the wrapper (or trip the test-mode block) can reach
608
- # it. `once` is disabled because this file names it exactly once.
609
- no warnings 'once';
610
- $fetch = $ProjectNameUtilities::DefaultHttpFetch;
611
- }
612
-
613
- return (undef, 'secrets: no fetch implementation for the token exchange')
614
- if !(defined $fetch && 'CODE' eq ref $fetch);
598
+ # The SDK's own transport, beneath every feature's wrapper: it holds the
599
+ # test feature's block and the GET-only guard, and the wrapped one would
600
+ # recurse on the first expiry.
601
+ my $ctx = $self->{ctx};
602
+ no warnings 'once';
603
+ my $fetch = sub { $ProjectNameUtilities::REGISTRY{fetcher}->($ctx, @_) };
615
604
 
616
605
  # The body is MARSHALLED, never concatenated: a refresh token (or a
617
606
  # configured request-field name) carrying a quote, backslash or newline
@@ -624,6 +613,8 @@ sub _buy_once {
624
613
  'body' => $body,
625
614
  # Never followed by the client: a redirect would carry the refresh token on.
626
615
  'redirect' => 'manual',
616
+ # Its own bound, in milliseconds: the timeout feature's wrapper is above it.
617
+ 'timeout' => 30000,
627
618
  };
628
619
 
629
620
  my ($res, $err);
@@ -644,6 +635,10 @@ sub _buy_once {
644
635
 
645
636
  return (undef, _trim("$@")) if !$ok;
646
637
 
638
+ # The transport's own refusal, the GET-only guard's among them, is the
639
+ # operation's error.
640
+ return (undef, $err) if Scalar::Util::blessed($err) && $err->isa('ProjectNameError');
641
+
647
642
  return (undef, 'secrets: token exchange failed: ' . _trim("$err") . " from $url")
648
643
  if defined $err;
649
644
 
@@ -61,6 +61,7 @@ sub PrePoint {
61
61
  my $span = {
62
62
  'traceId' => $self->_id('trace'),
63
63
  'spanId' => $self->_id('span'),
64
+ 'correlationId' => $ctx->{id},
64
65
  'name' => ($ctx->{op} ? $ctx->{op}{entity} : '_') . '.'
65
66
  . ($ctx->{op} ? $ctx->{op}{name} : '_'),
66
67
  'start' => $self->_now,