@voxgig/sdkgen 4.48.0 → 4.49.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 (174) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/dist/utility.js +9 -1
  4. package/dist/utility.js.map +1 -1
  5. package/package.json +1 -1
  6. package/project/.sdk/model/feature/secrets.aontu +3 -0
  7. package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
  8. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
  9. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
  10. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
  11. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
  12. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
  13. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
  14. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
  15. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
  16. package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
  17. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
  18. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
  19. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
  20. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
  21. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
  22. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
  23. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
  24. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
  25. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
  26. package/project/.sdk/tm/c/feature/cache.c +16 -1
  27. package/project/.sdk/tm/c/feature/secrets.c +149 -18
  28. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
  29. package/project/.sdk/tm/c/tests/feature_test.c +31 -0
  30. package/project/.sdk/tm/c/utility/make_spec.c +1 -1
  31. package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
  32. package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
  34. package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
  35. package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
  36. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
  38. package/project/.sdk/tm/cpp/core/types.hpp +1 -11
  39. package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
  40. package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
  41. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
  42. package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
  43. package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
  44. package/project/.sdk/tm/csharp/core/Control.cs +0 -5
  45. package/project/.sdk/tm/csharp/core/Point.cs +6 -0
  46. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
  47. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
  48. package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
  49. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
  50. package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
  51. package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
  52. package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
  53. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
  57. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
  58. package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
  59. package/project/.sdk/tm/go/core/target.go +8 -0
  60. package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
  61. package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
  62. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
  63. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  64. package/project/.sdk/tm/go/utility/media.go +2 -2
  65. package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
  66. package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
  67. package/project/.sdk/tm/java/core/Control.java +0 -5
  68. package/project/.sdk/tm/java/core/Point.java +7 -0
  69. package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
  70. package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
  71. package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
  72. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
  73. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
  74. package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
  75. package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
  76. package/project/.sdk/tm/java/utility/Media.java +2 -2
  77. package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
  78. package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
  79. package/project/.sdk/tm/js/src/Point.js +2 -0
  80. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
  81. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
  82. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
  84. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
  85. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
  86. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  87. package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
  88. package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
  89. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
  90. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
  91. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
  92. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
  93. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
  94. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
  95. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
  96. package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
  97. package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
  98. package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
  99. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
  100. package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
  101. package/project/.sdk/tm/lua/utility/clean.lua +1 -0
  102. package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
  103. package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
  104. package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
  105. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
  106. package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
  107. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
  108. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
  109. package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
  110. package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
  111. package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
  112. package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
  113. package/project/.sdk/tm/perl/t/feature.t +24 -0
  114. package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
  115. package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
  116. package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
  117. package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
  118. package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
  119. package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
  120. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
  121. package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
  122. package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
  123. package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
  126. package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
  127. package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
  128. package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
  129. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
  130. package/project/.sdk/tm/py/test/test_feature.py +18 -0
  131. package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
  132. package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
  133. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
  134. package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
  135. package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
  136. package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
  137. package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
  138. package/project/.sdk/tm/rust/feature/cache.rs +15 -1
  139. package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
  140. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
  141. package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
  142. package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
  143. package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
  144. package/project/.sdk/tm/scala/core/Control.scala +0 -5
  145. package/project/.sdk/tm/scala/core/Point.scala +3 -0
  146. package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
  147. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
  148. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
  149. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
  150. package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
  151. package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
  152. package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
  153. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
  154. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
  159. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
  160. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
  161. package/project/.sdk/tm/ts/src/Point.ts +3 -0
  162. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
  163. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
  164. package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
  165. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
  166. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
  167. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  168. package/project/.sdk/tm/zig/core/utility.zig +47 -4
  169. package/project/.sdk/tm/zig/feature/cache.zig +15 -1
  170. package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
  171. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
  172. package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
  173. package/project/sdkgen-package.json +1 -1
  174. package/src/utility.ts +12 -1
@@ -78,6 +78,7 @@ internal class WireCall
78
78
  public string Url = "";
79
79
  public string Auth = "";
80
80
  public bool HasAuth;
81
+ public string Values = "";
81
82
  public string Body = "";
82
83
  public object? Redirect;
83
84
  }
@@ -106,11 +107,14 @@ internal class Wire
106
107
  var call = new WireCall { Url = url };
107
108
 
108
109
  if (fetchdef.TryGetValue("headers", out var hraw) &&
109
- hraw is Dictionary<string, object?> headers &&
110
- headers.TryGetValue(SecretsFeatureTest.CredHeader, out var auth))
110
+ hraw is Dictionary<string, object?> headers)
111
111
  {
112
- call.HasAuth = true;
113
- call.Auth = auth as string ?? "";
112
+ if (headers.TryGetValue(SecretsFeatureTest.CredHeader, out var auth))
113
+ {
114
+ call.HasAuth = true;
115
+ call.Auth = auth as string ?? "";
116
+ }
117
+ call.Values = string.Join("\n", headers.Values);
114
118
  }
115
119
  if (fetchdef.TryGetValue("body", out var braw) && braw is string body)
116
120
  {
@@ -197,8 +201,7 @@ public class SecretsFeatureTest
197
201
  private static bool SkippedWithoutAuth(
198
202
  [System.Runtime.CompilerServices.CallerMemberName] string test = "")
199
203
  {
200
- if (SdkConfig.SharedConfig()["options"] is Dictionary<string, object?> options &&
201
- options.ContainsKey("auth"))
204
+ if (DeclaresAuth())
202
205
  {
203
206
  return false;
204
207
  }
@@ -206,17 +209,25 @@ public class SecretsFeatureTest
206
209
  return true;
207
210
  }
208
211
 
209
- // The credential header carries the SPEC's credential prefix, which a
210
- // TEMPLATE cannot know: an OpenAPI `http`/`bearer` scheme gives
211
- // `Bearer <token>`, an apiKey scheme the raw token. So assert on the
212
- // CREDENTIAL and let the prefix be whatever this SDK's API declares -
213
- // pinning the whole header value passes only for a prefix-less API, and
214
- // this file ships to every project that selects the feature.
215
- private static void CredentialIs(string header, string token)
212
+ private static bool DeclaresAuth() =>
213
+ SdkConfig.SharedConfig()["options"] is Dictionary<string, object?> options &&
214
+ options.ContainsKey("auth");
215
+
216
+ // The header value PrepareAuth writes for a token, in the form the
217
+ // DEFAULT client's auth gives: under Basic the token is the key half of
218
+ // the encoded pair, and a prefix is space-joined.
219
+ private static string Credential(string token, string secret)
220
+ {
221
+ var auth = StructUtils.GetProp(ProjectNameSDK.TestSDK(null, null).OptionsMap(), "auth");
222
+ var prefix = StructUtils.GetProp(auth, "prefix") as string ?? "";
223
+ var value = true.Equals(StructUtils.GetProp(auth, "basic"))
224
+ ? Convert.ToBase64String(Encoding.UTF8.GetBytes(token + ":" + secret)) : token;
225
+ return "" == prefix ? value : prefix + " " + value;
226
+ }
227
+
228
+ private static void CredentialIs(string header, string token, string secret = "")
216
229
  {
217
- var got = header ?? "";
218
- Assert.True(got == token || got.EndsWith(" " + token),
219
- "expected the " + CredHeader + " header to carry " + token + ", got: " + got);
230
+ Assert.Equal(Credential(token, secret), header);
220
231
  }
221
232
 
222
233
  // Construct the client and ADOPT the feature via `extend` ONLY when the
@@ -516,6 +527,30 @@ public class SecretsFeatureTest
516
527
  }
517
528
  }
518
529
 
530
+ [Fact]
531
+ public void AResolvedKeyIsPlacedAsPrepareAuthPlacesItTheSecretKept()
532
+ {
533
+ if (SkippedWithoutAuth()) return;
534
+
535
+ Environment.SetEnvironmentVariable(EnvPrefix + "APIKEY", "ENVKEY04");
536
+ try
537
+ {
538
+ var w = new Wire();
539
+ var client = SecretsClient(w, new Dictionary<string, object?>
540
+ {
541
+ ["secret"] = "PASS01",
542
+ ["feature"] = SecretsOpts(null),
543
+ });
544
+
545
+ DriveEntityOp(client, w);
546
+ CredentialIs(w.Api()[0].Auth, "ENVKEY04", "PASS01");
547
+ }
548
+ finally
549
+ {
550
+ Environment.SetEnvironmentVariable(EnvPrefix + "APIKEY", null);
551
+ }
552
+ }
553
+
519
554
  [Fact]
520
555
  public void CustomProviderObjectsAreAcceptedVerbatim()
521
556
  {
@@ -1408,6 +1443,34 @@ public class SecretsFeatureTest
1408
1443
  }
1409
1444
  }
1410
1445
 
1446
+ [Fact]
1447
+ public void ATokenBoughtOnARefusalIsPlacedAsPrepareAuthPlacesIt()
1448
+ {
1449
+ if (SkippedWithoutAuth()) return;
1450
+
1451
+ Environment.SetEnvironmentVariable(EnvPrefix + "REFRESH_TOKEN", "REFRESH01");
1452
+ try
1453
+ {
1454
+ var w = new Wire { ApiStatus = new List<int> { 401, 200 } };
1455
+ var client = SecretsClient(w, new Dictionary<string, object?>
1456
+ {
1457
+ ["secret"] = "PASS01",
1458
+ ["feature"] = ExchangeOpts(null),
1459
+ });
1460
+
1461
+ client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
1462
+
1463
+ Assert.True(2 == w.Api().Count,
1464
+ "expected the request to be retried exactly once, got " + w.Api().Count);
1465
+ CredentialIs(w.Api()[0].Auth, "ACCESS01", "PASS01");
1466
+ CredentialIs(w.Api()[1].Auth, "ACCESS02", "PASS01");
1467
+ }
1468
+ finally
1469
+ {
1470
+ Environment.SetEnvironmentVariable(EnvPrefix + "REFRESH_TOKEN", null);
1471
+ }
1472
+ }
1473
+
1411
1474
  [Fact]
1412
1475
  public void AnExplicitExchangeRefreshWinsOverTheChain()
1413
1476
  {
@@ -1899,39 +1962,102 @@ public class SecretsFeatureTest
1899
1962
  }
1900
1963
  }
1901
1964
 
1902
- // Real listeners and the SDK's own raw fetch: a stub follows nothing.
1903
- [Fact]
1904
- public void ARedirectAnsweringTheExchangeIsAFailureAndNothingFollowsIt()
1965
+ // Real origins: this one answers the exchange as Answer says and
1966
+ // records whatever else it gets; the other records everything.
1967
+ private sealed class RedirectOrigins : IDisposable
1905
1968
  {
1906
- if (SkippedWithoutAuth()) return;
1907
-
1908
- var elsewhere = new List<string>();
1909
- var followed = new List<string>();
1910
- (int Status, string Location) answer = (307, "");
1969
+ public readonly List<string> Elsewhere = new();
1970
+ public readonly List<string> Followed = new();
1971
+ public int Exchanged;
1972
+ public (int Status, string Location) Answer = (307, "");
1973
+ public readonly ExchangeOrigin Origin;
1974
+ public readonly ExchangeOrigin Other;
1911
1975
 
1912
- using var other = new ExchangeOrigin((method, path, body) =>
1976
+ public RedirectOrigins()
1913
1977
  {
1914
- lock (elsewhere)
1978
+ Other = new ExchangeOrigin((method, path, body) =>
1915
1979
  {
1916
- elsewhere.Add(method + " " + path + " " + body);
1917
- }
1918
- return ("200 OK", null, "{\"access_token\":\"ELSEWHERE01\"}");
1919
- });
1920
- using var origin = new ExchangeOrigin((method, path, body) =>
1980
+ lock (Elsewhere)
1981
+ {
1982
+ Elsewhere.Add(method + " " + path + " " + body);
1983
+ }
1984
+ return ("200 OK", null, "{\"access_token\":\"ELSEWHERE01\"}");
1985
+ });
1986
+ Origin = new ExchangeOrigin((method, path, body) =>
1987
+ {
1988
+ lock (Followed)
1989
+ {
1990
+ if ("/api/auth/token" == path)
1991
+ {
1992
+ Exchanged++;
1993
+ return (Answer.Status + " X", Answer.Location, "");
1994
+ }
1995
+ Followed.Add((method + " " + path + " " + body).Trim());
1996
+ }
1997
+ return ("200 OK", null, "{\"access_token\":\"MOVED01\"}");
1998
+ });
1999
+ }
2000
+
2001
+ public string Base => Origin.Base + "/api";
2002
+ public string Away => Other.Base + "/api/auth/token";
2003
+
2004
+ public void Dispose()
1921
2005
  {
1922
- if ("/api/auth/token" == path)
2006
+ Origin.Dispose();
2007
+ Other.Dispose();
2008
+ }
2009
+ }
2010
+
2011
+ private static ProjectNameSDK RedirectClient(RedirectOrigins o, string? redirect = null)
2012
+ {
2013
+ return WithSecrets(extend =>
2014
+ {
2015
+ var exchange = new Dictionary<string, object?>
2016
+ {
2017
+ ["active"] = true,
2018
+ ["refresh"] = "REFRESH01",
2019
+ };
2020
+ if (null != redirect)
1923
2021
  {
1924
- return (answer.Status + " X", answer.Location, "");
2022
+ exchange["redirect"] = redirect;
1925
2023
  }
1926
- lock (followed)
2024
+ var opts = new Dictionary<string, object?>
1927
2025
  {
1928
- followed.Add(method + " " + path);
2026
+ ["base"] = o.Base,
2027
+ ["allow"] = new Dictionary<string, object?>
2028
+ {
2029
+ ["op"] = "create,update,load,list,remove,command,direct,graphql",
2030
+ },
2031
+ ["feature"] = new Dictionary<string, object?>
2032
+ {
2033
+ ["secrets"] = new Dictionary<string, object?>
2034
+ {
2035
+ ["active"] = true,
2036
+ ["name"] = "refresh_token",
2037
+ ["exchange"] = exchange,
2038
+ },
2039
+ },
2040
+ };
2041
+ if (extend)
2042
+ {
2043
+ opts["extend"] = new List<object?> { new SecretsFeature() };
1929
2044
  }
1930
- return ("200 OK", null, "{\"access_token\":\"MOVED01\"}");
2045
+ return new ProjectNameSDK(opts);
1931
2046
  });
2047
+ }
1932
2048
 
1933
- var basev = origin.Base + "/api";
1934
- var away = other.Base + "/api/auth/token";
2049
+ // Real listeners and the SDK's own raw fetch: a stub follows nothing.
2050
+ [Fact]
2051
+ public void ARedirectAnsweringTheExchangeIsAFailureAndNothingFollowsIt()
2052
+ {
2053
+ if (SkippedWithoutAuth()) return;
2054
+
2055
+ using var o = new RedirectOrigins();
2056
+ var elsewhere = o.Elsewhere;
2057
+ var followed = o.Followed;
2058
+
2059
+ var basev = o.Base;
2060
+ var away = o.Away;
1935
2061
  var answers = new[] { (307, away), (308, away), (302, away), (307, "/api/moved/token") };
1936
2062
 
1937
2063
  var allowed = new List<string>();
@@ -1939,36 +2065,8 @@ public class SecretsFeatureTest
1939
2065
 
1940
2066
  foreach (var next in answers)
1941
2067
  {
1942
- answer = next;
1943
- var client = WithSecrets(extend =>
1944
- {
1945
- var opts = new Dictionary<string, object?>
1946
- {
1947
- ["base"] = basev,
1948
- ["allow"] = new Dictionary<string, object?>
1949
- {
1950
- ["op"] = "create,update,load,list,remove,command,direct,graphql",
1951
- },
1952
- ["feature"] = new Dictionary<string, object?>
1953
- {
1954
- ["secrets"] = new Dictionary<string, object?>
1955
- {
1956
- ["active"] = true,
1957
- ["name"] = "refresh_token",
1958
- ["exchange"] = new Dictionary<string, object?>
1959
- {
1960
- ["active"] = true,
1961
- ["refresh"] = "REFRESH01",
1962
- },
1963
- },
1964
- },
1965
- };
1966
- if (extend)
1967
- {
1968
- opts["extend"] = new List<object?> { new SecretsFeature() };
1969
- }
1970
- return new ProjectNameSDK(opts);
1971
- });
2068
+ o.Answer = next;
2069
+ var client = RedirectClient(o);
1972
2070
 
1973
2071
  var res = client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
1974
2072
  var message = ErrMessage(res);
@@ -1996,6 +2094,91 @@ public class SecretsFeatureTest
1996
2094
  Assert.Equal(answers.Length, refused);
1997
2095
  }
1998
2096
 
2097
+ [Fact]
2098
+ public void WithTheOptionARedirectOnTheExchangesOwnOriginIsFollowedAndNoOther()
2099
+ {
2100
+ if (SkippedWithoutAuth()) return;
2101
+
2102
+ using var o = new RedirectOrigins();
2103
+ var sent = " {\"refresh_token\":\"REFRESH01\"}";
2104
+ // Each case: the status, the Location, and the path the exchange is
2105
+ // asked again at, or null where the redirect is refused.
2106
+ var cases = new (int, string, string?)[]
2107
+ {
2108
+ (307, "/api/moved/token", "/api/moved/token"),
2109
+ (308, o.Origin.Base + "/api/moved/token", "/api/moved/token"),
2110
+ // A Location of a query alone keeps the path that answered.
2111
+ (307, "?step=2", "/api/auth/token?step=2"),
2112
+ (307, o.Away, null),
2113
+ (302, "/api/moved/token", null),
2114
+ (307, "/api/auth/token", null),
2115
+ };
2116
+
2117
+ var wrong = new List<string>();
2118
+ var followed = 0;
2119
+ var refused = 0;
2120
+ var looped = 0;
2121
+
2122
+ foreach (var (status, location, path) in cases)
2123
+ {
2124
+ lock (o.Followed)
2125
+ {
2126
+ o.Answer = (status, location);
2127
+ o.Followed.Clear();
2128
+ o.Exchanged = 0;
2129
+ }
2130
+
2131
+ var res = RedirectClient(o, "same-origin")
2132
+ .Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
2133
+ var message = ErrMessage(res);
2134
+
2135
+ List<string> seen;
2136
+ lock (o.Followed)
2137
+ {
2138
+ seen = new List<string>(o.Followed);
2139
+ if ("/api/auth/token" == location)
2140
+ {
2141
+ looped = o.Exchanged;
2142
+ }
2143
+ }
2144
+ var report = status + " to " + location + ": ok=" + res["ok"] + " " + message +
2145
+ " [" + string.Join(" | ", seen) + "]";
2146
+
2147
+ if (null != path)
2148
+ {
2149
+ if (Equals(res["ok"], true) && 2 == seen.Count && "POST " + path + sent == seen[0])
2150
+ {
2151
+ followed++;
2152
+ }
2153
+ else
2154
+ {
2155
+ wrong.Add(report);
2156
+ }
2157
+ }
2158
+ else if (0 == seen.Count && message.Contains(
2159
+ "token exchange failed: " + status + " from " + o.Base + "/auth/token"))
2160
+ {
2161
+ refused++;
2162
+ }
2163
+ else
2164
+ {
2165
+ wrong.Add(report);
2166
+ }
2167
+ }
2168
+
2169
+ Console.WriteLine("secrets: exchange opt-in followed " + followed +
2170
+ " redirect(s) on its own origin, refused " + refused + ", " +
2171
+ o.Elsewhere.Count + " elsewhere");
2172
+
2173
+ Assert.True(0 == o.Elsewhere.Count,
2174
+ "the exchange reached another origin: " + string.Join(" | ", o.Elsewhere));
2175
+ Assert.True(0 == wrong.Count, string.Join(" || ", wrong));
2176
+ Assert.Equal(3, followed);
2177
+ Assert.Equal(3, refused);
2178
+ // A redirect to itself stops at the hop limit.
2179
+ Assert.Equal(6, looped);
2180
+ }
2181
+
1999
2182
  private static int FreePort()
2000
2183
  {
2001
2184
  var probe = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0);
@@ -2075,4 +2258,68 @@ public class SecretsFeatureTest
2075
2258
  CredentialIs(call.Auth, "FRESH01");
2076
2259
  }
2077
2260
  }
2261
+
2262
+ // --- auth off -------------------------------------------------------
2263
+ //
2264
+ // Off by the config where it declares no auth, else by `auth: null`:
2265
+ // either way the feature places no credential, buys no token and
2266
+ // retries nothing.
2267
+
2268
+ [Fact]
2269
+ public void AuthOffPlacesNoCredentialAndBuysNoToken()
2270
+ {
2271
+ var declared = DeclaresAuth();
2272
+ var secrets = new[] { "OFFKEY01", "OFFKEY02", "OFFREFRESH01", "ACCESS01" };
2273
+ bool Carries(WireCall call) => call.HasAuth || secrets.Any(call.Values.Contains);
2274
+ var sent = new List<WireCall>();
2275
+ var bought = 0;
2276
+
2277
+ var scenarios = new (string What, string Env, string Value, Dictionary<string, object?> Opts, int Status)[]
2278
+ {
2279
+ ("a key the chain resolves", "APIKEY", "OFFKEY01",
2280
+ new Dictionary<string, object?> { ["feature"] = SecretsOpts(null) }, 200),
2281
+ ("an explicit apikey", "", "",
2282
+ new Dictionary<string, object?> { ["apikey"] = "OFFKEY02", ["feature"] = SecretsOpts(null) }, 200),
2283
+ ("a refusal", "REFRESH_TOKEN", "OFFREFRESH01",
2284
+ new Dictionary<string, object?> { ["feature"] = ExchangeOpts(null) }, 401),
2285
+ };
2286
+
2287
+ foreach (var (what, env, value, opts, status) in scenarios)
2288
+ {
2289
+ if ("" != env)
2290
+ {
2291
+ Environment.SetEnvironmentVariable(EnvPrefix + env, value);
2292
+ }
2293
+ try
2294
+ {
2295
+ var w = new Wire { ApiStatus = new List<int> { status } };
2296
+ if (declared)
2297
+ {
2298
+ opts["auth"] = null;
2299
+ }
2300
+ var client = SecretsClient(w, opts);
2301
+
2302
+ client.Direct(new Dictionary<string, object?> { ["path"] = "/thing" });
2303
+
2304
+ Assert.True(1 == w.Api().Count, what + ": a request was retried with auth off");
2305
+ Assert.True(0 == w.Token().Count, what + ": a token was bought with auth off");
2306
+ Assert.False(Carries(w.Api()[0]), what + ": a credential was sent with auth off: " + w.Report());
2307
+ Assert.Equal("", SecretsOf(client)!.Credential());
2308
+
2309
+ sent.AddRange(w.Api());
2310
+ bought += w.Token().Count;
2311
+ }
2312
+ finally
2313
+ {
2314
+ if ("" != env)
2315
+ {
2316
+ Environment.SetEnvironmentVariable(EnvPrefix + env, null);
2317
+ }
2318
+ }
2319
+ }
2320
+
2321
+ Console.WriteLine("secrets: auth off by " + (declared ? "option" : "config") + ": " +
2322
+ sent.Count + " request(s), " + sent.Count(Carries) + " credential(s), " +
2323
+ bought + " token(s)");
2324
+ }
2078
2325
  }
@@ -64,8 +64,8 @@ public static partial class SdkUtility
64
64
  {
65
65
  // GraphQL addresses one endpoint: no path parts, no query
66
66
  // string, and the body carries the operation. PrepareBody is
67
- // skipped deliberately — it only emits a body for data-input
68
- // ops, whereas every GraphQL op posts one, including
67
+ // skipped deliberately — it builds only a REST body,
68
+ // whereas every GraphQL op posts one, including
69
69
  // load/list/remove.
70
70
  ctx.Spec.Body = utility.GraphqlBody(ctx);
71
71
  ctx.Spec.Path = "";
@@ -1,5 +1,7 @@
1
1
  // ProjectName SDK utility: prepareBody.
2
2
 
3
+ using Voxgig.Struct;
4
+
3
5
  namespace ProjectNameSdk.Util;
4
6
 
5
7
  public static partial class SdkUtility
@@ -18,6 +20,46 @@ public static partial class SdkUtility
18
20
  return body;
19
21
  }
20
22
 
23
+ if (StructUtils.GetProp(ctx.Point, "fields") is List<object?> fields && 0 < fields.Count)
24
+ {
25
+ return MatchBody(ctx, fields);
26
+ }
27
+
21
28
  return null;
22
29
  }
30
+
31
+ // A list, load or remove routed to a method with a body sends the match
32
+ // fields that body declares, never a path parameter, and never a header,
33
+ // cookie or query argument the body does not also declare as a field.
34
+ private static Dictionary<string, object?> MatchBody(Context ctx, List<object?> fields)
35
+ {
36
+ var routed = new List<object?>();
37
+ if (StructUtils.GetProp(ctx.Point, "params") is List<object?> pl)
38
+ {
39
+ routed.AddRange(pl);
40
+ }
41
+ if (StructUtils.GetPath(ctx.Point, StructUtils.Jt("args", "params")) is List<object?> apl)
42
+ {
43
+ routed.AddRange(apl.Select(pd => StructUtils.GetProp(pd, "name")));
44
+ }
45
+ foreach (var kind in new[] { "header", "cookie", "query" })
46
+ {
47
+ if (StructUtils.GetPath(ctx.Point, StructUtils.Jt("args", kind)) is List<object?> defs)
48
+ {
49
+ routed.AddRange(defs.Where(ad => StructUtils.GetProp(ad, "field") is not true)
50
+ .Select(ad => StructUtils.GetProp(ad, "name")));
51
+ }
52
+ }
53
+
54
+ var body = new Dictionary<string, object?>();
55
+ foreach (var field in fields)
56
+ {
57
+ if (field is string name && "$action" != name && !routed.Contains(name) &&
58
+ StructUtils.GetProp(ctx.Reqmatch, name) is { } val)
59
+ {
60
+ body[name] = val;
61
+ }
62
+ }
63
+ return body;
64
+ }
23
65
  }
@@ -32,8 +32,9 @@ public static partial class SdkUtility
32
32
  }
33
33
 
34
34
  // A header or cookie parameter travels in the headers, which
35
- // PrepareHeaders fills, unless a query parameter shares its name: then
36
- // both are sent.
35
+ // PrepareHeaders fills, and a field the point's body declares travels in
36
+ // the body, which PrepareBody fills, unless a query parameter shares its
37
+ // name: then both are sent.
37
38
  var declared = new List<object?>();
38
39
  if (point != null &&
39
40
  StructUtils.GetPath(point, StructUtils.Jt("args", "query")) is List<object?> dql)
@@ -65,6 +66,16 @@ public static partial class SdkUtility
65
66
  }
66
67
  }
67
68
  }
69
+ if (point != null && StructUtils.GetProp(point, "fields") is List<object?> afl)
70
+ {
71
+ foreach (var fd in afl)
72
+ {
73
+ if (fd is string fname && !declared.Contains(fname))
74
+ {
75
+ paramnames.Add(fname);
76
+ }
77
+ }
78
+ }
68
79
 
69
80
  // A query parameter travels under the name the definition gives it,
70
81
  // its orig, which the model may have renamed for the caller.
@@ -110,8 +110,6 @@ defmodule ProjectName.EntityBase do
110
110
  # entity is yielded as its record, the struct map its data_get/1 returns.
111
111
  # `callopts` parameterises the call:
112
112
  # - ctrl: per-call pipeline control (threaded onto the op ctx);
113
- # - body: an enumerable/list payload for outbound (upload) streaming,
114
- # attached to the request (reqdata.body$ + a stream_out marker);
115
113
  # - signal: an optional 0-arity fn; when it returns true iteration stops.
116
114
  def stream(ent, action, args \\ nil, callopts \\ nil) do
117
115
  callopts = if S.ismap(callopts), do: callopts, else: S.jm([])
@@ -134,17 +132,6 @@ defmodule ProjectName.EntityBase do
134
132
 
135
133
  ctx = Context.new(ctxmap, S.getprop(ent, "_entctx"))
136
134
 
137
- # Outbound: expose an enumerable/list payload so the request builder /
138
- # transport can stream it as the request body.
139
- body = S.getprop(callopts, "body")
140
-
141
- if body != nil do
142
- reqdata = H.or_(H.to_map(S.getprop(ctx, "reqdata")), S.jm([]))
143
- S.setprop(reqdata, "body$", body)
144
- S.setprop(ctx, "reqdata", reqdata)
145
- S.setprop(ctx, "stream_out", body)
146
- end
147
-
148
135
  Pipeline.run_op(ctx, fn -> nil end)
149
136
 
150
137
  result = S.getprop(ctx, "result")
@@ -60,16 +60,23 @@ defmodule ProjectName.Feature.Cache do
60
60
  else
61
61
  {res, err} = inner.(ctx, url, fetchdef)
62
62
 
63
- if err == nil and cacheable(res) do
64
- snap = snapshot(res)
65
- ttl = case S.getprop(opts, "ttl") do nil -> 5000; v -> v end
66
- evict(f)
67
- S.setprop(store, key, S.jm(["expiry", now + ttl, "snapshot", snap]))
68
- track(f, "miss")
69
- {replay(snap), nil}
70
- else
71
- track(f, "bypass")
72
- {res, err}
63
+ cond do
64
+ # A body that declares another type than JSON passes by, unread.
65
+ err == nil and cacheable(res) and not json?(res) ->
66
+ track(f, "bypass")
67
+ {res, err}
68
+
69
+ err == nil and cacheable(res) ->
70
+ snap = snapshot(res)
71
+ ttl = case S.getprop(opts, "ttl") do nil -> 5000; v -> v end
72
+ evict(f)
73
+ S.setprop(store, key, S.jm(["expiry", now + ttl, "snapshot", snap]))
74
+ track(f, "miss")
75
+ {replay(snap), nil}
76
+
77
+ true ->
78
+ track(f, "bypass")
79
+ {res, err}
73
80
  end
74
81
  end
75
82
  end
@@ -90,6 +97,21 @@ defmodule ProjectName.Feature.Cache do
90
97
  end
91
98
  end
92
99
 
100
+ defp json?(res) do
101
+ headers = S.getprop(res, "headers")
102
+
103
+ type =
104
+ if S.ismap(headers) do
105
+ Enum.find_value(H.entries(headers), "", fn {k, v} ->
106
+ if String.downcase(to_string(k)) == "content-type", do: to_string(v)
107
+ end)
108
+ else
109
+ ""
110
+ end
111
+
112
+ type == "" or ProjectName.Utility.json_media?(type)
113
+ end
114
+
93
115
  defp snapshot(res) do
94
116
  jf = S.getprop(res, "json")
95
117