@voxgig/sdkgen 4.48.1 → 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 (119) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/secrets.aontu +3 -0
  4. package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
  5. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
  6. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
  7. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
  8. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
  9. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
  10. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
  11. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
  12. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
  13. package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
  14. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
  15. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
  16. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
  17. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
  18. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
  19. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
  20. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
  21. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
  22. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
  23. package/project/.sdk/tm/c/feature/cache.c +16 -1
  24. package/project/.sdk/tm/c/feature/secrets.c +149 -18
  25. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
  26. package/project/.sdk/tm/c/tests/feature_test.c +31 -0
  27. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
  28. package/project/.sdk/tm/clojure/src/sdk/core.clj +8 -1
  29. package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
  30. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
  31. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
  32. package/project/.sdk/tm/cpp/core/types.hpp +1 -11
  33. package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
  34. package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
  35. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
  36. package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
  37. package/project/.sdk/tm/csharp/core/Control.cs +0 -5
  38. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
  39. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
  40. package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
  41. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
  42. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
  43. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
  44. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
  45. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
  46. package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
  47. package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
  48. package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
  49. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
  50. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  51. package/project/.sdk/tm/go/utility/media.go +2 -2
  52. package/project/.sdk/tm/java/core/Control.java +0 -5
  53. package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
  54. package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
  55. package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
  56. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
  57. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
  58. package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
  59. package/project/.sdk/tm/java/utility/Media.java +2 -2
  60. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
  61. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
  62. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
  63. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  64. package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
  65. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
  66. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
  67. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
  68. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
  69. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
  70. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
  71. package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
  72. package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
  73. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
  74. package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
  75. package/project/.sdk/tm/lua/utility/clean.lua +1 -0
  76. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
  77. package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
  78. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
  79. package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
  80. package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
  81. package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
  82. package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
  83. package/project/.sdk/tm/perl/t/feature.t +24 -0
  84. package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
  85. package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
  86. package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
  87. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
  88. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
  89. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
  90. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
  91. package/project/.sdk/tm/py/test/test_feature.py +18 -0
  92. package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
  93. package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
  94. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
  95. package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
  96. package/project/.sdk/tm/rust/feature/cache.rs +15 -1
  97. package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
  98. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
  99. package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
  100. package/project/.sdk/tm/scala/core/Control.scala +0 -5
  101. package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
  102. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
  103. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
  104. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
  105. package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
  106. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
  107. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
  108. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
  109. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
  110. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
  111. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
  112. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
  113. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
  114. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  115. package/project/.sdk/tm/zig/feature/cache.zig +15 -1
  116. package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
  117. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
  118. package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
  119. package/project/sdkgen-package.json +1 -1
@@ -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
  {