@sdk-it/typescript 0.46.4 → 0.46.6
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/README.md +15 -0
- package/dist/index.js +20 -11
- package/dist/index.js.map +2 -2
- package/dist/lib/emitters/zod.d.ts.map +1 -1
- package/dist/lib/generator.d.ts +1 -1
- package/dist/lib/security.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -61,6 +61,21 @@ Generated types enforce the value required by each scheme:
|
|
|
61
61
|
- Mutual TLS uses `true`; the configured `fetch` implementation owns the
|
|
62
62
|
client certificate.
|
|
63
63
|
|
|
64
|
+
Any scheme also accepts `true` to declare a transport-owned credential: the
|
|
65
|
+
requirement counts as satisfied and the client sets nothing, because something
|
|
66
|
+
outside it supplies the credential. That is the configuration for a browser
|
|
67
|
+
session cookie (`apiKey` with `in: cookie`; the browser sends it when the
|
|
68
|
+
configured `fetch` passes `credentials: 'include'`) and for a host proxy that
|
|
69
|
+
injects `Authorization` on the client's behalf:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const client = new ExampleClient({
|
|
73
|
+
baseUrl: '/api',
|
|
74
|
+
fetch: (request) => fetch(request, { credentials: 'include' }),
|
|
75
|
+
credentials: { session: true },
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
64
79
|
Each value may instead be a sync or async provider. Providers receive the
|
|
65
80
|
scheme name plus the current operation's OpenAPI scopes or roles:
|
|
66
81
|
|
package/dist/index.js
CHANGED
|
@@ -483,10 +483,10 @@ var TypeScriptEmitter = class {
|
|
|
483
483
|
if (types.length > 1) {
|
|
484
484
|
const realTypes = types.filter((t) => t !== "null");
|
|
485
485
|
if (realTypes.length === 1 && types.includes("null")) {
|
|
486
|
-
const tsType = this.normal(realTypes[0], schema,
|
|
486
|
+
const tsType = this.normal(realTypes[0], schema, true);
|
|
487
487
|
return appendOptional(`${tsType} | null`, required);
|
|
488
488
|
}
|
|
489
|
-
const typeResults = types.map((t) => this.normal(t, schema,
|
|
489
|
+
const typeResults = types.map((t) => this.normal(t, schema, true));
|
|
490
490
|
return appendOptional(typeResults.join(" | "), required);
|
|
491
491
|
}
|
|
492
492
|
return this.normal(types[0], schema, required);
|
|
@@ -771,9 +771,16 @@ var ZodEmitter = class {
|
|
|
771
771
|
if (types.length > 1) {
|
|
772
772
|
const realTypes = types.filter((t) => t !== "null");
|
|
773
773
|
if (realTypes.length === 1 && types.includes("null")) {
|
|
774
|
-
return this.normal(
|
|
774
|
+
return this.normal(
|
|
775
|
+
realTypes[0],
|
|
776
|
+
{ ...schema, type: realTypes[0] },
|
|
777
|
+
required,
|
|
778
|
+
true
|
|
779
|
+
);
|
|
775
780
|
}
|
|
776
|
-
const subSchemas = types.map(
|
|
781
|
+
const subSchemas = types.map(
|
|
782
|
+
(t) => this.normal(t, { ...schema, type: t }, true)
|
|
783
|
+
);
|
|
777
784
|
return `z.union([${subSchemas.join(", ")}])${appendOptional2(required)}`;
|
|
778
785
|
}
|
|
779
786
|
return this.normal(types[0], schema, required, false);
|
|
@@ -1753,7 +1760,8 @@ const providerSchema = <T extends SecurityCredentialValue>() =>
|
|
|
1753
1760
|
z.custom<SecurityCredentialProvider<T>>((value) => typeof value === 'function');
|
|
1754
1761
|
const stringCredentialSchema = z.union([
|
|
1755
1762
|
z.string(),
|
|
1756
|
-
|
|
1763
|
+
z.literal(true),
|
|
1764
|
+
providerSchema<string | true>(),
|
|
1757
1765
|
]);
|
|
1758
1766
|
const basicCredentialValueSchema = z.object({
|
|
1759
1767
|
username: z.string(),
|
|
@@ -1761,7 +1769,8 @@ const basicCredentialValueSchema = z.object({
|
|
|
1761
1769
|
});
|
|
1762
1770
|
const basicCredentialSchema = z.union([
|
|
1763
1771
|
basicCredentialValueSchema,
|
|
1764
|
-
|
|
1772
|
+
z.literal(true),
|
|
1773
|
+
providerSchema<{ username: string; password: string } | true>(),
|
|
1765
1774
|
]);
|
|
1766
1775
|
const mutualTlsCredentialSchema = z.union([
|
|
1767
1776
|
z.literal(true),
|
|
@@ -1833,6 +1842,9 @@ function applyCredential(
|
|
|
1833
1842
|
if (credential === undefined) {
|
|
1834
1843
|
throw new Error('Security credential provider returned no credential');
|
|
1835
1844
|
}
|
|
1845
|
+
// true declares a transport-owned credential: the configured fetch, a host
|
|
1846
|
+
// proxy, or the browser's cookie jar supplies it, so nothing is set here.
|
|
1847
|
+
if (credential === true) return;
|
|
1836
1848
|
if (scheme.type === 'apiKey') {
|
|
1837
1849
|
if (typeof credential !== 'string') {
|
|
1838
1850
|
throw new TypeError('API key credentials must be strings');
|
|
@@ -1846,7 +1858,7 @@ function applyCredential(
|
|
|
1846
1858
|
config.url.searchParams.set(scheme.name, credential);
|
|
1847
1859
|
}
|
|
1848
1860
|
} else if (scheme.in === 'cookie') {
|
|
1849
|
-
if (
|
|
1861
|
+
if ('document' in globalThis) {
|
|
1850
1862
|
throw new Error(
|
|
1851
1863
|
\`Cannot send the \${scheme.name} cookie credential: browsers forbid setting the Cookie header. Let the browser send the cookie and pass a fetch that sets credentials: 'include'.\`,
|
|
1852
1864
|
);
|
|
@@ -1862,10 +1874,7 @@ function applyCredential(
|
|
|
1862
1874
|
return;
|
|
1863
1875
|
}
|
|
1864
1876
|
if (scheme.type === 'mutualTLS') {
|
|
1865
|
-
|
|
1866
|
-
throw new TypeError('mutualTLS credentials must be true when the custom fetch owns the client certificate');
|
|
1867
|
-
}
|
|
1868
|
-
return;
|
|
1877
|
+
throw new TypeError('mutualTLS credentials must be true when the custom fetch owns the client certificate');
|
|
1869
1878
|
}
|
|
1870
1879
|
if (scheme.type === 'http' && scheme.scheme.toLowerCase() === 'basic') {
|
|
1871
1880
|
if (
|