@voxgig/sdkgen 4.35.0 → 4.35.1

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 (41) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/tm/c/feature/secrets.c +21 -6
  4. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +24 -9
  5. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +16 -10
  6. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +16 -7
  7. package/project/.sdk/tm/cpp/feature/secrets.hpp +9 -4
  8. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +20 -7
  9. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +10 -6
  10. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +21 -9
  11. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +7 -3
  12. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +15 -5
  13. package/project/.sdk/tm/go/feature/secrets_feature.go +9 -2
  14. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +21 -10
  15. package/project/.sdk/tm/java/feature/SecretsFeature.java +10 -5
  16. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +21 -9
  17. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +8 -4
  18. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +35 -24
  19. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +11 -6
  20. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +17 -8
  21. package/project/.sdk/tm/lua/feature/secrets_feature.lua +11 -4
  22. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +22 -9
  23. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +8 -4
  24. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +19 -10
  25. package/project/.sdk/tm/php/feature/SecretsFeature.php +10 -5
  26. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +33 -11
  27. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +8 -3
  28. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +27 -13
  29. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -5
  30. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +20 -11
  31. package/project/.sdk/tm/rust/feature/secrets.rs +8 -7
  32. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +17 -2
  33. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +10 -5
  34. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +19 -7
  35. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -5
  36. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +15 -7
  37. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +5 -1
  38. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +31 -20
  39. package/project/.sdk/tm/zig/feature/secrets.zig +12 -6
  40. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +21 -5
  41. package/project/sdkgen-package.json +1 -1
@@ -344,11 +344,11 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
344
344
  // Buy a token and try the request again when the API says the current one
345
345
  // is spent.
346
346
  //
347
- // The retry rewrites the authorization header IN PLACE on the fetchdef,
347
+ // The retry rewrites the credential header IN PLACE on the fetchdef,
348
348
  // because the header was built by the synchronous prepareAuth before this
349
349
  // request left and it carries the token that just failed. Rebuilt the way
350
- // prepareAuth builds it, from the same options auth.prefix, so the two
351
- // cannot drift.
350
+ // prepareAuth builds it, from the same options auth name and prefix, so
351
+ // the two cannot drift.
352
352
  private def withrefresh(
353
353
  ctx: Context,
354
354
  url: String,
@@ -426,12 +426,17 @@ class SecretsFeature extends BaseFeature("secrets", "0.1.0", true) {
426
426
  val rawauth = if (this.liveopts == null) null else this.liveopts.get("auth")
427
427
  rawauth match {
428
428
  case authmap: JMap[_, _] =>
429
+ // The header prepareAuth wrote: auth.name, lower-cased.
430
+ val name = authmap.asInstanceOf[JMap[String, Object]].get("name") match {
431
+ case s: String if s.nonEmpty => s.toLowerCase(java.util.Locale.ROOT)
432
+ case _ => "authorization"
433
+ }
429
434
  val prefix = authmap.asInstanceOf[JMap[String, Object]].get("prefix") match {
430
435
  case s: String => s
431
436
  case _ => ""
432
437
  }
433
- if ("" == prefix) headers.put("authorization", token)
434
- else headers.put("authorization", prefix + " " + token)
438
+ if ("" == prefix) headers.put(name, token)
439
+ else headers.put(name, prefix + " " + token)
435
440
  case _ => headers.remove("authorization")
436
441
  }
437
442
  }
@@ -44,6 +44,18 @@ object SecretsTestMain {
44
44
  private var npass = 0
45
45
  private val failures = new ArrayList[String]()
46
46
 
47
+ // The header the credential travels in: the DEFAULT client's auth.name,
48
+ // lower-cased as prepareAuth sends it. Read from a default client because
49
+ // a test's `auth: null` leaves no name to read.
50
+ private lazy val CREDHEADER: String =
51
+ ProjectNameSDK.testSDK(null, null).optionsMap().get("auth") match {
52
+ case auth: JMap[_, _] => auth.asInstanceOf[JMap[String, Object]].get("name") match {
53
+ case s: String if s.nonEmpty => s.toLowerCase(java.util.Locale.ROOT)
54
+ case _ => "authorization"
55
+ }
56
+ case _ => "authorization"
57
+ }
58
+
47
59
  private def pass(): Unit = { npass += 1 }
48
60
  private def fail(name: String, msg: String): Unit = failures.add(name + ": " + msg)
49
61
  private def check(name: String, cond: Boolean, msg: String): Unit =
@@ -56,7 +68,7 @@ object SecretsTestMain {
56
68
  private def eqi(name: String, exp: Int, act: Int): Unit =
57
69
  check(name, exp == act, "expected " + exp + ", got " + act)
58
70
 
59
- // The Authorization header carries the SPEC's credential prefix, which a
71
+ // The credential header carries the SPEC's credential prefix, which a
60
72
  // TEMPLATE cannot know: an OpenAPI `http`/`bearer` scheme gives `Bearer
61
73
  // <token>`, an apiKey scheme the raw token. So assert on the CREDENTIAL and
62
74
  // let the prefix be whatever this SDK's API declares - pinning the whole
@@ -70,7 +82,7 @@ object SecretsTestMain {
70
82
  new String(java.util.Base64.getDecoder.decode(got.substring(6)), "UTF-8").startsWith(token + ":")
71
83
  } catch { case _: IllegalArgumentException => false })
72
84
  check(name, got == token || got.endsWith(" " + token) || basic,
73
- "expected the authorization header to carry " + token + ", got \"" + got + "\"")
85
+ "expected the " + CREDHEADER + " header to carry " + token + ", got \"" + got + "\"")
74
86
  }
75
87
 
76
88
  // ---- the recording transport --------------------------------------------
@@ -98,8 +110,8 @@ object SecretsTestMain {
98
110
  }
99
111
  val call = new LinkedHashMap[String, Object]()
100
112
  call.put("url", url)
101
- call.put("has", java.lang.Boolean.valueOf(headers.containsKey("authorization")))
102
- call.put("auth", headers.get("authorization") match {
113
+ call.put("has", java.lang.Boolean.valueOf(headers.containsKey(CREDHEADER)))
114
+ call.put("auth", headers.get(CREDHEADER) match {
103
115
  case s: String => s
104
116
  case _ => ""
105
117
  })
@@ -327,7 +339,7 @@ object SecretsTestMain {
327
339
  val client = ProjectNameSDK.testSDK(null, jmap("apikey" -> "OPTKEY01"))
328
340
  val fetchdef = client.prepare(jmap("path" -> "/"))
329
341
  val headers = fetchdef.get("headers").asInstanceOf[JMap[String, Object]]
330
- credentialIs("inactive.apikey", headers.get("authorization").asInstanceOf[String], "OPTKEY01")
342
+ credentialIs("inactive.apikey", headers.get(CREDHEADER).asInstanceOf[String], "OPTKEY01")
331
343
 
332
344
  check("inactive.nofeature", null == secretsFeatureOf(client),
333
345
  "no model activation and no extend: the feature must not be installed")
@@ -335,8 +347,8 @@ object SecretsTestMain {
335
347
  val bare = ProjectNameSDK.testSDK(null, null)
336
348
  val bareheaders = bare.prepare(jmap("path" -> "/"))
337
349
  .get("headers").asInstanceOf[JMap[String, Object]]
338
- check("inactive.noapikey", !bareheaders.containsKey("authorization"),
339
- "unexpected authorization header: " + bareheaders.get("authorization"))
350
+ check("inactive.noapikey", !bareheaders.containsKey(CREDHEADER),
351
+ "unexpected " + CREDHEADER + " header: " + bareheaders.get(CREDHEADER))
340
352
  }
341
353
 
342
354
  // =========================================================================
@@ -20,9 +20,9 @@
20
20
  // (the ts design) would have one thread walking the map while another
21
21
  // mutated it. The credential is therefore held in FEATURE STATE behind a
22
22
  // lock, the options map stays frozen after construction, and the
23
- // authorization header is rewritten per request at the transport - built
24
- // the same way prepareAuth builds it, from the same options.auth.prefix, so
25
- // the two cannot drift. This is go's structural deviation, adopted for a
23
+ // credential header is rewritten per request at the transport - built
24
+ // the same way prepareAuth builds it, from the same options.auth name and
25
+ // prefix, so the two cannot drift. This is go's structural deviation, adopted for a
26
26
  // sharper version of go's own reason.
27
27
  //
28
28
  // WHERE RESOLUTION HAPPENS. At the TRANSPORT SEAM, not in the PreSpec hook.
@@ -434,7 +434,7 @@ public final class SecretsFeature: BaseFeature {
434
434
  // withrefresh buys a token and tries the request again when the API says
435
435
  // the current one is spent.
436
436
  //
437
- // The retry rewrites the authorization header IN PLACE on the fetchdef,
437
+ // The retry rewrites the credential header IN PLACE on the fetchdef,
438
438
  // because the header was built by the synchronous prepareAuth before this
439
439
  // request left, and it carries the token that just failed.
440
440
  private func withrefresh(_ ctx: Context, _ url: String, _ fetchdef: VMap,
@@ -526,10 +526,14 @@ public final class SecretsFeature: BaseFeature {
526
526
  return
527
527
  }
528
528
 
529
+ // The header prepareAuth writes: auth.name, lower-cased.
530
+ let rawname = gp(auth, "name").asString ?? ""
531
+ let name = "" == rawname ? "authorization" : rawname.lowercased()
532
+
529
533
  let prefix = gp(auth, "prefix").asString ?? ""
530
534
  // Empty prefix (raw apiKey credential) must not add a leading space -
531
535
  // prepareAuth's rule, repeated here because this is the other writer.
532
- headers.entries["authorization"] = .string("" == prefix ? token : prefix + " " + token)
536
+ headers.entries[name] = .string("" == prefix ? token : prefix + " " + token)
533
537
  }
534
538
 
535
539
  // buy an access token with the refresh token. Concurrent callers share the
@@ -44,6 +44,14 @@ import XCTest
44
44
  import Sekreto
45
45
  import struct VoxgigPlugin.Definition
46
46
 
47
+ // The header the credential travels in: the DEFAULT client's auth.name,
48
+ // lower-cased as prepareAuth sends it. Read from a default client because a
49
+ // test's `auth: nil` leaves no name to read.
50
+ let secretsCredHeader: String = {
51
+ let name = gp(gp(ProjectNameSDK.testSDK(nil, nil).optionsMap(), "auth"), "name").asString ?? ""
52
+ return "" == name ? "authorization" : name.lowercased()
53
+ }()
54
+
47
55
  // -------------------------------------------------------------------
48
56
  // The recording transport: system.fetch for a LIVE client, scripting one
49
57
  // status per API call (the last repeating) and a token endpoint for the
@@ -89,7 +97,7 @@ final class SecretsWire {
89
97
  var auth = ""
90
98
  var hasAuth = false
91
99
  if let headers = gp(fetchdef, "headers").asMap {
92
- for (k, v) in headers.entries where k.lowercased() == "authorization" {
100
+ for (k, v) in headers.entries where k.lowercased() == secretsCredHeader {
93
101
  hasAuth = true
94
102
  auth = v.asString ?? stringify(v)
95
103
  }
@@ -176,14 +184,14 @@ final class SecretsFeatureTest: XCTestCase {
176
184
  // -------------------------------------------------------------------
177
185
  // Support.
178
186
 
179
- // The Authorization header carries the SPEC's credential prefix, which a
187
+ // The credential header carries the SPEC's credential prefix, which a
180
188
  // TEMPLATE cannot know: an OpenAPI `http`/`bearer` scheme gives
181
189
  // `Bearer <token>`, an apiKey scheme the raw token. So assert on the
182
190
  // CREDENTIAL and let the prefix be whatever this SDK's API declares.
183
191
  private func credentialIs(_ header: String, _ token: String,
184
192
  file: StaticString = #filePath, line: UInt = #line) {
185
193
  XCTAssertTrue(header == token || header.hasSuffix(" " + token),
186
- "expected the authorization header to carry \(token), got: \"\(header)\"",
194
+ "expected the \(secretsCredHeader) header to carry \(token), got: \"\(header)\"",
187
195
  file: file, line: line)
188
196
  }
189
197
 
@@ -331,7 +339,7 @@ final class SecretsFeatureTest: XCTestCase {
331
339
  let client = ProjectNameSDK.testSDK(nil, vm(("apikey", .string("OPTKEY01"))))
332
340
  let fetchdef = try client.prepare(vm(("path", .string("/"))))
333
341
  let headers = gp(fetchdef, "headers").asMap ?? VMap()
334
- credentialIs(gp(headers, "authorization").asString ?? "", "OPTKEY01")
342
+ credentialIs(gp(headers, secretsCredHeader).asString ?? "", "OPTKEY01")
335
343
 
336
344
  // No runtime activation, no extend: the feature must not be installed,
337
345
  // whatever this project's model says.
@@ -339,12 +347,12 @@ final class SecretsFeatureTest: XCTestCase {
339
347
  "the feature must not install itself without feature.secrets.active")
340
348
  }
341
349
 
342
- func testInactiveNoApikeyMeansNoAuthorizationHeader() throws {
350
+ func testInactiveNoApikeyMeansNoCredentialHeader() throws {
343
351
  let client = ProjectNameSDK.testSDK(nil, nil)
344
352
  let fetchdef = try client.prepare(vm(("path", .string("/"))))
345
353
  let headers = gp(fetchdef, "headers").asMap ?? VMap()
346
- XCTAssertNil(headers.entries["authorization"],
347
- "unexpected authorization header: \(stringify(gp(headers, "authorization")))")
354
+ XCTAssertNil(headers.entries[secretsCredHeader],
355
+ "unexpected \(secretsCredHeader) header: \(stringify(gp(headers, secretsCredHeader)))")
348
356
  }
349
357
 
350
358
  // ===================================================================
@@ -314,8 +314,12 @@ class SecretsFeature extends BaseFeature {
314
314
  return
315
315
  }
316
316
 
317
+ // The header prepareAuth wrote: auth.name, lower-cased.
318
+ const name = "string" === typeof auth.name && "" !== auth.name ?
319
+ auth.name.toLowerCase() : "authorization"
320
+
317
321
  const prefix = auth.prefix
318
- fetchdef.headers.authorization = prefix ? prefix + " " + token : token
322
+ fetchdef.headers[name] = prefix ? prefix + " " + token : token
319
323
  }
320
324
  }
321
325
 
@@ -8,6 +8,17 @@ import { SDK } from '../../utility/index'
8
8
  const ENVPREFIX = 'PROJECTENV_TEST_SECRETS_'
9
9
 
10
10
 
11
+ // The header the credential travels in: the DEFAULT client's auth.name,
12
+ // lower-cased as prepareAuth sends it. Read from a default client because
13
+ // a test's `auth: null` leaves no name to read.
14
+ const CREDHEADER = (() => {
15
+ const auth = (SDK as any).test({}, {}).options().auth
16
+ const name = null == auth ? null : auth.name
17
+ return 'string' === typeof name && '' !== name ?
18
+ name.toLowerCase() : 'authorization'
19
+ })()
20
+
21
+
11
22
  // prepare() returns the fetchdef the transport would receive — the closest
12
23
  // observable point to the wire for header assertions — and it awaits
13
24
  // secrets resolution itself, because it bypasses the feature hook pipeline.
@@ -22,7 +33,7 @@ async function prepared(sdkopts: any): Promise<any> {
22
33
  function credentialIs(header: any, token: string) {
23
34
  const got = String(null == header ? '' : header)
24
35
  assert.ok(got === token || got.endsWith(' ' + token),
25
- 'expected the Authorization header to carry ' + token + ', got: ' + got)
36
+ 'expected the ' + CREDHEADER + ' header to carry ' + token + ', got: ' + got)
26
37
  }
27
38
 
28
39
 
@@ -48,16 +59,16 @@ describe('secrets', () => {
48
59
 
49
60
  test('inactive: apikey option behaves exactly as before', async () => {
50
61
  const { sdk, fetchdef } = await prepared({ apikey: 'OPTKEY01' })
51
- credentialIs(fetchdef.headers['authorization'], 'OPTKEY01')
62
+ credentialIs(fetchdef.headers[CREDHEADER], 'OPTKEY01')
52
63
 
53
64
  // No feature, no instance: the accessor is the only way in.
54
65
  assert.equal(sdk.secrets(), undefined)
55
66
  })
56
67
 
57
68
 
58
- test('inactive: no apikey means no authorization header', async () => {
69
+ test('inactive: no apikey means no credential header', async () => {
59
70
  const { fetchdef } = await prepared({})
60
- assert.equal(fetchdef.headers['authorization'], undefined)
71
+ assert.equal(fetchdef.headers[CREDHEADER], undefined)
61
72
  })
62
73
 
63
74
 
@@ -66,7 +77,7 @@ describe('secrets', () => {
66
77
  const { sdk, fetchdef } = await prepared(
67
78
  Object.assign({ apikey: 'OPTKEY01' }, envchain()))
68
79
 
69
- credentialIs(fetchdef.headers['authorization'], 'OPTKEY01')
80
+ credentialIs(fetchdef.headers[CREDHEADER], 'OPTKEY01')
70
81
 
71
82
  // The explicit option is a real store, not a special case: a directed
72
83
  // read names it like any other.
@@ -78,7 +89,7 @@ describe('secrets', () => {
78
89
  test('active: an OMITTED apikey defers to the chain', async () => {
79
90
  process.env[ENVPREFIX + 'APIKEY'] = 'ENVKEY01'
80
91
  const { fetchdef } = await prepared(envchain())
81
- credentialIs(fetchdef.headers['authorization'], 'ENVKEY01')
92
+ credentialIs(fetchdef.headers[CREDHEADER], 'ENVKEY01')
82
93
  })
83
94
 
84
95
 
@@ -86,7 +97,7 @@ describe('secrets', () => {
86
97
  process.env[ENVPREFIX + 'APIKEY'] = 'ENVKEY01'
87
98
  const { fetchdef } = await prepared(
88
99
  Object.assign({ apikey: '' }, envchain()))
89
- credentialIs(fetchdef.headers['authorization'], 'ENVKEY01')
100
+ credentialIs(fetchdef.headers[CREDHEADER], 'ENVKEY01')
90
101
  })
91
102
 
92
103
 
@@ -97,7 +108,7 @@ describe('secrets', () => {
97
108
  Object.assign({ auth: null }, envchain()))
98
109
 
99
110
  // Nothing on the wire, even though the chain would have resolved.
100
- assert.equal(fetchdef.headers['authorization'], undefined)
111
+ assert.equal(fetchdef.headers[CREDHEADER], undefined)
101
112
 
102
113
  // The suppression survives option validation rather than being
103
114
  // replaced by the optspec's default auth map.
@@ -108,7 +119,7 @@ describe('secrets', () => {
108
119
  test('active: auth null suppresses an EXPLICIT apikey too', async () => {
109
120
  const { fetchdef } = await prepared(
110
121
  Object.assign({ apikey: 'OPTKEY01', auth: null }, envchain()))
111
- assert.equal(fetchdef.headers['authorization'], undefined)
122
+ assert.equal(fetchdef.headers[CREDHEADER], undefined)
112
123
  })
113
124
 
114
125
 
@@ -125,14 +136,14 @@ describe('secrets', () => {
125
136
  },
126
137
  },
127
138
  })
128
- credentialIs(fetchdef.headers['authorization'], 'CUSTOM01')
139
+ credentialIs(fetchdef.headers[CREDHEADER], 'CUSTOM01')
129
140
  assert.deepEqual(asked, ['apikey'])
130
141
  })
131
142
 
132
143
 
133
144
  test('active: a miss everywhere leaves the header off', async () => {
134
145
  const { sdk, fetchdef } = await prepared(envchain())
135
- assert.equal(fetchdef.headers['authorization'], undefined)
146
+ assert.equal(fetchdef.headers[CREDHEADER], undefined)
136
147
  assert.equal(sdk.options().apikey, '')
137
148
  })
138
149
 
@@ -185,7 +196,7 @@ describe('secrets', () => {
185
196
 
186
197
  const second = await sdk.prepare({ path: '/' })
187
198
  assert.ok(!(second instanceof Error), 'second attempt should recover, got ' + String(second))
188
- credentialIs(second.headers['authorization'], 'RECOVERED01')
199
+ credentialIs(second.headers[CREDHEADER], 'RECOVERED01')
189
200
  })
190
201
 
191
202
 
@@ -233,11 +244,11 @@ describe('secrets', () => {
233
244
  })
234
245
 
235
246
  const first = await sdk.prepare({ path: '/' })
236
- assert.equal(first.headers['authorization'], undefined,
247
+ assert.equal(first.headers[CREDHEADER], undefined,
237
248
  'the first resolve missed, so no credential should go out')
238
249
 
239
250
  const second = await sdk.prepare({ path: '/' })
240
- credentialIs(second.headers['authorization'], 'LATEKEY')
251
+ credentialIs(second.headers[CREDHEADER], 'LATEKEY')
241
252
 
242
253
  assert.ok(1 < calls,
243
254
  'the chain was asked once and the MISS cached: a secret that ' +
@@ -273,7 +284,7 @@ describe('secrets', () => {
273
284
  process.env[ENVPREFIX + 'API_TOKEN'] = 'TOKKEY01'
274
285
  try {
275
286
  const { fetchdef } = await prepared(envchain({ name: 'api.token' }))
276
- credentialIs(fetchdef.headers['authorization'], 'TOKKEY01')
287
+ credentialIs(fetchdef.headers[CREDHEADER], 'TOKKEY01')
277
288
  }
278
289
  finally {
279
290
  delete process.env[ENVPREFIX + 'API_TOKEN']
@@ -374,7 +385,7 @@ describe('secrets exchange', () => {
374
385
  let apicall = -1
375
386
 
376
387
  const fetch = async (url: string, init: any) => {
377
- calls.push({ url, init, auth: (init.headers || {})['authorization'] })
388
+ calls.push({ url, init, auth: (init.headers || {})[CREDHEADER] })
378
389
 
379
390
  if (url.endsWith('/' + (o.path || 'auth/token'))) {
380
391
  if (true === o.tokenfails) {
@@ -698,7 +709,7 @@ describe('secrets exchange', () => {
698
709
  const bought = stub.token().length
699
710
 
700
711
  const feature = sdk._secrets
701
- const fetchdef: any = { headers: { authorization: 'Bearer STALE01' } }
712
+ const fetchdef: any = { headers: { [CREDHEADER]: 'Bearer STALE01' } }
702
713
 
703
714
  sdk._options.apikey = 'STALE01'
704
715
 
@@ -719,7 +730,7 @@ describe('secrets exchange', () => {
719
730
  assert.equal(calls, 2, 'the request was retried once')
720
731
  assert.equal(stub.token().length, bought,
721
732
  'the retry must reuse the token another request already bought')
722
- authIs({ auth: fetchdef.headers.authorization }, 'ACCESS09')
733
+ authIs({ auth: fetchdef.headers[CREDHEADER] }, 'ACCESS09')
723
734
  })
724
735
 
725
736
 
@@ -728,7 +739,7 @@ describe('secrets exchange', () => {
728
739
 
729
740
  const { fetchdef } = await prepared(envchain())
730
741
 
731
- credentialIs(fetchdef.headers['authorization'], 'PLAINKEY01')
742
+ credentialIs(fetchdef.headers[CREDHEADER], 'PLAINKEY01')
732
743
  delete process.env[ENVPREFIX + 'APIKEY']
733
744
  })
734
745
 
@@ -754,7 +765,7 @@ describe('secrets exchange', () => {
754
765
 
755
766
  assert.equal(stub.calls.length, 0, 'test mode must not do IO')
756
767
  // A deterministic placeholder, so offline suites need no configuration.
757
- credentialIs(fetchdef.headers['authorization'], 'test-access_token')
768
+ credentialIs(fetchdef.headers[CREDHEADER], 'test-access_token')
758
769
  })
759
770
 
760
771
  })
@@ -613,11 +613,11 @@ fn resolve_once(st: *State, ctx: *Context) E!void {
613
613
  // Buy a token and try the request again when the API says the current one
614
614
  // is spent.
615
615
  //
616
- // The retry rewrites the authorization header IN PLACE on the fetchdef,
616
+ // The retry rewrites the credential header IN PLACE on the fetchdef,
617
617
  // because the header was built by the synchronous prepare_auth before this
618
618
  // request left and carries the token that just failed. Rebuilt the way
619
- // prepare_auth builds it, from the same options.auth.prefix, so the two
620
- // cannot drift.
619
+ // prepare_auth builds it, from the same options.auth name and prefix, so
620
+ // the two cannot drift.
621
621
  fn with_refresh(st: *State, ctx: *Context, url: []const u8, fetchdef: Value, inner: Fetcher) E!Value {
622
622
  // `auth: null` is the documented way to send NO credential, and
623
623
  // prepare_auth honours it by removing the header. A refusal of a
@@ -686,12 +686,18 @@ fn reauth(st: *State, fetchdef: Value, token: []const u8) void {
686
686
  const headers = h.getp(fetchdef, "headers");
687
687
  if (headers != .object) return;
688
688
 
689
+ // The header prepare_auth writes: auth.name, lower-cased.
690
+ const name: []const u8 = switch (h.getpath(&.{ "auth", "name" }, st.liveopts)) {
691
+ .string => |s| if (s.len == 0) HEADER_AUTH else std.ascii.allocLowerString(h.A(), s) catch HEADER_AUTH,
692
+ else => HEADER_AUTH,
693
+ };
694
+
689
695
  // Suppressed auth means NO header, the same answer prepare_auth gives.
690
696
  // Reached defensively - with_refresh does not retry at all when auth is
691
697
  // suppressed - but this is the function that writes the credential, so
692
698
  // it is where the rule has to hold.
693
699
  if (!auth_active(st.liveopts)) {
694
- h.del_prop(headers, h.vstr(HEADER_AUTH));
700
+ h.del_prop(headers, h.vstr(name));
695
701
  return;
696
702
  }
697
703
 
@@ -702,9 +708,9 @@ fn reauth(st: *State, fetchdef: Value, token: []const u8) void {
702
708
 
703
709
  // Empty prefix (a raw apiKey credential) must not add a leading space.
704
710
  if (0 == prefix.len) {
705
- h.setp(headers, HEADER_AUTH, h.vstr(token));
711
+ h.setp(headers, name, h.vstr(token));
706
712
  } else {
707
- h.setp(headers, HEADER_AUTH, h.vstr(std.fmt.allocPrint(h.A(), "{s} {s}", .{ prefix, token }) catch token));
713
+ h.setp(headers, name, h.vstr(std.fmt.allocPrint(h.A(), "{s} {s}", .{ prefix, token }) catch token));
708
714
  }
709
715
  }
710
716
 
@@ -61,6 +61,22 @@ fn present() bool {
61
61
  return h.getp(h.getp(cfg, "feature"), "secrets") == .object;
62
62
  }
63
63
 
64
+ // The header the credential travels in: the DEFAULT client's auth.name,
65
+ // lower-cased as prepare_auth sends it. Read from a default client because a
66
+ // test's `auth: null` leaves no name to read. Computed once.
67
+ var credheader: ?[]const u8 = null;
68
+
69
+ fn cred_header() []const u8 {
70
+ if (credheader) |name| return name;
71
+ const client = sdk.test_sdk(vnull(), vnull());
72
+ const name: []const u8 = switch (h.getpath(&.{ "auth", "name" }, client.options_map())) {
73
+ .string => |s| if (s.len == 0) "authorization" else std.ascii.allocLowerString(h.A(), s) catch "authorization",
74
+ else => "authorization",
75
+ };
76
+ credheader = name;
77
+ return name;
78
+ }
79
+
64
80
  // ---- the counted transport ---------------------------------------------
65
81
 
66
82
  /// One recorded request, SNAPSHOT at the moment it was handed to the
@@ -103,7 +119,7 @@ const Wire = struct {
103
119
  "";
104
120
  const fetchdef: Value = if (arg == .array and 2 <= arg.array.data.items.len) arg.array.data.items[1] else vnull();
105
121
  const headers = h.getp(fetchdef, "headers");
106
- const auth: ?[]const u8 = if (h.get_str(headers, "authorization")) |a| (h.A().dupe(u8, a) catch a) else null;
122
+ const auth: ?[]const u8 = if (h.get_str(headers, cred_header())) |a| (h.A().dupe(u8, a) catch a) else null;
107
123
  const body: ?[]const u8 = if (h.get_str(fetchdef, "body")) |b| (h.A().dupe(u8, b) catch b) else null;
108
124
  self.calls.append(h.A(), .{ .url = h.A().dupe(u8, url) catch url, .auth = auth, .body = body }) catch {};
109
125
 
@@ -227,15 +243,15 @@ fn count_named(client: *sdk.SDK, name: []const u8) usize {
227
243
  return n;
228
244
  }
229
245
 
230
- // The Authorization header carries the SPEC's credential prefix, which a
231
- // TEMPLATE cannot know: an OpenAPI bearer scheme gives `Bearer <token>`, an
246
+ // The credential header carries the SPEC's credential prefix (if any), which
247
+ // a TEMPLATE cannot know: an OpenAPI bearer scheme gives `Bearer <token>`, an
232
248
  // apiKey scheme the raw token. So assert on the CREDENTIAL and let the
233
249
  // prefix be whatever this SDK's API declares.
234
250
  fn credential_is(auth: ?[]const u8, token: []const u8) !void {
235
251
  const got = auth orelse "";
236
252
  const suffix = std.fmt.allocPrint(h.A(), " {s}", .{token}) catch token;
237
253
  if (!(std.mem.eql(u8, got, token) or std.mem.endsWith(u8, got, suffix))) {
238
- std.debug.print("expected the authorization header to carry {s}, got: {s}\n", .{ token, got });
254
+ std.debug.print("expected the {s} header to carry {s}, got: {s}\n", .{ cred_header(), token, got });
239
255
  return error.TestUnexpectedResult;
240
256
  }
241
257
  }
@@ -317,7 +333,7 @@ test "secrets inactive: apikey option behaves exactly as before" {
317
333
  try credential_is(w.api()[0].auth, "OPTKEY01");
318
334
  }
319
335
 
320
- test "secrets inactive: no apikey means no authorization header" {
336
+ test "secrets inactive: no apikey means no credential header" {
321
337
  if (!present()) return error.SkipZigTest;
322
338
  const w = Wire.new();
323
339
  const client = live_client(w, h.omap());
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.35.0",
6
+ "version": "4.35.1",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",