@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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +9 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/secrets.aontu +3 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
- package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
- package/project/.sdk/tm/c/feature/cache.c +16 -1
- package/project/.sdk/tm/c/feature/secrets.c +149 -18
- package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
- package/project/.sdk/tm/c/tests/feature_test.c +31 -0
- package/project/.sdk/tm/c/utility/make_spec.c +1 -1
- package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
- package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
- package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
- package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
- package/project/.sdk/tm/cpp/core/types.hpp +1 -11
- package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
- package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
- package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
- package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
- package/project/.sdk/tm/csharp/core/Control.cs +0 -5
- package/project/.sdk/tm/csharp/core/Point.cs +6 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
- package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
- package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
- package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
- package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
- package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
- package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
- package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
- package/project/.sdk/tm/go/core/target.go +8 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
- package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
- package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/media.go +2 -2
- package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
- package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
- package/project/.sdk/tm/java/core/Control.java +0 -5
- package/project/.sdk/tm/java/core/Point.java +7 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
- package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
- package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
- package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
- package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
- package/project/.sdk/tm/java/utility/Media.java +2 -2
- package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
- package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
- package/project/.sdk/tm/js/src/Point.js +2 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
- package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
- package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
- package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
- package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
- package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
- package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
- package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
- package/project/.sdk/tm/lua/utility/clean.lua +1 -0
- package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
- package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
- package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
- package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
- package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
- package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
- package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
- package/project/.sdk/tm/perl/t/feature.t +24 -0
- package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
- package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
- package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
- package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
- package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
- package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
- package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
- package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
- package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
- package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
- package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
- package/project/.sdk/tm/py/test/test_feature.py +18 -0
- package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
- package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
- package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
- package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
- package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
- package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
- package/project/.sdk/tm/rust/feature/cache.rs +15 -1
- package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
- package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
- package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
- package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
- package/project/.sdk/tm/scala/core/Control.scala +0 -5
- package/project/.sdk/tm/scala/core/Point.scala +3 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
- package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
- package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
- package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
- package/project/.sdk/tm/ts/src/Point.ts +3 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/zig/core/utility.zig +47 -4
- package/project/.sdk/tm/zig/feature/cache.zig +15 -1
- package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
- package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
- package/project/sdkgen-package.json +1 -1
- package/src/utility.ts +12 -1
|
@@ -38,11 +38,42 @@ const { Sekreto, envkey } = require('./sekreto')
|
|
|
38
38
|
// bypasses feature hooks entirely, so it awaits client._secrets.resolve()
|
|
39
39
|
// itself — which is what defends the raw direct()/graphql() paths, since
|
|
40
40
|
// both reach the wire through prepare().
|
|
41
|
+
const REDIRECT_MAX = 5
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// The next URL of a redirect that keeps its method, when that URL is on the
|
|
45
|
+
// exchange's own origin. Any other redirect would drop the body or leave it.
|
|
46
|
+
function moved(url, at, res) {
|
|
47
|
+
const status = null == res ? 0 : res.status
|
|
48
|
+
if (307 !== status && 308 !== status) {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const headers = res.headers
|
|
53
|
+
const location = null == headers ? undefined :
|
|
54
|
+
'function' === typeof headers.get ? headers.get('location') : headers.location
|
|
55
|
+
|
|
56
|
+
if ('string' !== typeof location || '' === location) {
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const next = new URL(location, at)
|
|
62
|
+
return next.origin === new URL(url).origin ? next.href : undefined
|
|
63
|
+
}
|
|
64
|
+
catch (_err) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
41
70
|
class SecretsFeature extends BaseFeature {
|
|
42
71
|
version = '0.1.0'
|
|
43
72
|
name = 'secrets'
|
|
44
73
|
|
|
45
74
|
_client
|
|
75
|
+
_declared = false
|
|
76
|
+
_basic = false
|
|
46
77
|
_sekreto
|
|
47
78
|
_secretname = 'apikey'
|
|
48
79
|
_resolving
|
|
@@ -81,6 +112,13 @@ class SecretsFeature extends BaseFeature {
|
|
|
81
112
|
const plugins = require('../../Config').FEATURE_PLUGINS || {}
|
|
82
113
|
|
|
83
114
|
this._client = client
|
|
115
|
+
|
|
116
|
+
// What PrepareAuth was generated from: the config declares auth only
|
|
117
|
+
// where it places a credential, and Basic only where it composes one.
|
|
118
|
+
const declared = ctx.config?.options?.auth
|
|
119
|
+
this._declared = null != declared
|
|
120
|
+
this._basic = true === declared?.basic
|
|
121
|
+
|
|
84
122
|
this._secretname = 'string' === typeof fopts.name &&
|
|
85
123
|
'' !== fopts.name ? fopts.name : 'apikey'
|
|
86
124
|
|
|
@@ -94,6 +132,7 @@ class SecretsFeature extends BaseFeature {
|
|
|
94
132
|
response: 'string' === typeof xopts.response ? xopts.response : 'access_token',
|
|
95
133
|
statuses: Array.isArray(xopts.statuses) ? xopts.statuses : [401],
|
|
96
134
|
retries: 'number' === typeof xopts.retries ? xopts.retries : 1,
|
|
135
|
+
redirect: 'same-origin' === xopts.redirect ? 'same-origin' : 'refuse',
|
|
97
136
|
} : null
|
|
98
137
|
|
|
99
138
|
const providers = []
|
|
@@ -164,6 +203,12 @@ class SecretsFeature extends BaseFeature {
|
|
|
164
203
|
}
|
|
165
204
|
|
|
166
205
|
|
|
206
|
+
// PrepareAuth's decision: auth the config declares, not suppressed by `auth: null`.
|
|
207
|
+
_authon() {
|
|
208
|
+
return this._declared && null != this._client._options.auth
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
167
212
|
// Every value this feature resolves or buys is a secret the SDK handles,
|
|
168
213
|
// and none arrives under an option key the intake registration saw.
|
|
169
214
|
_register(value) {
|
|
@@ -223,7 +268,7 @@ class SecretsFeature extends BaseFeature {
|
|
|
223
268
|
// boolean is the whole of what resolve() needs to tell a cacheable HIT
|
|
224
269
|
// from a miss it must not retain.
|
|
225
270
|
async _resolveonce() {
|
|
226
|
-
if (null == this._sekreto) {
|
|
271
|
+
if (null == this._sekreto || !this._authon()) {
|
|
227
272
|
return false
|
|
228
273
|
}
|
|
229
274
|
|
|
@@ -254,17 +299,6 @@ class SecretsFeature extends BaseFeature {
|
|
|
254
299
|
return true
|
|
255
300
|
}
|
|
256
301
|
|
|
257
|
-
// `auth: null` is the documented way to send NO credential, and a
|
|
258
|
-
// purchase is a credential-bearing call: the refresh token goes to the
|
|
259
|
-
// token endpoint in the request body. _withRefresh honours suppression
|
|
260
|
-
// for the RETRY, but it runs after this — by then the refresh token has
|
|
261
|
-
// already left the process, and no later check can call it back. The
|
|
262
|
-
// suppression has to be honoured here, before the first purchase, or it
|
|
263
|
-
// only ever half-held.
|
|
264
|
-
if (null == this._client.options().auth) {
|
|
265
|
-
return false
|
|
266
|
-
}
|
|
267
|
-
|
|
268
302
|
this._client._options.apikey = await this._buy()
|
|
269
303
|
|
|
270
304
|
return true
|
|
@@ -337,13 +371,26 @@ class SecretsFeature extends BaseFeature {
|
|
|
337
371
|
// feature wraps, and sending the token request back through it would
|
|
338
372
|
// recurse on the first 401 — and would route the exchange through the
|
|
339
373
|
// test mock, which knows nothing about it.
|
|
340
|
-
const
|
|
374
|
+
const fetchdef = {
|
|
341
375
|
method: x.method,
|
|
342
376
|
headers: { 'content-type': 'application/json' },
|
|
343
377
|
body: JSON.stringify({ [x.request]: this._refresh }),
|
|
344
|
-
// Never followed: a redirect would carry the refresh token on.
|
|
378
|
+
// Never followed by the client: a redirect would carry the refresh token on.
|
|
345
379
|
redirect: 'manual',
|
|
346
|
-
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let res = await fetch(url, fetchdef)
|
|
383
|
+
|
|
384
|
+
// By option alone, and only while the exchange stays on its own origin.
|
|
385
|
+
let at = url
|
|
386
|
+
for (let hops = 0; 'same-origin' === x.redirect && hops < REDIRECT_MAX; hops++) {
|
|
387
|
+
const next = moved(url, at, res)
|
|
388
|
+
if (null == next) {
|
|
389
|
+
break
|
|
390
|
+
}
|
|
391
|
+
at = next
|
|
392
|
+
res = await fetch(at, fetchdef)
|
|
393
|
+
}
|
|
347
394
|
|
|
348
395
|
const status = null == res ? 0 : res.status
|
|
349
396
|
|
|
@@ -378,12 +425,9 @@ class SecretsFeature extends BaseFeature {
|
|
|
378
425
|
const x = this._exchange
|
|
379
426
|
const max = null == x ? 0 : x.retries
|
|
380
427
|
|
|
381
|
-
//
|
|
382
|
-
//
|
|
383
|
-
|
|
384
|
-
// cannot be fixed by buying one — retrying would transmit exactly the
|
|
385
|
-
// credential the caller suppressed.
|
|
386
|
-
if (null == this._client.options().auth) {
|
|
428
|
+
// A refusal of an unauthenticated request is not an expired token, and
|
|
429
|
+
// retrying would transmit the credential that auth off withholds.
|
|
430
|
+
if (!this._authon()) {
|
|
387
431
|
return inner(ctx, url, fetchdef)
|
|
388
432
|
}
|
|
389
433
|
|
|
@@ -448,23 +492,29 @@ class SecretsFeature extends BaseFeature {
|
|
|
448
492
|
return
|
|
449
493
|
}
|
|
450
494
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
// Suppressed auth means NO header, the same answer prepareAuth gives.
|
|
454
|
-
// Reached defensively - _withRefresh does not retry at all when auth
|
|
455
|
-
// is null - but this is the function that writes the credential, so
|
|
456
|
-
// it is where the rule has to hold.
|
|
457
|
-
if (null == auth) {
|
|
495
|
+
if (!this._authon()) {
|
|
458
496
|
delete fetchdef.headers.authorization
|
|
459
497
|
return
|
|
460
498
|
}
|
|
461
499
|
|
|
500
|
+
const auth = this._client._options.auth
|
|
501
|
+
|
|
462
502
|
// The header prepareAuth wrote: auth.name, lower-cased.
|
|
463
503
|
const name = 'string' === typeof auth.name && '' !== auth.name ?
|
|
464
504
|
auth.name.toLowerCase() : 'authorization'
|
|
465
505
|
|
|
506
|
+
const value = this._basic && true === auth.basic ? this._pair(token) : token
|
|
466
507
|
const prefix = auth.prefix
|
|
467
|
-
fetchdef.headers[name] = prefix ? prefix + ' ' +
|
|
508
|
+
fetchdef.headers[name] = prefix ? prefix + ' ' + value : value
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
// Under Basic the token is the key half, as apikey is: prepareAuth's pair.
|
|
513
|
+
_pair(token) {
|
|
514
|
+
const secret = this._client._options.secret
|
|
515
|
+
const pair = Buffer.from(token + ':' + (null == secret ? '' : secret)).toString('base64')
|
|
516
|
+
this._register(pair)
|
|
517
|
+
return pair
|
|
468
518
|
}
|
|
469
519
|
}
|
|
470
520
|
|
|
@@ -48,7 +48,7 @@ function makeSpec(ctx) {
|
|
|
48
48
|
if ('graphql' === point.kind) {
|
|
49
49
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
50
50
|
// the body carries the operation. prepareBody is skipped deliberately —
|
|
51
|
-
// it only
|
|
51
|
+
// it builds only a REST body, whereas every
|
|
52
52
|
// GraphQL op posts one, including load/list/remove.
|
|
53
53
|
ctx.spec.body = utility.graphqlBody(ctx)
|
|
54
54
|
ctx.spec.path = ''
|
|
@@ -23,6 +23,35 @@ function prepareBody(ctx) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
else if (ctx.point && Array.isArray(ctx.point.fields) && 0 < ctx.point.fields.length) {
|
|
27
|
+
body = matchBody(ctx)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return body
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
35
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
36
|
+
// cookie or query argument the body does not also declare as a field.
|
|
37
|
+
function matchBody(ctx) {
|
|
38
|
+
const point = ctx.point
|
|
39
|
+
const args = point.args || {}
|
|
40
|
+
const getprop = ctx.utility.struct.getprop
|
|
41
|
+
|
|
42
|
+
const routed = (point.params || [])
|
|
43
|
+
.concat((args.params || []).map((arg) => arg && arg.name))
|
|
44
|
+
.concat(['header', 'cookie', 'query'].flatMap((kind) => (args[kind] || [])
|
|
45
|
+
.filter((arg) => !arg || true !== arg.field).map((arg) => arg && arg.name)))
|
|
46
|
+
|
|
47
|
+
const body = {}
|
|
48
|
+
for (const name of point.fields) {
|
|
49
|
+
const val = getprop(ctx.reqmatch, name)
|
|
50
|
+
if (null != val && '$action' !== name && !routed.includes(name)) {
|
|
51
|
+
body[name] = val
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
return body
|
|
27
56
|
}
|
|
28
57
|
|
|
@@ -31,11 +31,13 @@ function prepareQuery(ctx) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// A header or cookie
|
|
35
|
-
//
|
|
34
|
+
// A header or cookie argument travels in the headers, and a field the point's
|
|
35
|
+
// body declares in the body, unless a query parameter shares its name.
|
|
36
36
|
const elsewhere = ((point.args && point.args.header) || [])
|
|
37
37
|
.concat((point.args && point.args.cookie) || [])
|
|
38
|
-
.map((a) => a && a.name)
|
|
38
|
+
.map((a) => a && a.name)
|
|
39
|
+
.concat(Array.isArray(point.fields) ? point.fields : [])
|
|
40
|
+
.filter((name) => !declared.includes(name))
|
|
39
41
|
|
|
40
42
|
const out = {}
|
|
41
43
|
for (let [key, val] of items(reqmatch)) {
|