@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
@@ -30,8 +30,9 @@ class ProjectNamePrepareQuery
30
30
  }
31
31
  }
32
32
  // A header or cookie parameter travels in the headers, which
33
- // prepareHeaders fills, unless a query parameter shares its name:
34
- // then both are sent.
33
+ // prepareHeaders fills, and a field the point's body declares
34
+ // travels in the body, which prepareBody fills, unless a query
35
+ // parameter shares its name: then both are sent.
35
36
  $ql = \Voxgig\Struct\Struct::getpath($point, 'args.query');
36
37
  $declared = is_array($ql)
37
38
  ? array_map(fn($qd) => \Voxgig\Struct\Struct::getprop($qd, 'name'), $ql) : [];
@@ -46,6 +47,12 @@ class ProjectNamePrepareQuery
46
47
  }
47
48
  }
48
49
  }
50
+ $fields = \Voxgig\Struct\Struct::getprop($point, 'fields');
51
+ foreach (is_array($fields) ? $fields : [] as $name) {
52
+ if (is_string($name) && !in_array($name, $declared, true)) {
53
+ $params[] = $name;
54
+ }
55
+ }
49
56
  }
50
57
  // A query parameter travels under the name the definition gives it,
51
58
  // its orig, which the model may have renamed for the caller.
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
  import time
5
5
 
6
6
  from projectname_sdk.feature.base_feature import ProjectNameBaseFeature
7
+ from projectname_sdk.utility.media import header_value, is_json_media
7
8
 
8
9
 
9
10
  # Response caching for safe (read) requests. Wraps the active transport and
@@ -84,7 +85,12 @@ class ProjectNameCacheFeature(ProjectNameBaseFeature):
84
85
  status = res.get("status")
85
86
  if not isinstance(status, (int, float)) or isinstance(status, bool):
86
87
  return False
87
- return 200 <= status < 300
88
+ return 200 <= status < 300 and self._json(res)
89
+
90
+ # A body that declares another type than JSON passes by, unread.
91
+ def _json(self, res):
92
+ ctype = header_value(res.get("headers"), "content-type")
93
+ return ctype == "" or is_json_media(ctype)
88
94
 
89
95
  def _snapshot(self, res):
90
96
  data = None
@@ -1,8 +1,10 @@
1
1
  # ProjectName SDK secrets feature
2
2
 
3
3
  from __future__ import annotations
4
+ import base64
4
5
  import json
5
6
  import urllib.error
7
+ import urllib.parse
6
8
  import urllib.request
7
9
 
8
10
  from projectname_sdk.utility.voxgig_struct import voxgig_struct as vs
@@ -90,6 +92,8 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
90
92
  self.active = True
91
93
 
92
94
  self._client = None
95
+ self._declared = False
96
+ self._basic = False
93
97
  self._sekreto = None
94
98
  self._secretname = "apikey"
95
99
  self._resolved = False
@@ -109,6 +113,13 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
109
113
 
110
114
  self._client = client
111
115
 
116
+ # What prepare_auth was generated from: the config declares auth only
117
+ # where it places a credential, and Basic only where it composes one.
118
+ configopts = vs.getprop(ctx.config, "options")
119
+ declared = vs.getprop(configopts, "auth") if isinstance(configopts, dict) else None
120
+ self._declared = isinstance(declared, dict)
121
+ self._basic = self._declared and declared.get("basic") is True
122
+
112
123
  name = fopts.get("name")
113
124
  self._secretname = name if isinstance(name, str) and "" != name \
114
125
  else "apikey"
@@ -131,6 +142,8 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
131
142
  "retries": xopts.get("retries")
132
143
  if isinstance(xopts.get("retries"), (int, float))
133
144
  and not isinstance(xopts.get("retries"), bool) else 1,
145
+ "redirect": "same-origin"
146
+ if "same-origin" == xopts.get("redirect") else "refuse",
134
147
  }
135
148
  else:
136
149
  self._exchange = None
@@ -199,6 +212,11 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
199
212
  def sekreto(self):
200
213
  return self._sekreto
201
214
 
215
+ # prepare_auth's decision: auth the config declares, not suppressed by
216
+ # `auth: None`.
217
+ def _authon(self):
218
+ return self._declared and self._client.options.get("auth") is not None
219
+
202
220
  # Every value this feature resolves or buys is a secret the SDK handles,
203
221
  # and none arrives under an option key the intake registration saw.
204
222
  def _register(self, value):
@@ -233,7 +251,7 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
233
251
  # bool is the whole of what resolve() needs to tell a cacheable HIT
234
252
  # from a miss it must not retain.
235
253
  def _resolve_once(self):
236
- if self._sekreto is None:
254
+ if self._sekreto is None or not self._authon():
237
255
  return False
238
256
 
239
257
  # Miss-vs-error: `try_` answers None for "no store has it" and
@@ -277,16 +295,6 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
277
295
  # another, which is the same path expiry takes anyway.
278
296
  return True
279
297
 
280
- # `auth: None` is the documented way to send NO credential, and a
281
- # purchase is a credential-bearing call: the refresh token goes to
282
- # the token endpoint in the request body. _with_refresh honours
283
- # suppression for the RETRY, but it runs after this - by then the
284
- # refresh token has already left the process, and no later check
285
- # can call it back. The suppression has to be honoured here, before
286
- # the first purchase, or it only ever half-held.
287
- if self._client.options_map().get("auth") is None:
288
- return False
289
-
290
298
  self._client.options["apikey"] = self._buy()
291
299
 
292
300
  return True
@@ -342,13 +350,28 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
342
350
  # feature wraps, and sending the token request back through it
343
351
  # would recurse on the first 401 - and would route the exchange
344
352
  # through the test mock, which knows nothing about it.
345
- res, err = fetch(url, {
353
+ fetchdef = {
346
354
  "method": x["method"],
347
355
  "headers": {"content-type": "application/json"},
348
356
  "body": json.dumps({x["request"]: self._refresh}),
349
- # Never followed: a redirect would carry the refresh token on.
357
+ # Never followed by the client: a redirect would carry the
358
+ # refresh token on.
350
359
  "redirect": "manual",
351
- })
360
+ }
361
+
362
+ res, err = fetch(url, fetchdef)
363
+
364
+ # By option alone, and only while the exchange stays on its own origin.
365
+ at = url
366
+ hops = 0
367
+ while "same-origin" == x["redirect"] and hops < _REDIRECT_MAX \
368
+ and err is None:
369
+ nxt = _moved(url, at, res)
370
+ if nxt is None:
371
+ break
372
+ at = nxt
373
+ res, err = fetch(at, fetchdef)
374
+ hops += 1
352
375
 
353
376
  if err is not None:
354
377
  raise Exception(
@@ -395,12 +418,9 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
395
418
  x = self._exchange
396
419
  max_retries = 0 if x is None else x["retries"]
397
420
 
398
- # `auth: None` is the documented way to send NO credential, and
399
- # prepare_auth honours it by removing the header. A refusal of a
400
- # deliberately unauthenticated request is not an expired token and
401
- # cannot be fixed by buying one - retrying would transmit exactly
402
- # the credential the caller suppressed.
403
- if self._client.options_map().get("auth") is None:
421
+ # A refusal of an unauthenticated request is not an expired token,
422
+ # and retrying would transmit the credential that auth off withholds.
423
+ if not self._authon():
404
424
  return inner(ctx, url, fetchdef)
405
425
 
406
426
  attempt = 0
@@ -451,13 +471,9 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
451
471
  not isinstance(fetchdef.get("headers"), dict):
452
472
  return
453
473
 
454
- auth = self._client.options_map().get("auth")
474
+ auth = self._client.options.get("auth")
455
475
 
456
- # Suppressed auth means NO header, the same answer prepare_auth
457
- # gives. Reached defensively - _with_refresh does not retry at all
458
- # when auth is None - but this is the function that writes the
459
- # credential, so it is where the rule has to hold.
460
- if auth is None:
476
+ if not self._authon():
461
477
  fetchdef["headers"].pop("authorization", None)
462
478
  return
463
479
 
@@ -466,9 +482,51 @@ class ProjectNameSecretsFeature(ProjectNameBaseFeature):
466
482
  name = name.lower() if isinstance(name, str) and "" != name \
467
483
  else "authorization"
468
484
 
485
+ value = token
486
+ if self._basic and isinstance(auth, dict) and auth.get("basic") is True:
487
+ value = self._pair(token)
488
+
469
489
  prefix = auth.get("prefix") if isinstance(auth, dict) else None
470
490
  fetchdef["headers"][name] = \
471
- prefix + " " + token if prefix else token
491
+ prefix + " " + value if prefix else value
492
+
493
+ # Under Basic the token is the key half, as apikey is: prepare_auth's pair.
494
+ def _pair(self, token):
495
+ secret = self._client.options.get("secret")
496
+ pair = base64.b64encode(
497
+ (str(token) + ":" + ("" if secret is None else str(secret))).encode("utf-8")
498
+ ).decode("ascii")
499
+ self._register(pair)
500
+ return pair
501
+
502
+
503
+ _REDIRECT_MAX = 5
504
+
505
+
506
+ def _origin(parts):
507
+ port = parts.port or {"http": 80, "https": 443}.get(parts.scheme)
508
+ return (parts.scheme, parts.hostname, port)
509
+
510
+
511
+ def _moved(url, at, res):
512
+ """Where a 307 or 308 points, when that is on the exchange's own
513
+ origin. Any other redirect would drop the body or leave the origin."""
514
+ status = res.get("status") if isinstance(res, dict) else None
515
+ if status not in (307, 308):
516
+ return None
517
+
518
+ headers = res.get("headers")
519
+ location = headers.get("location") if isinstance(headers, dict) else None
520
+ if not isinstance(location, str) or "" == location:
521
+ return None
522
+
523
+ try:
524
+ nxt = urllib.parse.urljoin(at, location)
525
+ same = _origin(urllib.parse.urlsplit(nxt)) == \
526
+ _origin(urllib.parse.urlsplit(url))
527
+ except ValueError:
528
+ return None
529
+ return nxt if same else None
472
530
 
473
531
 
474
532
  class _NoRedirect(urllib.request.HTTPRedirectHandler):
@@ -500,6 +558,7 @@ def _raw_exchange_fetch(fullurl, fetchdef):
500
558
  with _NO_REDIRECT.open(req, timeout=30) as res:
501
559
  raw = res.read()
502
560
  status = res.status
561
+ headers = {k.lower(): v for k, v in res.headers.items()}
503
562
 
504
563
  def _json():
505
564
  try:
@@ -507,11 +566,13 @@ def _raw_exchange_fetch(fullurl, fetchdef):
507
566
  except Exception:
508
567
  return None
509
568
 
510
- return {"status": status, "json": _json}, None
569
+ return {"status": status, "headers": headers, "json": _json}, None
511
570
  except urllib.error.HTTPError as e:
512
571
  # A non-2xx answer IS a response: hand back its status so the
513
572
  # caller reports "token exchange failed: <status>" rather than a
514
573
  # transport error.
515
- return {"status": e.code, "json": lambda: None}, None
574
+ headers = {k.lower(): v for k, v in (e.headers or {}).items()}
575
+ return {"status": e.code, "headers": headers,
576
+ "json": lambda: None}, None
516
577
  except Exception as e:
517
578
  return None, e
@@ -64,7 +64,7 @@ def make_spec_util(ctx):
64
64
  if "graphql" == vs.getprop(point, "kind"):
65
65
  # GraphQL addresses one endpoint: no path parts, no query string,
66
66
  # and the body carries the operation. prepare_body is skipped
67
- # deliberately — it only emits a body for data-input ops, whereas
67
+ # deliberately — it builds only a REST body, whereas
68
68
  # every GraphQL op posts one, including load/list/remove.
69
69
  ctx.spec.body = utility.graphql_body(ctx)
70
70
  ctx.spec.path = ""
@@ -1,5 +1,6 @@
1
1
  # ProjectName SDK utility: prepare_body
2
2
 
3
+ from projectname_sdk.utility.voxgig_struct import voxgig_struct as vs
3
4
  from projectname_sdk.utility.media import is_raw_request, raw_body
4
5
 
5
6
 
@@ -12,4 +13,29 @@ def prepare_body_util(ctx):
12
13
  body = ctx.utility.transform_request(ctx)
13
14
  return body
14
15
 
16
+ fields = vs.getprop(ctx.point, "fields") if ctx.point is not None else None
17
+ if isinstance(fields, list) and 0 < len(fields):
18
+ return _match_body(ctx, fields)
19
+
15
20
  return None
21
+
22
+
23
+ # A list, load or remove routed to a method with a body sends the match
24
+ # fields that body declares, never a path parameter, and never a header,
25
+ # cookie or query argument the body does not also declare as a field.
26
+ def _match_body(ctx, fields):
27
+ point = ctx.point
28
+ params = vs.getprop(point, "params")
29
+ routed = list(params) if isinstance(params, list) else []
30
+ for kind in ("params", "header", "cookie", "query"):
31
+ defs = vs.getpath(point, "args." + kind)
32
+ if isinstance(defs, list):
33
+ routed += [vs.getprop(ad, "name") for ad in defs
34
+ if kind == "params" or vs.getprop(ad, "field") is not True]
35
+
36
+ body = {}
37
+ for name in fields:
38
+ val = vs.getprop(ctx.reqmatch or {}, name)
39
+ if val is not None and name != "$action" and name not in routed:
40
+ body[name] = val
41
+ return body
@@ -31,8 +31,9 @@ def prepare_query_util(ctx):
31
31
  if isinstance(name, str):
32
32
  params.append(name)
33
33
  # A header or cookie parameter travels in the headers, which
34
- # prepare_headers fills, unless a query parameter shares its name:
35
- # then both are sent.
34
+ # prepare_headers fills, and a field the point's body declares travels
35
+ # in the body, which prepare_body fills, unless a query parameter
36
+ # shares its name: then both are sent.
36
37
  ql = vs.getpath(point, "args.query")
37
38
  declared = [vs.getprop(qd, "name") for qd in ql] if isinstance(ql, list) else []
38
39
  for located in (vs.getpath(point, "args.header"), vs.getpath(point, "args.cookie")):
@@ -41,6 +42,10 @@ def prepare_query_util(ctx):
41
42
  name = vs.getprop(hd, "name")
42
43
  if isinstance(name, str) and name not in declared:
43
44
  params.append(name)
45
+ fields = vs.getprop(point, "fields")
46
+ if isinstance(fields, list):
47
+ params += [name for name in fields
48
+ if isinstance(name, str) and name not in declared]
44
49
 
45
50
  # A query parameter travels under the name the definition gives it, its
46
51
  # orig, which the model may have renamed for the caller.