@voxgig/sdkgen 4.50.0 → 4.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  30. package/project/.sdk/tm/c/tests/feature_test.c +104 -0
  31. package/project/.sdk/tm/c/utility/clean.c +26 -33
  32. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  34. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  35. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  36. package/project/.sdk/tm/clojure/src/sdk/features.clj +81 -10
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +33 -0
  38. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  39. package/project/.sdk/tm/cpp/Makefile +5 -0
  40. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  41. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  42. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  43. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  44. package/project/.sdk/tm/cpp/test/feature_test.cpp +99 -0
  45. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  46. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  47. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  48. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  49. package/project/.sdk/tm/csharp/test/FeatureTest.cs +76 -0
  50. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  51. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  52. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  53. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  57. package/project/.sdk/tm/elixir/test/feature_test.exs +61 -0
  58. package/project/.sdk/tm/go/core/context.go +6 -0
  59. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  60. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  61. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  62. package/project/.sdk/tm/go/test/feature_test.go +61 -0
  63. package/project/.sdk/tm/go/utility/clean.go +5 -7
  64. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  65. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  66. package/project/.sdk/tm/java/core/Context.java +9 -0
  67. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  68. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  69. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  70. package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
  71. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  72. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  73. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  74. package/project/.sdk/tm/js/src/Context.js +4 -0
  75. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  76. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  77. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  78. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  79. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  80. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  81. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  82. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  84. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  85. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  86. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  87. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  88. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  89. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  90. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +59 -0
  91. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  92. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  93. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  94. package/project/.sdk/tm/lua/core/context.lua +6 -0
  95. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  96. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  97. package/project/.sdk/tm/lua/test/feature_test.lua +81 -0
  98. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  99. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  100. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  101. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  102. package/project/.sdk/tm/ocaml/sdk_features.ml +106 -8
  103. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  104. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  105. package/project/.sdk/tm/ocaml/test/t_feature.ml +35 -1
  106. package/project/.sdk/tm/perl/core/context.pm +3 -0
  107. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  108. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  109. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  110. package/project/.sdk/tm/perl/t/feature.t +66 -0
  111. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  112. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  113. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  114. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  115. package/project/.sdk/tm/php/core/Context.php +4 -0
  116. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  117. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  118. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  119. package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
  120. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  121. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  122. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  123. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  126. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  127. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  128. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  129. package/project/.sdk/tm/py/test/test_feature.py +50 -0
  130. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  131. package/project/.sdk/tm/rb/core/context.rb +4 -1
  132. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  133. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  134. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  135. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  136. package/project/.sdk/tm/rb/test/feature_test.rb +74 -0
  137. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  138. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  139. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  140. package/project/.sdk/tm/rust/core/context.rs +8 -0
  141. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  142. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  143. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  144. package/project/.sdk/tm/rust/tests/feature_test.rs +100 -0
  145. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  146. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  147. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  148. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  149. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  150. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  151. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +28 -0
  152. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  153. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  154. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  159. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  160. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  161. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +55 -0
  162. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  163. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  164. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  165. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  166. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  167. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  168. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  169. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  170. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  171. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  172. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  173. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  174. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  175. package/project/.sdk/tm/zig/core/context.zig +5 -0
  176. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  177. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  178. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  179. package/project/.sdk/tm/zig/test/feature_test.zig +65 -0
  180. package/project/sdkgen-package.json +1 -1
@@ -39,6 +39,9 @@ class Context {
39
39
  entopts
40
40
  options
41
41
 
42
+ // The clean registry, which holds every registered credential in plain form.
43
+ cleancfg
44
+
42
45
  opmap
43
46
 
44
47
  response
@@ -72,6 +75,7 @@ class Context {
72
75
  this.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
73
76
  this.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
74
77
  this.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
78
+ this.cleancfg = getprop(ctxmap, 'cleancfg', getprop(basectx, 'cleancfg'))
75
79
 
76
80
  this.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
77
81
  this.shared = getprop(ctxmap, 'shared', getprop(basectx, 'shared'))
@@ -5,13 +5,9 @@ const { headerValue, isJsonMedia } = require('../../utility/MediaUtility')
5
5
 
6
6
 
7
7
  // Response caching for safe (read) requests. Wraps the active transport and
8
- // serves a fresh cached snapshot instead of hitting the network when the
9
- // same method+URL was fetched within `ttl` ms. Only successful responses to
10
- // cacheable methods (default: GET) are stored, keyed by method+URL. The
11
- // cache is bounded (`max` entries, oldest evicted) and every hit/miss is
12
- // recorded on `client._cache` for inspection. One-shot response bodies are
13
- // normalised on capture so both the current caller and later hits can read
14
- // the JSON body repeatedly.
8
+ // serves a cached snapshot for a repeat of the same method, URL and headers.
9
+ // The store is per client and bounded; see the features reference for the
10
+ // key, the write invalidation and the Cache-Control rules.
15
11
  class CacheFeature extends BaseFeature {
16
12
  version = '0.0.1'
17
13
  name = 'cache'
@@ -20,6 +16,7 @@ class CacheFeature extends BaseFeature {
20
16
  _client
21
17
  _options = {}
22
18
  _store = new Map()
19
+ _key = undefined
23
20
 
24
21
 
25
22
  init(ctx, options) {
@@ -32,6 +29,7 @@ class CacheFeature extends BaseFeature {
32
29
  }
33
30
 
34
31
  this._store = new Map()
32
+ this._key = cacheKey()
35
33
 
36
34
  const self = this
37
35
  const utility = ctx.utility
@@ -48,10 +46,18 @@ class CacheFeature extends BaseFeature {
48
46
  const methods = this._options.methods || ['GET']
49
47
 
50
48
  if (methods.indexOf(method) < 0) {
51
- return inner(ctx, url, fetchdef)
49
+ if (SAFE_METHODS.indexOf(method) >= 0) {
50
+ return inner(ctx, url, fetchdef)
51
+ }
52
+ try {
53
+ return await inner(ctx, url, fetchdef)
54
+ }
55
+ finally {
56
+ this._invalidate(url)
57
+ }
52
58
  }
53
59
 
54
- const key = method + ' ' + url
60
+ const key = method + ' ' + url + ' ' + await this._digest(fetchdef && fetchdef.headers)
55
61
  const now = this._now()
56
62
  const hit = this._store.get(key)
57
63
 
@@ -78,9 +84,16 @@ class CacheFeature extends BaseFeature {
78
84
  return this._replay(snapshot)
79
85
  }
80
86
 
81
- const ttl = null == this._options.ttl ? 5000 : this._options.ttl
87
+ const ttl = cacheLifetime(snapshot.headers,
88
+ null == this._options.ttl ? 5000 : this._options.ttl)
89
+ if (ttl <= 0) {
90
+ this._track('bypass')
91
+ return this._replay(snapshot)
92
+ }
93
+
94
+ this._store.delete(key)
82
95
  this._evict()
83
- this._store.set(key, { expiry: now + ttl, snapshot })
96
+ this._store.set(key, { expiry: now + ttl, scope: urlScope(url), snapshot })
84
97
  this._track('miss')
85
98
  return this._replay(snapshot)
86
99
  }
@@ -90,6 +103,25 @@ class CacheFeature extends BaseFeature {
90
103
  }
91
104
 
92
105
 
106
+ async _digest(headers) {
107
+ const subtle = globalThis.crypto.subtle
108
+ const mac = await subtle.sign('HMAC', await this._key,
109
+ new TextEncoder().encode(headerText(headers)))
110
+ return Array.from(new Uint8Array(mac), (b) => b.toString(16).padStart(2, '0')).join('')
111
+ }
112
+
113
+
114
+ _invalidate(url) {
115
+ const path = urlScope(url)
116
+ const collection = urlParent(path)
117
+ for (const [key, entry] of this._store) {
118
+ if (scopeUnder(entry.scope, path) || entry.scope === collection) {
119
+ this._store.delete(key)
120
+ }
121
+ }
122
+ }
123
+
124
+
93
125
  _cacheable(res) {
94
126
  if (null == res || res instanceof Error) {
95
127
  return false
@@ -188,6 +220,81 @@ class CacheFeature extends BaseFeature {
188
220
  }
189
221
 
190
222
 
223
+ const SAFE_METHODS = ['GET', 'HEAD']
224
+
225
+ const UNSTORED = ['no-store', 'private', 'no-cache']
226
+
227
+
228
+ // A fresh random secret per client: the key holds a digest of the headers,
229
+ // never a header value.
230
+ function cacheKey() {
231
+ const crypto = globalThis.crypto
232
+ return crypto.subtle.importKey('raw', crypto.getRandomValues(new Uint8Array(32)),
233
+ { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
234
+ }
235
+
236
+
237
+ function headerText(headers) {
238
+ const pairs = []
239
+ for (const name of Object.keys(headers || {})) {
240
+ if (null != headers[name]) {
241
+ pairs.push([name.toLowerCase(), String(headers[name])])
242
+ }
243
+ }
244
+ pairs.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0)
245
+ return pairs.map((p) => p[0] + ':' + p[1] + '\n').join('')
246
+ }
247
+
248
+
249
+ // The configured ttl, capped by the response's Cache-Control; zero when the
250
+ // response may not be stored.
251
+ function cacheLifetime(headers, ttl) {
252
+ let control = ''
253
+ for (const name of Object.keys(headers || {})) {
254
+ if ('cache-control' === name.toLowerCase()) {
255
+ control = String(headers[name])
256
+ }
257
+ }
258
+ let life = ttl
259
+ for (const part of control.toLowerCase().split(',')) {
260
+ const directive = part.trim()
261
+ if (UNSTORED.indexOf(directive) >= 0) {
262
+ return 0
263
+ }
264
+ const age = directive.match(/^max-age\s*=\s*"?(\d+)"?$/)
265
+ if (null != age) {
266
+ life = Math.min(life, Number(age[1]) * 1000)
267
+ }
268
+ }
269
+ return life
270
+ }
271
+
272
+
273
+ function urlScope(url) {
274
+ let scope = String(url).split(/[?#]/)[0]
275
+ while (scope.endsWith('/')) {
276
+ scope = scope.slice(0, -1)
277
+ }
278
+ return scope
279
+ }
280
+
281
+
282
+ function urlParent(scope) {
283
+ const scheme = scope.indexOf('://')
284
+ const root = scheme < 0 ? 0 : scope.indexOf('/', scheme + 3)
285
+ if (root < 0) {
286
+ return scope
287
+ }
288
+ const cut = scope.lastIndexOf('/')
289
+ return scope.slice(0, cut < root ? root : cut)
290
+ }
291
+
292
+
293
+ function scopeUnder(scope, prefix) {
294
+ return scope === prefix || scope.startsWith(prefix + '/')
295
+ }
296
+
297
+
191
298
  module.exports = {
192
299
  CacheFeature
193
300
  }
@@ -51,8 +51,9 @@ class CostFeature extends BaseFeature {
51
51
  client._cost = {
52
52
  currency: this._options.currency || 'USD',
53
53
  total: { calls: 0, attempts: 0, amount: 0, reported: 0, estimated: 0 },
54
- ops: {},
55
- actors: {},
54
+ // Keyed by a caller's string, so no prototype to collide with.
55
+ ops: Object.create(null),
56
+ actors: Object.create(null),
56
57
  budget: { limit, spent: 0, remaining: limit, exceeded: false },
57
58
  last: undefined,
58
59
  }
@@ -29,7 +29,7 @@ class MetricsFeature extends BaseFeature {
29
29
  if (null == client._metrics) {
30
30
  client._metrics = {
31
31
  total: { count: 0, ok: 0, err: 0, totalMs: 0, maxMs: 0 },
32
- ops: {},
32
+ ops: Object.create(null),
33
33
  }
34
34
  }
35
35
  }
@@ -189,17 +189,17 @@ class PagingFeature extends BaseFeature {
189
189
 
190
190
  // Only bind variables the operation actually declares, or the server
191
191
  // rejects the document.
192
- const declared = {}
192
+ const declared = new Set()
193
193
  for (const v of ((point.graphql && point.graphql.vars) || [])) {
194
- declared[v.name] = true
194
+ declared.add(v.name)
195
195
  }
196
196
 
197
- if (null != paging.cursor && declared[afterVar]) {
197
+ if (null != paging.cursor && declared.has(afterVar)) {
198
198
  vars[afterVar] = paging.cursor
199
199
  }
200
200
 
201
201
  if (null != this._options.limit && null == vars[firstVar] &&
202
- declared[firstVar]) {
202
+ declared.has(firstVar)) {
203
203
  vars[firstVar] = this._options.limit
204
204
  }
205
205
  }
@@ -18,7 +18,7 @@ class RbacFeature extends BaseFeature {
18
18
 
19
19
  _client
20
20
  _options = {}
21
- _granted = {}
21
+ _granted = new Set()
22
22
 
23
23
 
24
24
  init(ctx, options) {
@@ -26,10 +26,10 @@ class RbacFeature extends BaseFeature {
26
26
  this._options = options || {}
27
27
  this.active = options.active
28
28
 
29
- this._granted = {}
29
+ this._granted = new Set()
30
30
  const perms = this._options.permissions || []
31
31
  for (const p of perms) {
32
- this._granted[p] = true
32
+ this._granted.add(p)
33
33
  }
34
34
  }
35
35
 
@@ -48,7 +48,7 @@ class RbacFeature extends BaseFeature {
48
48
  return
49
49
  }
50
50
 
51
- if (this._granted['*'] || this._granted[required]) {
51
+ if (this._granted.has('*') || this._granted.has(required)) {
52
52
  this._track(ctx, required, true)
53
53
  return
54
54
  }
@@ -1,5 +1,6 @@
1
1
 
2
2
  const { BaseFeature } = require('../base/BaseFeature')
3
+ const { fetcher } = require('../../utility/FetcherUtility')
3
4
  const { Sekreto, envkey } = require('./sekreto')
4
5
 
5
6
 
@@ -367,19 +368,28 @@ class SecretsFeature extends BaseFeature {
367
368
  throw new Error('secrets: no fetch implementation for the token exchange')
368
369
  }
369
370
 
370
- // Deliberately NOT the SDK transport. The transport is what this
371
- // feature wraps, and sending the token request back through it would
372
- // recurse on the first 401 — and would route the exchange through the
373
- // test mock, which knows nothing about it.
374
371
  const fetchdef = {
375
372
  method: x.method,
376
373
  headers: { 'content-type': 'application/json' },
377
374
  body: JSON.stringify({ [x.request]: this._refresh }),
378
375
  // Never followed by the client: a redirect would carry the refresh token on.
379
376
  redirect: 'manual',
377
+ // Its own bound: the timeout feature's wrapper is above it.
378
+ signal: AbortSignal.timeout(30000),
380
379
  }
381
380
 
382
- let res = await fetch(url, fetchdef)
381
+ // The SDK's own transport, beneath every feature's wrapper: the wrapped
382
+ // one would recurse on the first 401 and reach the test mock. It applies
383
+ // the GET-only guard, and its refusal is the operation's error.
384
+ const send = async (at) => {
385
+ const sent = await fetcher(this._client._rootctx, at, fetchdef)
386
+ if (sent instanceof Error) {
387
+ throw sent
388
+ }
389
+ return sent
390
+ }
391
+
392
+ let res = await send(url)
383
393
 
384
394
  // By option alone, and only while the exchange stays on its own origin.
385
395
  let at = url
@@ -389,7 +399,7 @@ class SecretsFeature extends BaseFeature {
389
399
  break
390
400
  }
391
401
  at = next
392
- res = await fetch(at, fetchdef)
402
+ res = await send(at)
393
403
  }
394
404
 
395
405
  const status = null == res ? 0 : res.status
@@ -202,7 +202,8 @@ class ValidateFeature extends BaseFeature {
202
202
 
203
203
 
204
204
  _entitySpec(ctx) {
205
- return this._spec[entname(ctx)]
205
+ const name = entname(ctx)
206
+ return Object.prototype.hasOwnProperty.call(this._spec, name) ? this._spec[name] : undefined
206
207
  }
207
208
 
208
209
 
@@ -54,7 +54,7 @@ function count(val, dflt) {
54
54
  // is reached with a bare one) falls back to the schema defaults, so nothing
55
55
  // leaves raw for want of a constructor.
56
56
  function cleanConfig(ctx) {
57
- const derived = ctx?.options?.__derived__?.clean
57
+ const derived = ctx?.cleancfg
58
58
  if (null != derived) {
59
59
  return derived
60
60
  }
@@ -43,7 +43,7 @@ function makeOptions(ctx) {
43
43
  const layer = (b) => null != b && 'object' === typeof b && !Array.isArray(b) ? b : {}
44
44
  const cleancfg = makeCleanConfig(merge([{}, OPTSPEC.clean,
45
45
  struct.clone(layer(cfgopts.clean)), layer(opts.clean)]))
46
- const cleanctx = { options: { __derived__: { clean: cleancfg } } }
46
+ const cleanctx = { cleancfg }
47
47
  cleanAddSensitive(cleanctx, settings(opts))
48
48
  for (const raw of [...splitvalues(cfgopts.clean?.values), ...splitvalues(opts.clean?.values)]) {
49
49
  cleanAdd(cleanctx, raw)
@@ -164,13 +164,13 @@ function makeOptions(ctx) {
164
164
  featureorder = names
165
165
  }
166
166
 
167
- opts.__derived__ = {
168
- clean: cleancfg,
169
- featureorder,
170
- }
167
+ opts.__derived__ = { featureorder }
168
+
169
+ // Beside the options, not in them: options() hands them to callers.
170
+ ctx.cleancfg = cleancfg
171
171
 
172
172
  // Again over the merged result: the config's own defaults can carry one.
173
- cleanAddSensitive({ options: opts }, settings(opts))
173
+ cleanAddSensitive(cleanctx, settings(opts))
174
174
 
175
175
  return opts
176
176
  }
@@ -156,6 +156,66 @@ async function usableOps(want) {
156
156
  }
157
157
 
158
158
 
159
+
160
+ const READ_OPS = ['list', 'load']
161
+ const WRITE_OPS = ['create', 'update', 'patch', 'remove']
162
+
163
+
164
+ // A read and a write of one entity (#READ, #WRITE), each driven as usableOps
165
+ // drives an op; #ITEM is a write of the same entity driven with ITEM_ARGS.
166
+ async function usablePair() {
167
+ const found = {}
168
+ for (const cand of candidates(makeClient({}))) {
169
+ const role = READ_OPS.includes(cand.op) ? 'read' : WRITE_OPS.includes(cand.op) ? 'write' : ''
170
+ const seen = found[cand.entity] = found[cand.entity] || {}
171
+ if ('' === role || null != seen[role]) { continue }
172
+ try {
173
+ await makeClient({})[cand.accessor]()[cand.op]({}, {})
174
+ }
175
+ catch (e) { continue }
176
+ seen[role] = cand
177
+ if (null != seen.read && null != seen.write) {
178
+ return { read: seen.read, write: seen.write, item: await usableItem(cand.entity) }
179
+ }
180
+ }
181
+ return undefined
182
+ }
183
+
184
+
185
+ const ITEM_ARGS = { id: 'corpus-item' }
186
+
187
+ async function usableItem(entity) {
188
+ for (const cand of candidates(makeClient({}))) {
189
+ if (entity !== cand.entity || !['update', 'patch', 'remove'].includes(cand.op)) { continue }
190
+ try {
191
+ await makeClient({})[cand.accessor]()[cand.op]({ ...ITEM_ARGS }, {})
192
+ return cand
193
+ }
194
+ catch (e) { continue }
195
+ }
196
+ return undefined
197
+ }
198
+
199
+
200
+ // A step may wait before its call, may add request headers for its call, and
201
+ // may pass `args` as the operation's first argument.
202
+ async function runStep(client, ref, step) {
203
+ if (null != step.wait) {
204
+ await new Promise((resolve) => setTimeout(resolve, step.wait))
205
+ }
206
+ const options = client._rootctx.options
207
+ const prior = options.headers
208
+ if (null != step.headers) {
209
+ options.headers = { ...(prior || {}), ...step.headers }
210
+ }
211
+ try {
212
+ await client[ref.accessor]()[ref.op]({ ...(step.args || {}) }, step.ctrl || {})
213
+ }
214
+ finally {
215
+ options.headers = prior
216
+ }
217
+ }
218
+
159
219
  // Replace #OP1/#OP2 throughout a case, keys included.
160
220
  function resolve(node, tokens) {
161
221
  if ('string' === typeof node) {
@@ -169,7 +229,9 @@ function resolve(node, tokens) {
169
229
  if (null != node && 'object' === typeof node) {
170
230
  const out = {}
171
231
  for (const k of Object.keys(node)) {
172
- out[resolve(k, tokens)] = resolve(node[k], tokens)
232
+ Object.defineProperty(out, resolve(k, tokens), {
233
+ value: resolve(node[k], tokens), enumerable: true, writable: true, configurable: true,
234
+ })
173
235
  }
174
236
  return out
175
237
  }
@@ -177,6 +239,15 @@ function resolve(node, tokens) {
177
239
  }
178
240
 
179
241
 
242
+ // No case may write onto the shared prototypes, as a `__proto__` key can.
243
+ function shared() {
244
+ return [Object.prototype, Object]
245
+ .map((o) => Object.getOwnPropertyNames(o).sort().join(',')).join(' | ')
246
+ }
247
+
248
+ const PRISTINE = shared()
249
+
250
+
180
251
  // Which #OPn tokens a case uses. A case wanting more operations than this SDK
181
252
  // has is skipped rather than failed.
182
253
  function tokensUsed(kase) {
@@ -214,6 +285,7 @@ describe('FeatureCorpus', () => {
214
285
  let corpus
215
286
  let ops = []
216
287
  let byKey = {}
288
+ let pair
217
289
 
218
290
 
219
291
  before(async () => {
@@ -221,6 +293,10 @@ describe('FeatureCorpus', () => {
221
293
  ops = await usableOps(2)
222
294
  byKey = {}
223
295
  for (const o of ops) { byKey[o.key] = o }
296
+ pair = await usablePair()
297
+ for (const o of pair ? [pair.read, pair.write, pair.item] : []) {
298
+ if (null != o) { byKey[o.key] = o }
299
+ }
224
300
  })
225
301
 
226
302
 
@@ -285,6 +361,20 @@ describe('FeatureCorpus', () => {
285
361
  continue
286
362
  }
287
363
 
364
+ const paired = /#(READ|WRITE|ITEM|OTHER)\b/.test(JSON.stringify(raw))
365
+ if (paired && null == pair) {
366
+ t.diagnostic(`skip "${raw.name}": needs a read and a write of one entity, this SDK offers none`)
367
+ continue
368
+ }
369
+ const other = null == pair ? undefined :
370
+ ops.find((o) => o.entity !== pair.read.entity)
371
+ const lacking = [['#ITEM', pair?.item], ['#OTHER', other]]
372
+ .find(([tok, op]) => null == op && new RegExp(tok + '\\b').test(JSON.stringify(raw)))
373
+ if (null != lacking) {
374
+ t.diagnostic(`skip "${raw.name}": needs ${lacking[0]}, which this SDK cannot drive`)
375
+ continue
376
+ }
377
+
288
378
  const missing = missingFeature(probe, raw)
289
379
  if (null != missing) {
290
380
  t.diagnostic(`skip "${raw.name}": needs the ${missing} feature, ` +
@@ -294,6 +384,12 @@ describe('FeatureCorpus', () => {
294
384
 
295
385
  const tokens = {}
296
386
  for (let i = 0; i < need; i++) { tokens['#OP' + (i + 1)] = ops[i].key }
387
+ if (paired && null != pair) {
388
+ tokens['#READ'] = pair.read.key
389
+ tokens['#WRITE'] = pair.write.key
390
+ if (null != pair.item) { tokens['#ITEM'] = pair.item.key }
391
+ if (null != other) { tokens['#OTHER'] = other.key }
392
+ }
297
393
 
298
394
  const kase = resolve(raw, tokens)
299
395
  ran++
@@ -307,7 +403,7 @@ describe('FeatureCorpus', () => {
307
403
  ok(null != ref, `${kase.name}: no operation ${step.op}`)
308
404
  let err = undefined
309
405
  try {
310
- await client[ref.accessor]()[ref.op]({}, step.ctrl || {})
406
+ await runStep(client, ref, step)
311
407
  }
312
408
  catch (e) {
313
409
  err = e
@@ -324,6 +420,8 @@ describe('FeatureCorpus', () => {
324
420
  }
325
421
 
326
422
  subset(client[`_${name}`], kase.out, `${kase.name}: _${name}`)
423
+ deepStrictEqual(shared(), PRISTINE,
424
+ `${kase.name}: the case wrote onto Object or Object.prototype`)
327
425
  }
328
426
  catch (err) {
329
427
  const msg = String(err?.message ?? err)
@@ -92,9 +92,8 @@ function makeClient(spec) {
92
92
 
93
93
  // One clean registry per client, as makeOptions gives a real one, so a value
94
94
  // a feature registers with cleanAdd is masked by every clean after it.
95
- const derived = stdutil.makeOptions({
96
- utility, options: { feature: { test: { active: true } } }, config: {},
97
- }).__derived__
95
+ const regctx = { utility, options: { feature: { test: { active: true } } }, config: {} }
96
+ const derived = stdutil.makeOptions(regctx).__derived__
98
97
 
99
98
  const client = {
100
99
  _mode: spec.mode || 'test',
@@ -120,6 +119,7 @@ function makeClient(spec) {
120
119
  client,
121
120
  utility,
122
121
  options: client._options,
122
+ cleancfg: regctx.cleancfg,
123
123
  out: {},
124
124
  ctrl: over.ctrl || {},
125
125
  meta: {},
@@ -559,7 +559,7 @@ describe('pipeline:result helpers', () => {
559
559
  const secret = 'PIPELINE-SECRET-a1b2c3d4e5f6'
560
560
  const text = 'x'.repeat(150) + secret + 'y'.repeat(100)
561
561
  const ctx = base({
562
- options: { __derived__: { clean: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 } } },
562
+ cleancfg: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 },
563
563
  spec: { headers: { 'user-agent': 'Probe ' + secret } },
564
564
  response: { body: 'body', json: async () => { throw Object.assign(new SyntaxError('bad json'), { text }) } },
565
565
  result: { status: 200, headers: { 'content-type': 'text/html' } },
@@ -20,6 +20,8 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
20
20
  var config: MutableMap<String, Any?>? = null
21
21
  var entopts: MutableMap<String, Any?>? = null
22
22
  var options: MutableMap<String, Any?>? = null
23
+ // The clean registry, beside the options rather than in them.
24
+ var cleancfg: Any? = null
23
25
  var opmap: MutableMap<String, Operation>? = null
24
26
  var response: Response? = null
25
27
  var result: Result? = null
@@ -116,6 +118,7 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
116
118
  if (this.options == null && basectx != null) {
117
119
  this.options = basectx.options
118
120
  }
121
+ this.cleancfg = Helpers.getCtxProp(ctxmap, "cleancfg") ?: basectx?.cleancfg
119
122
 
120
123
  // Entity
121
124
  val e = Helpers.getCtxProp(ctxmap, "entity")