retell-sdk 2.2.3 → 2.2.4
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/example.js +34 -2
- package/example.js.map +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/sdks.d.ts.map +1 -1
- package/lib/sdks.js.map +1 -1
- package/lib/security.d.ts.map +1 -1
- package/lib/security.js +5 -1
- package/lib/security.js.map +1 -1
- package/models/components/agent.d.ts +3 -3
- package/models/components/agent.d.ts.map +1 -1
- package/models/components/agent.js +60 -26
- package/models/components/agent.js.map +1 -1
- package/models/components/agentpromptparams.d.ts.map +1 -1
- package/models/components/agentpromptparams.js.map +1 -1
- package/models/components/calldetail.d.ts.map +1 -1
- package/models/components/calldetail.js +18 -6
- package/models/components/calldetail.js.map +1 -1
- package/models/components/callphonenumber.d.ts.map +1 -1
- package/models/components/callphonenumber.js.map +1 -1
- package/models/components/phonenumber.d.ts.map +1 -1
- package/models/components/phonenumber.js.map +1 -1
- package/models/components/security.d.ts.map +1 -1
- package/models/errors/createagent.d.ts.map +1 -1
- package/models/errors/createagent.js +36 -12
- package/models/errors/createagent.js.map +1 -1
- package/models/errors/createphonecall.d.ts.map +1 -1
- package/models/errors/createphonecall.js +54 -18
- package/models/errors/createphonecall.js.map +1 -1
- package/models/errors/createphonenumber.d.ts.map +1 -1
- package/models/errors/createphonenumber.js +42 -14
- package/models/errors/createphonenumber.js.map +1 -1
- package/models/errors/deleteagent.d.ts.map +1 -1
- package/models/errors/deleteagent.js +36 -12
- package/models/errors/deleteagent.js.map +1 -1
- package/models/errors/deletephonenumber.d.ts.map +1 -1
- package/models/errors/deletephonenumber.js +33 -11
- package/models/errors/deletephonenumber.js.map +1 -1
- package/models/errors/getagent.d.ts.map +1 -1
- package/models/errors/getagent.js +36 -12
- package/models/errors/getagent.js.map +1 -1
- package/models/errors/getcall.d.ts.map +1 -1
- package/models/errors/getcall.js +30 -10
- package/models/errors/getcall.js.map +1 -1
- package/models/errors/getphonenumber.d.ts.map +1 -1
- package/models/errors/getphonenumber.js +36 -12
- package/models/errors/getphonenumber.js.map +1 -1
- package/models/errors/listagents.d.ts.map +1 -1
- package/models/errors/listagents.js +15 -5
- package/models/errors/listagents.js.map +1 -1
- package/models/errors/listcalls.d.ts.map +1 -1
- package/models/errors/listcalls.js +24 -8
- package/models/errors/listcalls.js.map +1 -1
- package/models/errors/listphonenumbers.d.ts.map +1 -1
- package/models/errors/listphonenumbers.js +27 -9
- package/models/errors/listphonenumbers.js.map +1 -1
- package/models/errors/updateagent.d.ts.map +1 -1
- package/models/errors/updateagent.js +36 -12
- package/models/errors/updateagent.js.map +1 -1
- package/models/errors/updatephoneagent.d.ts.map +1 -1
- package/models/errors/updatephoneagent.js +36 -12
- package/models/errors/updatephoneagent.js.map +1 -1
- package/models/operations/createagent.d.ts.map +1 -1
- package/models/operations/createagent.js +16 -6
- package/models/operations/createagent.js.map +1 -1
- package/models/operations/createphonecall.d.ts.map +1 -1
- package/models/operations/createphonecall.js +18 -6
- package/models/operations/createphonecall.js.map +1 -1
- package/models/operations/createphonenumber.d.ts.map +1 -1
- package/models/operations/createphonenumber.js +6 -2
- package/models/operations/createphonenumber.js.map +1 -1
- package/models/operations/createwebcall.d.ts.map +1 -1
- package/models/operations/deleteagent.d.ts.map +1 -1
- package/models/operations/deleteagent.js.map +1 -1
- package/models/operations/deletephonenumber.d.ts.map +1 -1
- package/models/operations/deletephonenumber.js.map +1 -1
- package/models/operations/getagent.d.ts.map +1 -1
- package/models/operations/getagent.js.map +1 -1
- package/models/operations/getcall.d.ts.map +1 -1
- package/models/operations/getcall.js.map +1 -1
- package/models/operations/getphonenumber.d.ts.map +1 -1
- package/models/operations/getphonenumber.js +6 -2
- package/models/operations/getphonenumber.js.map +1 -1
- package/models/operations/listagents.d.ts.map +1 -1
- package/models/operations/listagents.js.map +1 -1
- package/models/operations/listcalls.d.ts.map +1 -1
- package/models/operations/listcalls.js +6 -2
- package/models/operations/listcalls.js.map +1 -1
- package/models/operations/listphonenumbers.d.ts.map +1 -1
- package/models/operations/listphonenumbers.js +6 -2
- package/models/operations/listphonenumbers.js.map +1 -1
- package/models/operations/updateagent.d.ts.map +1 -1
- package/models/operations/updateagent.js +18 -4
- package/models/operations/updateagent.js.map +1 -1
- package/models/operations/updatephoneagent.d.ts.map +1 -1
- package/models/operations/updatephoneagent.js +6 -2
- package/models/operations/updatephoneagent.js.map +1 -1
- package/package.json +1 -1
- package/sdk/liveClient.d.ts.map +1 -1
- package/sdk/liveClient.js +7 -2
- package/sdk/liveClient.js.map +1 -1
- package/sdk/sdk.d.ts.map +1 -1
- package/sdk/sdk.js +22 -5
- package/sdk/sdk.js.map +1 -1
- package/src/example.ts +121 -87
- package/src/lib/config.ts +32 -32
- package/src/lib/sdks.ts +91 -82
- package/src/lib/security.ts +133 -118
- package/src/models/components/agent.ts +459 -387
- package/src/models/components/agentpromptparams.ts +46 -38
- package/src/models/components/calldetail.ts +137 -125
- package/src/models/components/callphonenumber.ts +46 -38
- package/src/models/components/phonenumber.ts +69 -68
- package/src/models/components/security.ts +1 -1
- package/src/models/errors/createagent.ts +359 -311
- package/src/models/errors/createphonecall.ts +537 -472
- package/src/models/errors/createphonenumber.ts +447 -395
- package/src/models/errors/deleteagent.ts +359 -311
- package/src/models/errors/deletephonenumber.ts +357 -315
- package/src/models/errors/getagent.ts +358 -302
- package/src/models/errors/getcall.ts +348 -294
- package/src/models/errors/getphonenumber.ts +357 -312
- package/src/models/errors/listagents.ts +174 -147
- package/src/models/errors/listcalls.ts +251 -211
- package/src/models/errors/listphonenumbers.ts +252 -217
- package/src/models/errors/updateagent.ts +359 -311
- package/src/models/errors/updatephoneagent.ts +357 -312
- package/src/models/operations/createagent.ts +165 -129
- package/src/models/operations/createphonecall.ts +283 -238
- package/src/models/operations/createphonenumber.ts +118 -98
- package/src/models/operations/createwebcall.ts +13 -13
- package/src/models/operations/deleteagent.ts +94 -78
- package/src/models/operations/deletephonenumber.ts +94 -78
- package/src/models/operations/getagent.ts +104 -88
- package/src/models/operations/getcall.ts +101 -88
- package/src/models/operations/getphonenumber.ts +108 -88
- package/src/models/operations/listagents.ts +68 -60
- package/src/models/operations/listcalls.ts +238 -213
- package/src/models/operations/listphonenumbers.ts +72 -60
- package/src/models/operations/updateagent.ts +226 -173
- package/src/models/operations/updatephoneagent.ts +160 -132
- package/src/sdk/liveClient.ts +11 -7
- package/src/sdk/sdk.ts +1313 -1160
package/src/lib/sdks.ts
CHANGED
|
@@ -2,106 +2,115 @@
|
|
|
2
2
|
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
HTTPClient,
|
|
7
|
+
matchResponse,
|
|
8
|
+
matchStatusCode,
|
|
9
|
+
unpackHeaders,
|
|
10
|
+
} from "./http";
|
|
11
|
+
import {
|
|
12
|
+
SecurityState,
|
|
13
|
+
resolveSecurity,
|
|
14
|
+
resolveGlobalSecurity,
|
|
15
|
+
} from "./security";
|
|
7
16
|
import { pathToFunc } from "./url";
|
|
8
17
|
import { encodeForm } from "./encodings";
|
|
9
18
|
import { stringToBase64 } from "./base64";
|
|
10
19
|
|
|
11
20
|
export type RequestOptions = {
|
|
12
|
-
|
|
21
|
+
fetchOptions?: Omit<RequestInit, "method" | "body">;
|
|
13
22
|
};
|
|
14
23
|
|
|
15
24
|
type RequestConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
method: string;
|
|
26
|
+
path: string;
|
|
27
|
+
baseURL?: string | URL;
|
|
28
|
+
query?: string;
|
|
29
|
+
body?: RequestInit["body"];
|
|
30
|
+
headers?: HeadersInit;
|
|
31
|
+
security?: SecurityState | null;
|
|
23
32
|
};
|
|
24
33
|
|
|
25
34
|
export class ClientSDK {
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
readonly #client: HTTPClient;
|
|
36
|
+
protected readonly baseURL: URL;
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
constructor(init: { client: HTTPClient; baseURL: URL }) {
|
|
39
|
+
const url = init.baseURL;
|
|
40
|
+
url.pathname = url.pathname.replace(/\/+$/, "") + "/";
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
this.#client = init.client;
|
|
43
|
+
this.baseURL = url;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async fetch$(conf: RequestConfig, options?: RequestOptions) {
|
|
47
|
+
const { method, path, query, headers: opHeaders, security } = conf;
|
|
48
|
+
|
|
49
|
+
const reqURL = new URL(conf.baseURL ?? this.baseURL);
|
|
50
|
+
const inputURL = new URL(path, reqURL);
|
|
51
|
+
|
|
52
|
+
if (path) {
|
|
53
|
+
reqURL.pathname += inputURL.pathname.replace(/^\/+/, "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let finalQuery = query || "";
|
|
57
|
+
|
|
58
|
+
const secQuery: string[] = [];
|
|
59
|
+
for (const [k, v] of Object.entries(security?.queryParams || {})) {
|
|
60
|
+
secQuery.push(encodeForm(k, v, { charEncoding: "percent" }));
|
|
61
|
+
}
|
|
62
|
+
if (secQuery.length) {
|
|
63
|
+
finalQuery += `&${secQuery.join("&")}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (finalQuery) {
|
|
67
|
+
const q = finalQuery.startsWith("&") ? finalQuery.slice(1) : finalQuery;
|
|
68
|
+
reqURL.search = `?${q}`;
|
|
35
69
|
}
|
|
36
70
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
finalQuery += `&${secQuery.join("&")}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (finalQuery) {
|
|
58
|
-
const q = finalQuery.startsWith("&") ? finalQuery.slice(1) : finalQuery;
|
|
59
|
-
reqURL.search = `?${q}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const headers = new Headers(opHeaders);
|
|
63
|
-
|
|
64
|
-
const username = security?.basic.username || "";
|
|
65
|
-
const password = security?.basic.password || "";
|
|
66
|
-
if (username) {
|
|
67
|
-
const encoded = stringToBase64([username, password].join(":"));
|
|
68
|
-
headers.set("Authorization", `Basic ${encoded}`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const securityHeaders = new Headers(security?.headers || {});
|
|
72
|
-
for (const [k, v] of securityHeaders) {
|
|
73
|
-
headers.set(k, v);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let cookie = headers.get("cookie") || "";
|
|
77
|
-
for (const [k, v] of Object.entries(security?.cookies || {})) {
|
|
78
|
-
cookie += `; ${k}=${v}`;
|
|
79
|
-
}
|
|
80
|
-
cookie = cookie.startsWith("; ") ? cookie.slice(2) : cookie;
|
|
81
|
-
headers.set("cookie", cookie);
|
|
82
|
-
|
|
83
|
-
const userHeaders = new Headers(options?.fetchOptions?.headers);
|
|
84
|
-
for (const [k, v] of userHeaders) {
|
|
85
|
-
headers.set(k, v);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const req = new Request(reqURL, {
|
|
89
|
-
...options?.fetchOptions,
|
|
90
|
-
body: conf.body ?? null,
|
|
91
|
-
headers,
|
|
92
|
-
method,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return this.#client.request(req);
|
|
71
|
+
const headers = new Headers(opHeaders);
|
|
72
|
+
|
|
73
|
+
const username = security?.basic.username || "";
|
|
74
|
+
const password = security?.basic.password || "";
|
|
75
|
+
if (username) {
|
|
76
|
+
const encoded = stringToBase64([username, password].join(":"));
|
|
77
|
+
headers.set("Authorization", `Basic ${encoded}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const securityHeaders = new Headers(security?.headers || {});
|
|
81
|
+
for (const [k, v] of securityHeaders) {
|
|
82
|
+
headers.set(k, v);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let cookie = headers.get("cookie") || "";
|
|
86
|
+
for (const [k, v] of Object.entries(security?.cookies || {})) {
|
|
87
|
+
cookie += `; ${k}=${v}`;
|
|
96
88
|
}
|
|
89
|
+
cookie = cookie.startsWith("; ") ? cookie.slice(2) : cookie;
|
|
90
|
+
headers.set("cookie", cookie);
|
|
91
|
+
|
|
92
|
+
const userHeaders = new Headers(options?.fetchOptions?.headers);
|
|
93
|
+
for (const [k, v] of userHeaders) {
|
|
94
|
+
headers.set(k, v);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const req = new Request(reqURL, {
|
|
98
|
+
...options?.fetchOptions,
|
|
99
|
+
body: conf.body ?? null,
|
|
100
|
+
headers,
|
|
101
|
+
method,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return this.#client.request(req);
|
|
105
|
+
}
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
protected unpackHeaders = unpackHeaders;
|
|
99
108
|
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
protected matchStatusCode = matchStatusCode;
|
|
110
|
+
protected matchResponse = matchResponse;
|
|
102
111
|
|
|
103
|
-
|
|
112
|
+
protected templateURLComponent = pathToFunc;
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
protected resolveSecurity = resolveSecurity;
|
|
115
|
+
protected resolveGlobalSecurity = resolveGlobalSecurity;
|
|
107
116
|
}
|
package/src/lib/security.ts
CHANGED
|
@@ -5,160 +5,175 @@
|
|
|
5
5
|
import * as components from "../models/components";
|
|
6
6
|
|
|
7
7
|
export enum SecurityErrorCode {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Incomplete = "incomplete",
|
|
9
|
+
UnrecognisedSecurityType = "unrecognized_security_type",
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class SecurityError extends Error {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
constructor(
|
|
14
|
+
public code: SecurityErrorCode,
|
|
15
|
+
message: string,
|
|
16
|
+
options?: ErrorOptions,
|
|
17
|
+
) {
|
|
18
|
+
super(message, options);
|
|
19
|
+
this.name = "SecurityError";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static incomplete(): SecurityError {
|
|
23
|
+
return new SecurityError(
|
|
24
|
+
SecurityErrorCode.Incomplete,
|
|
25
|
+
"Security requirements not met in order to perform the operation",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
static unrecognizedType(type: string): SecurityError {
|
|
29
|
+
return new SecurityError(
|
|
30
|
+
SecurityErrorCode.UnrecognisedSecurityType,
|
|
31
|
+
`Unrecognised security type: ${type}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
export type SecurityState = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
basic: { username: string; password?: string };
|
|
38
|
+
headers: Record<string, string>;
|
|
39
|
+
queryParams: Record<string, string>;
|
|
40
|
+
cookies: Record<string, string>;
|
|
37
41
|
};
|
|
38
42
|
|
|
39
43
|
type SecurityInputBasicPacked = {
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
type: "http:basic";
|
|
45
|
+
value: { username: string; password?: string } | null | undefined;
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
type SecurityInputBasic = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
type: "http:basic";
|
|
50
|
+
value: string | null | undefined;
|
|
51
|
+
fieldName: "username" | "password";
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
type SecurityInputBearer = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
type: "http:bearer";
|
|
56
|
+
value: string | null | undefined;
|
|
57
|
+
fieldName: string;
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
type SecurityInputAPIKey = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
type: "apiKey:header" | "apiKey:query" | "apiKey:cookie";
|
|
62
|
+
value: string | null | undefined;
|
|
63
|
+
fieldName: string;
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
type SecurityInputOIDC = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
type: "openIdConnect";
|
|
68
|
+
value: string | null | undefined;
|
|
69
|
+
fieldName: string;
|
|
66
70
|
};
|
|
67
71
|
|
|
68
72
|
type SecurityInputOAuth2 = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
type: "oauth2";
|
|
74
|
+
value: string | null | undefined;
|
|
75
|
+
fieldName: string;
|
|
72
76
|
};
|
|
73
77
|
|
|
74
78
|
export type SecurityInput =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export function resolveSecurity(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const { type } = spec;
|
|
101
|
-
|
|
102
|
-
switch (type) {
|
|
103
|
-
case "apiKey:header":
|
|
104
|
-
state.headers[spec.fieldName] = spec.value;
|
|
105
|
-
break;
|
|
106
|
-
case "apiKey:query":
|
|
107
|
-
state.queryParams[spec.fieldName] = spec.value;
|
|
108
|
-
break;
|
|
109
|
-
case "apiKey:cookie":
|
|
110
|
-
state.cookies[spec.fieldName] = spec.value;
|
|
111
|
-
break;
|
|
112
|
-
case "http:basic":
|
|
113
|
-
applyBasic(state, spec);
|
|
114
|
-
break;
|
|
115
|
-
case "http:bearer":
|
|
116
|
-
applyBearer(state, spec);
|
|
117
|
-
break;
|
|
118
|
-
case "oauth2":
|
|
119
|
-
applyBearer(state, spec);
|
|
120
|
-
break;
|
|
121
|
-
case "openIdConnect":
|
|
122
|
-
applyBearer(state, spec);
|
|
123
|
-
break;
|
|
124
|
-
default:
|
|
125
|
-
spec satisfies never;
|
|
126
|
-
throw SecurityError.unrecognizedType(type);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return state;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function applyBasic(state: SecurityState, spec: SecurityInputBasic | SecurityInputBasicPacked) {
|
|
79
|
+
| SecurityInputBasic
|
|
80
|
+
| SecurityInputBasicPacked
|
|
81
|
+
| SecurityInputBearer
|
|
82
|
+
| SecurityInputAPIKey
|
|
83
|
+
| SecurityInputOAuth2
|
|
84
|
+
| SecurityInputOIDC;
|
|
85
|
+
|
|
86
|
+
export function resolveSecurity(
|
|
87
|
+
...options: SecurityInput[][]
|
|
88
|
+
): SecurityState | null {
|
|
89
|
+
const state: SecurityState = {
|
|
90
|
+
basic: { username: "", password: "" },
|
|
91
|
+
headers: {},
|
|
92
|
+
queryParams: {},
|
|
93
|
+
cookies: {},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const option = options.find((opts) => opts.every((o) => Boolean(o.value)));
|
|
97
|
+
if (option == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
option.forEach((spec) => {
|
|
134
102
|
if (spec.value == null) {
|
|
135
|
-
|
|
103
|
+
return;
|
|
136
104
|
}
|
|
137
105
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
106
|
+
const { type } = spec;
|
|
107
|
+
|
|
108
|
+
switch (type) {
|
|
109
|
+
case "apiKey:header":
|
|
110
|
+
state.headers[spec.fieldName] = spec.value;
|
|
111
|
+
break;
|
|
112
|
+
case "apiKey:query":
|
|
113
|
+
state.queryParams[spec.fieldName] = spec.value;
|
|
114
|
+
break;
|
|
115
|
+
case "apiKey:cookie":
|
|
116
|
+
state.cookies[spec.fieldName] = spec.value;
|
|
117
|
+
break;
|
|
118
|
+
case "http:basic":
|
|
119
|
+
applyBasic(state, spec);
|
|
120
|
+
break;
|
|
121
|
+
case "http:bearer":
|
|
122
|
+
applyBearer(state, spec);
|
|
123
|
+
break;
|
|
124
|
+
case "oauth2":
|
|
125
|
+
applyBearer(state, spec);
|
|
126
|
+
break;
|
|
127
|
+
case "openIdConnect":
|
|
128
|
+
applyBearer(state, spec);
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
spec satisfies never;
|
|
132
|
+
throw SecurityError.unrecognizedType(type);
|
|
142
133
|
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return state;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function applyBasic(
|
|
140
|
+
state: SecurityState,
|
|
141
|
+
spec: SecurityInputBasic | SecurityInputBasicPacked,
|
|
142
|
+
) {
|
|
143
|
+
if (spec.value == null) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if ("fieldName" in spec) {
|
|
148
|
+
state.basic[spec.fieldName] = spec.value;
|
|
149
|
+
} else {
|
|
150
|
+
state.basic = spec.value;
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
|
|
145
154
|
function applyBearer(
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
state: SecurityState,
|
|
156
|
+
spec: SecurityInputBearer | SecurityInputOAuth2 | SecurityInputOIDC,
|
|
148
157
|
) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
158
|
+
if (spec.value == null) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
162
|
+
let value = spec.value;
|
|
163
|
+
if (value.slice(0, 7).toLowerCase() !== "bearer ") {
|
|
164
|
+
value = `Bearer ${value}`;
|
|
165
|
+
}
|
|
157
166
|
|
|
158
|
-
|
|
167
|
+
state.headers[spec.fieldName] = value;
|
|
159
168
|
}
|
|
160
|
-
export function resolveGlobalSecurity(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
export function resolveGlobalSecurity(
|
|
170
|
+
security: Partial<components.Security> | null | undefined,
|
|
171
|
+
) {
|
|
172
|
+
return resolveSecurity([
|
|
173
|
+
{
|
|
174
|
+
value: security?.apiKey,
|
|
175
|
+
fieldName: "Authorization",
|
|
176
|
+
type: "http:bearer",
|
|
177
|
+
},
|
|
178
|
+
]);
|
|
164
179
|
}
|