@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
@@ -1200,7 +1200,7 @@ inline SpecPtr makeSpec(CtxPtr ctx) {
1200
1200
  if ("graphql" == as_str(getp(ctx->point, "kind"))) {
1201
1201
  // GraphQL addresses one endpoint: no path parts, no query string, and
1202
1202
  // the body carries the operation. prepareBody is skipped deliberately
1203
- // — it only emits a body for data-input ops, whereas every GraphQL op
1203
+ // — it builds only a REST body, whereas every GraphQL op
1204
1204
  // posts one, including load/list/remove.
1205
1205
  ctx->spec->body = graphqlBody(ctx);
1206
1206
  ctx->spec->path = "";
@@ -1599,11 +1599,48 @@ inline Value mediaHeaders(const Value& point, Value headers) {
1599
1599
  // A string Value holds any bytes, and they are sent as they are.
1600
1600
  inline Value rawBody(const Value& reqdata) { return getp(reqdata, rawBodyKey()); }
1601
1601
 
1602
+ // A list, load or remove routed to a method with a body sends the match
1603
+ // fields that body declares, never a path parameter, and never a header,
1604
+ // cookie or query argument the body does not also declare as a field.
1605
+ inline Value matchBody(CtxPtr ctx, const Value& fields) {
1606
+ std::vector<std::string> routed;
1607
+ Value params = getp(ctx->point, "params");
1608
+ if (params.is_list()) {
1609
+ for (const auto& p : *params.as_list()) {
1610
+ if (p.is_string()) routed.push_back(p.as_string());
1611
+ }
1612
+ }
1613
+ for (const char* kind : {"params", "header", "cookie", "query"}) {
1614
+ Value defs = getp(getp(ctx->point, "args"), kind);
1615
+ if (!defs.is_list()) continue;
1616
+ for (const auto& ad : *defs.as_list()) {
1617
+ Value n = getp(ad, "name");
1618
+ Value f = getp(ad, "field");
1619
+ bool kept = std::string("params") != kind && f.is_bool() && f.as_bool();
1620
+ if (n.is_string() && !kept) routed.push_back(n.as_string());
1621
+ }
1622
+ }
1623
+
1624
+ Value body = vmap();
1625
+ for (const auto& f : *fields.as_list()) {
1626
+ if (!f.is_string()) continue;
1627
+ std::string name = f.as_string();
1628
+ Value val = getp(ctx->reqmatch, name);
1629
+ if (!is_nullish(val) && "$action" != name &&
1630
+ std::find(routed.begin(), routed.end(), name) == routed.end()) {
1631
+ map_put(body, name, val);
1632
+ }
1633
+ }
1634
+ return body;
1635
+ }
1636
+
1602
1637
  inline Value prepareBody(CtxPtr ctx) {
1603
1638
  if (ctx->op->input == "data") {
1604
1639
  if (isRawRequest(ctx->point)) return rawBody(ctx->reqdata);
1605
1640
  return ctx->utility->transformRequest(ctx);
1606
1641
  }
1642
+ Value fields = getp(ctx->point, "fields");
1643
+ if (fields.is_list() && !fields.as_list()->empty()) return matchBody(ctx, fields);
1607
1644
  return Value::undef();
1608
1645
  }
1609
1646
 
@@ -1782,6 +1819,16 @@ inline Value prepareParams(CtxPtr ctx) {
1782
1819
 
1783
1820
  // ---- prepareQuery -----------------------------------------------------
1784
1821
 
1822
+ // Whether the point's body declares this field, which prepareBody sends.
1823
+ inline bool bodyField(const Value& point, const std::string& name) {
1824
+ Value fields = getp(point, "fields");
1825
+ if (!fields.is_list()) return false;
1826
+ for (const auto& f : *fields.as_list()) {
1827
+ if (f.is_string() && f.as_string() == name) return true;
1828
+ }
1829
+ return false;
1830
+ }
1831
+
1785
1832
  inline Value prepareQuery(CtxPtr ctx) {
1786
1833
  Value point = ctx->point;
1787
1834
  Value reqmatch = ctx->reqmatch;
@@ -1815,10 +1862,11 @@ inline Value prepareQuery(CtxPtr ctx) {
1815
1862
  return false;
1816
1863
  };
1817
1864
 
1818
- // A header or cookie parameter travels in the headers, which prepareHeaders
1819
- // fills, unless a query parameter shares its name: then both are sent.
1865
+ // A header or cookie parameter travels in the headers, and a body field in
1866
+ // the body, unless a query parameter shares its name: then both are sent.
1820
1867
  Value aquery = point.is_map() ? getp(getp(point, "args"), "query") : Value::undef();
1821
- auto elsewhere = [&](const std::string& s) { return (named(aheader, s) || named(acookie, s)) && !named(aquery, s); };
1868
+ auto located = [&](const std::string& s) { return named(aheader, s) || named(acookie, s) || bodyField(point, s); };
1869
+ auto elsewhere = [&](const std::string& s) { return located(s) && !named(aquery, s); };
1822
1870
 
1823
1871
  // A query parameter travels under the name the definition gives it, its
1824
1872
  // orig, which the model may have renamed for the caller.
@@ -9,9 +9,4 @@ public class Control
9
9
  public Dictionary<string, object?>? Explain;
10
10
  public string Actor = "";
11
11
  public Dictionary<string, object?>? Paging;
12
-
13
- // Outbound streaming marker: the entity `stream` method sets this to the
14
- // caller-supplied async payload so the request builder / transport can
15
- // stream it as the request body.
16
- public object? Stream_out;
17
12
  }
@@ -19,6 +19,8 @@ public class Point
19
19
  public List<object?>? Relations;
20
20
  public Dictionary<string, object?> Alias = new();
21
21
  public Dictionary<string, object?> Transform = new();
22
+ // The fields a list, load or remove sends in a request body.
23
+ public List<object?>? Fields;
22
24
 
23
25
  public Point(Dictionary<string, object?>? pointmap)
24
26
  {
@@ -66,5 +68,9 @@ public class Point
66
68
  {
67
69
  Transform = tf;
68
70
  }
71
+ if (StructUtils.GetProp(pointmap, "fields") is List<object?> fl)
72
+ {
73
+ Fields = fl;
74
+ }
69
75
  }
70
76
  }
@@ -7,6 +7,8 @@
7
7
  // are snapshotted on capture so both the current caller and later hits can
8
8
  // re-read the JSON body repeatedly.
9
9
 
10
+ using ProjectNameSdk.Util;
11
+
10
12
  using static ProjectNameSdk.Feature.FeatureOptions;
11
13
 
12
14
  namespace ProjectNameSdk.Feature;
@@ -99,6 +101,13 @@ public class CacheFeature : BaseFeature
99
101
  err = ex;
100
102
  }
101
103
 
104
+ // A body that declares another type than JSON passes by, unread.
105
+ if (err == null && Storable(res) && !Json(res))
106
+ {
107
+ Bypass++;
108
+ return res;
109
+ }
110
+
102
111
  if (err == null && Storable(res))
103
112
  {
104
113
  var snapshot = Snapshot(res);
@@ -126,6 +135,13 @@ public class CacheFeature : BaseFeature
126
135
  !(res is Dictionary<string, object?> rm && rm.TryGetValue("unreadable", out var u) && u is true);
127
136
  }
128
137
 
138
+ private static bool Json(object? res)
139
+ {
140
+ var headers = res is Dictionary<string, object?> rm ? rm.GetValueOrDefault("headers") : null;
141
+ var type = Response.HeaderValue(headers, "content-type");
142
+ return type == "" || SdkUtility.IsJsonMedia(type);
143
+ }
144
+
129
145
  private static CacheSnapshot Snapshot(object? res)
130
146
  {
131
147
  var rm = res as Dictionary<string, object?>;
@@ -92,6 +92,11 @@ public class SecretsFeature : BaseFeature
92
92
  // never writes it (see the header).
93
93
  private Dictionary<string, object?>? _liveopts;
94
94
 
95
+ // What PrepareAuth was generated from: the config declares auth only
96
+ // where it places a credential, and Basic only where it composes one.
97
+ private bool _declared;
98
+ private bool _basic;
99
+
95
100
  private string _secretname = "apikey";
96
101
  private bool _cache = true;
97
102
  private Sekreto? _sek;
@@ -133,6 +138,11 @@ public class SecretsFeature : BaseFeature
133
138
  _liveopts = ctx.Options;
134
139
  Active = FoptBool(options, "active", false);
135
140
 
141
+ var declared = StructUtils.GetPath(ctx.Config, StructUtils.Jt("options", "auth"));
142
+ _declared = declared is Dictionary<string, object?>;
143
+ _basic = declared is Dictionary<string, object?> authdecl &&
144
+ authdecl.TryGetValue("basic", out var basic) && true.Equals(basic);
145
+
136
146
  if (!Active)
137
147
  {
138
148
  return;
@@ -172,6 +182,7 @@ public class SecretsFeature : BaseFeature
172
182
  Response = FoptStr(xopts, "response", "access_token"),
173
183
  Statuses = statuses,
174
184
  Retries = FoptInt(xopts, "retries", 1),
185
+ SameOrigin = "same-origin" == FoptStr(xopts, "redirect", "refuse"),
175
186
  };
176
187
  }
177
188
 
@@ -412,7 +423,7 @@ public class SecretsFeature : BaseFeature
412
423
  // from a miss it must not keep.
413
424
  private bool ResolveOnce()
414
425
  {
415
- if (null == _sek)
426
+ if (null == _sek || AuthSuppressed())
416
427
  {
417
428
  return false;
418
429
  }
@@ -469,18 +480,6 @@ public class SecretsFeature : BaseFeature
469
480
  return true;
470
481
  }
471
482
 
472
- // `auth: null` is the documented way to send NO credential, and a
473
- // purchase is a credential-bearing call: the refresh token goes to
474
- // the token endpoint in the request body. WithRefresh honours
475
- // suppression for the RETRY, but it runs after this - by then the
476
- // refresh token has already left the process, and no later check
477
- // can call it back. The suppression has to be honoured here, before
478
- // the first purchase, or it only ever half-held.
479
- if (AuthSuppressed())
480
- {
481
- return false;
482
- }
483
-
484
483
  Buy();
485
484
 
486
485
  return true;
@@ -531,11 +530,8 @@ public class SecretsFeature : BaseFeature
531
530
  private object? WithRefresh(Context ctx, string url,
532
531
  Dictionary<string, object?> fetchdef, FetcherFunc inner)
533
532
  {
534
- // `auth: null` is the documented way to send NO credential, and
535
- // PrepareAuth honours it by removing the header. A refusal of a
536
- // deliberately unauthenticated request is not an expired token and
537
- // cannot be fixed by buying one - retrying would transmit exactly
538
- // the credential the caller suppressed.
533
+ // A refusal of an unauthenticated request is not an expired token,
534
+ // and retrying would transmit the credential that auth off withholds.
539
535
  if (AuthSuppressed())
540
536
  {
541
537
  return inner(ctx, url, fetchdef);
@@ -611,18 +607,13 @@ public class SecretsFeature : BaseFeature
611
607
  return false;
612
608
  }
613
609
 
614
- // `auth` ABSENT and `auth` PRESENT-AND-NULL both mean suppression.
615
- //
616
- // go gets away with one nil check because a Go map returns nil for
617
- // both; a C# Dictionary does not, and MakeOptions.cs deliberately
618
- // RESTORES a supplied `auth: null` after validate (that IS csharp's
619
- // auth-suppression fix). Testing only for absence would re-transmit
620
- // exactly the credential the caller suppressed. Same two-branch shape
621
- // PrepareAuth uses.
610
+ // PrepareAuth's decision: suppressed where the config declares no auth,
611
+ // and where `auth` is absent or a present null. MakeOptions.cs restores
612
+ // a supplied `auth: null` after validate, so absence alone misses it.
622
613
  private bool AuthSuppressed()
623
614
  {
624
615
  var opts = _liveopts;
625
- if (null == opts)
616
+ if (!_declared || null == opts)
626
617
  {
627
618
  return true;
628
619
  }
@@ -652,10 +643,22 @@ public class SecretsFeature : BaseFeature
652
643
  return;
653
644
  }
654
645
 
646
+ var value = _basic && true.Equals(StructUtils.GetPath(_liveopts, StructUtils.Jt("auth", "basic")))
647
+ ? Pair(token) : token;
648
+
655
649
  var prefix = StructUtils.GetPath(_liveopts, StructUtils.Jt("auth", "prefix"))
656
650
  as string ?? "";
657
651
 
658
- headers[name] = "" == prefix ? token : prefix + " " + token;
652
+ headers[name] = "" == prefix ? value : prefix + " " + value;
653
+ }
654
+
655
+ // Under Basic the token is the key half, as apikey is: PrepareAuth's pair.
656
+ private string Pair(string token)
657
+ {
658
+ var secret = StructUtils.GetProp(_liveopts, "secret") as string ?? "";
659
+ var pair = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(token + ":" + secret));
660
+ Register(pair);
661
+ return pair;
659
662
  }
660
663
 
661
664
  // ---------------------------------------------------------------
@@ -780,7 +783,7 @@ public class SecretsFeature : BaseFeature
780
783
  ["content-type"] = "application/json",
781
784
  },
782
785
  ["body"] = body,
783
- // Never followed: a redirect would carry the refresh token on.
786
+ // Never followed by the client: a redirect would carry the refresh token on.
784
787
  ["redirect"] = "manual",
785
788
  };
786
789
 
@@ -799,18 +802,32 @@ public class SecretsFeature : BaseFeature
799
802
  // system.fetch seam promises.
800
803
  var sysfetch = StructUtils.GetPath(options, StructUtils.Jt("system", "fetch"));
801
804
 
802
- object? res;
803
- if (sysfetch is Func<string, Dictionary<string, object?>, Dictionary<string, object?>> ff)
804
- {
805
- res = ff(url, fetchdef);
806
- }
807
- else if (sysfetch is Func<string, Dictionary<string, object?>, object?> ffa)
805
+ object? Fetch(string at)
808
806
  {
809
- res = ffa(url, fetchdef);
807
+ if (sysfetch is Func<string, Dictionary<string, object?>, Dictionary<string, object?>> ff)
808
+ {
809
+ return ff(at, fetchdef);
810
+ }
811
+ if (sysfetch is Func<string, Dictionary<string, object?>, object?> ffa)
812
+ {
813
+ return ffa(at, fetchdef);
814
+ }
815
+ return SdkUtility.DefaultHttpFetch(at, fetchdef);
810
816
  }
811
- else
817
+
818
+ var res = Fetch(url);
819
+
820
+ // By option alone, and only while the exchange stays on its own origin.
821
+ var here = url;
822
+ for (var hops = 0; x.SameOrigin && hops < RedirectMax; hops++)
812
823
  {
813
- res = SdkUtility.DefaultHttpFetch(url, fetchdef);
824
+ var next = Moved(url, here, res);
825
+ if (null == next)
826
+ {
827
+ break;
828
+ }
829
+ here = next;
830
+ res = Fetch(here);
814
831
  }
815
832
 
816
833
  var status = Helpers.ToInt(StructUtils.GetProp(res, "status"));
@@ -860,6 +877,27 @@ public class SecretsFeature : BaseFeature
860
877
  return token;
861
878
  }
862
879
 
880
+ private const int RedirectMax = 5;
881
+
882
+ // Where a redirect that keeps method and body points, when that is on the
883
+ // exchange's own origin. Any other would drop the body or leave the origin.
884
+ private static string? Moved(string url, string at, object? res)
885
+ {
886
+ var status = Helpers.ToInt(StructUtils.GetProp(res, "status"));
887
+ if ((307 != status && 308 != status) ||
888
+ StructUtils.GetProp(StructUtils.GetProp(res, "headers"), "location") is not string location ||
889
+ "" == location ||
890
+ !Uri.TryCreate(at, UriKind.Absolute, out var here) ||
891
+ !Uri.TryCreate(here, location, out var next) ||
892
+ !Uri.TryCreate(url, UriKind.Absolute, out var own))
893
+ {
894
+ return null;
895
+ }
896
+ var same = own.Scheme == next.Scheme && own.Port == next.Port &&
897
+ string.Equals(own.Host, next.Host, StringComparison.OrdinalIgnoreCase);
898
+ return same ? next.AbsoluteUri : null;
899
+ }
900
+
863
901
  // ---------------------------------------------------------------
864
902
  // The type-model seam.
865
903
 
@@ -918,6 +956,7 @@ internal sealed class SecretsExchange
918
956
  public string Response = "access_token";
919
957
  public List<int> Statuses = new() { 401 };
920
958
  public int Retries = 1;
959
+ public bool SameOrigin;
921
960
  }
922
961
 
923
962
  // One shared in-flight resolution: late arrivals wait on Done and read Err.
@@ -543,6 +543,35 @@ public class FeatureCacheTest
543
543
  Assert.Equal(3, rec.Calls.Count);
544
544
  }
545
545
 
546
+ [Fact]
547
+ public void BodyOfAnotherTypeThanJsonPassesByUnread()
548
+ {
549
+ if (Fh.SkipWithout("cache")) return;
550
+ var sent = new List<Dictionary<string, object?>>();
551
+ var rec = new FhRecorder
552
+ {
553
+ Reply = (_, _) =>
554
+ {
555
+ var res = Fh.Response(200, null, new Dictionary<string, object?>
556
+ {
557
+ ["content-type"] = "audio/wav",
558
+ });
559
+ res["body"] = new byte[] { 0x52, 0x49, 0x46, 0x46 };
560
+ sent.Add(res);
561
+ return res;
562
+ },
563
+ };
564
+ var f = new CacheFeature();
565
+ var h = Fh.Make(rec.Fetch, (f, null));
566
+ var a = h.Op(new FhOpSpec { Op = "load", Path = "/w/1/audio" });
567
+ var b = h.Op(new FhOpSpec { Op = "load", Path = "/w/1/audio" });
568
+ Assert.True(2 == rec.Calls.Count, "the body was stored");
569
+ Assert.True(ReferenceEquals(sent[0]["body"], a.Ctx?.Response?.Body),
570
+ "the cache handed on a copy it had read");
571
+ Assert.True(ReferenceEquals(sent[1]["body"], b.Ctx?.Response?.Body));
572
+ Assert.Equal(2, f.Bypass);
573
+ }
574
+
546
575
  [Fact]
547
576
  public void InactiveDoesNotWrap()
548
577
  {