@drttix/drt-sdk 0.6.5 → 0.7.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/azure-pipelines.yml +15 -6
- package/demo/default.html +2 -1
- package/demo/test.html +529 -102
- package/demo/with-base.html +10 -8
- package/dist/bundle/drt-sdk.js +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/src/generated/portal/core/OpenAPI.js +1 -1
- package/dist/cjs/src/generated/portal/core/request.js +3 -1
- package/dist/cjs/src/generated/portal/services/AccountService.d.ts +12 -2
- package/dist/cjs/src/generated/portal/services/AccountService.js +26 -2
- package/dist/cjs/src/generated/portal/services/AuthService.d.ts +2 -1
- package/dist/cjs/src/generated/portal/services/AuthService.js +5 -1
- package/dist/cjs/src/generated/portal/services/FeaturesBlockedSeatsService.d.ts +10 -7
- package/dist/cjs/src/generated/portal/services/FeaturesBlockedSeatsService.js +19 -7
- package/dist/cjs/src/generated/portal/services/OrderLookupService.d.ts +4 -3
- package/dist/cjs/src/generated/portal/services/OrderLookupService.js +7 -3
- package/dist/cjs/src/generated/scanner/core/request.d.ts +7 -10
- package/dist/cjs/src/generated/scanner/core/request.js +56 -37
- package/dist/cjs/src/generated/shopper/core/request.js +3 -1
- package/dist/cjs/src/scripts/build-all.js +9 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/src/generated/portal/core/OpenAPI.js +1 -1
- package/dist/esm/src/generated/portal/core/request.js +3 -1
- package/dist/esm/src/generated/portal/services/AccountService.d.ts +12 -2
- package/dist/esm/src/generated/portal/services/AccountService.js +26 -2
- package/dist/esm/src/generated/portal/services/AuthService.d.ts +2 -1
- package/dist/esm/src/generated/portal/services/AuthService.js +5 -1
- package/dist/esm/src/generated/portal/services/FeaturesBlockedSeatsService.d.ts +10 -7
- package/dist/esm/src/generated/portal/services/FeaturesBlockedSeatsService.js +19 -7
- package/dist/esm/src/generated/portal/services/OrderLookupService.d.ts +4 -3
- package/dist/esm/src/generated/portal/services/OrderLookupService.js +7 -3
- package/dist/esm/src/generated/scanner/core/request.d.ts +7 -10
- package/dist/esm/src/generated/scanner/core/request.js +58 -39
- package/dist/esm/src/generated/shopper/core/request.js +3 -1
- package/dist/esm/src/scripts/build-all.js +9 -1
- package/index.ts +5 -0
- package/package.json +3 -1
- package/src/custom/custom-request.txt +7 -2
- package/src/generated/portal/core/OpenAPI.ts +1 -1
- package/src/generated/portal/core/request.ts +7 -2
- package/src/generated/portal/services/AccountService.ts +30 -1
- package/src/generated/portal/services/AuthService.ts +7 -1
- package/src/generated/portal/services/FeaturesBlockedSeatsService.ts +23 -6
- package/src/generated/portal/services/OrderLookupService.ts +7 -2
- package/src/generated/scanner/core/request.ts +331 -266
- package/src/generated/shopper/core/request.ts +7 -2
- package/src/scripts/build-all.ts +14 -1
|
@@ -2,321 +2,386 @@
|
|
|
2
2
|
/* istanbul ignore file */
|
|
3
3
|
/* tslint:disable */
|
|
4
4
|
/* eslint-disable */
|
|
5
|
-
import { ApiError } from
|
|
6
|
-
import type { ApiRequestOptions } from
|
|
7
|
-
import type { ApiResult } from
|
|
8
|
-
import { CancelablePromise } from
|
|
9
|
-
import type { OnCancel } from
|
|
10
|
-
import type { OpenAPIConfig } from
|
|
11
|
-
|
|
12
|
-
export const isDefined = <T>(
|
|
13
|
-
|
|
5
|
+
import { ApiError } from "./ApiError";
|
|
6
|
+
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
7
|
+
import type { ApiResult } from "./ApiResult";
|
|
8
|
+
import { CancelablePromise } from "./CancelablePromise";
|
|
9
|
+
import type { OnCancel } from "./CancelablePromise";
|
|
10
|
+
import type { OpenAPIConfig } from "./OpenAPI";
|
|
11
|
+
|
|
12
|
+
export const isDefined = <T>(
|
|
13
|
+
value: T | null | undefined
|
|
14
|
+
): value is Exclude<T, null | undefined> => {
|
|
15
|
+
return value !== undefined && value !== null;
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
export const isString = (value: any): value is string => {
|
|
17
|
-
|
|
19
|
+
return typeof value === "string";
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
export const isStringWithValue = (value: any): value is string => {
|
|
21
|
-
|
|
23
|
+
return isString(value) && value !== "";
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export const isBlob = (value: any): value is Blob => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
return (
|
|
28
|
+
typeof value === "object" &&
|
|
29
|
+
typeof value.type === "string" &&
|
|
30
|
+
typeof value.stream === "function" &&
|
|
31
|
+
typeof value.arrayBuffer === "function" &&
|
|
32
|
+
typeof value.constructor === "function" &&
|
|
33
|
+
typeof value.constructor.name === "string" &&
|
|
34
|
+
/^(Blob|File)$/.test(value.constructor.name) &&
|
|
35
|
+
/^(Blob|File)$/.test(value[Symbol.toStringTag])
|
|
36
|
+
);
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
export const isFormData = (value: any): value is FormData => {
|
|
38
|
-
|
|
40
|
+
return value instanceof FormData;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export const base64 = (str: string): string => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
try {
|
|
45
|
+
return btoa(str);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
return Buffer.from(str).toString("base64");
|
|
49
|
+
}
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
export const getQueryString = (params: Record<string, any>): string => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
53
|
+
const qs: string[] = [];
|
|
54
|
+
|
|
55
|
+
const append = (key: string, value: any) => {
|
|
56
|
+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const process = (key: string, value: any) => {
|
|
60
|
+
if (isDefined(value)) {
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
value.forEach((v) => {
|
|
63
|
+
process(key, v);
|
|
64
|
+
});
|
|
65
|
+
} else if (typeof value === "object") {
|
|
66
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
67
|
+
process(`${key}[${k}]`, v);
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
append(key, value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
76
|
+
process(key, value);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (qs.length > 0) {
|
|
80
|
+
return `?${qs.join("&")}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return "";
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
88
|
+
|
|
89
|
+
const path = options.url
|
|
90
|
+
.replace("{api-version}", config.VERSION)
|
|
91
|
+
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
|
92
|
+
if (options.path?.hasOwnProperty(group)) {
|
|
93
|
+
return encoder(String(options.path[group]));
|
|
94
|
+
}
|
|
95
|
+
return substring;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const url = `${config.BASE}${path}`;
|
|
99
|
+
if (options.query) {
|
|
100
|
+
return `${url}${getQueryString(options.query)}`;
|
|
101
|
+
}
|
|
102
|
+
return url;
|
|
101
103
|
};
|
|
102
104
|
|
|
103
|
-
export const getFormData = (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
105
|
+
export const getFormData = (
|
|
106
|
+
options: ApiRequestOptions
|
|
107
|
+
): FormData | undefined => {
|
|
108
|
+
if (options.formData) {
|
|
109
|
+
const formData = new FormData();
|
|
110
|
+
|
|
111
|
+
const process = (key: string, value: any) => {
|
|
112
|
+
if (isString(value) || isBlob(value)) {
|
|
113
|
+
formData.append(key, value);
|
|
114
|
+
} else {
|
|
115
|
+
formData.append(key, JSON.stringify(value));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
Object.entries(options.formData)
|
|
120
|
+
.filter(([_, value]) => isDefined(value))
|
|
121
|
+
.forEach(([key, value]) => {
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
value.forEach((v) => process(key, v));
|
|
124
|
+
} else {
|
|
125
|
+
process(key, value);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return formData;
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
128
132
|
};
|
|
129
133
|
|
|
130
134
|
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
|
|
131
135
|
|
|
132
|
-
export const resolve = async <T>(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
export const resolve = async <T>(
|
|
137
|
+
options: ApiRequestOptions,
|
|
138
|
+
resolver?: T | Resolver<T>
|
|
139
|
+
): Promise<T | undefined> => {
|
|
140
|
+
if (typeof resolver === "function") {
|
|
141
|
+
return (resolver as Resolver<T>)(options);
|
|
142
|
+
}
|
|
143
|
+
return resolver;
|
|
137
144
|
};
|
|
138
145
|
|
|
139
|
-
export const getHeaders = async (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
146
|
+
export const getHeaders = async (
|
|
147
|
+
config: OpenAPIConfig,
|
|
148
|
+
options: ApiRequestOptions
|
|
149
|
+
): Promise<Headers> => {
|
|
150
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
151
|
+
resolve(options, config.TOKEN),
|
|
152
|
+
resolve(options, config.USERNAME),
|
|
153
|
+
resolve(options, config.PASSWORD),
|
|
154
|
+
resolve(options, config.HEADERS),
|
|
155
|
+
]);
|
|
156
|
+
|
|
157
|
+
// Filter out undefined/null values from options.headers first
|
|
158
|
+
const optionsHeaders = Object.fromEntries(
|
|
159
|
+
Object.entries(options.headers || {}).filter(([_, value]) => isDefined(value))
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const headers = Object.entries({
|
|
163
|
+
Accept: "application/json",
|
|
164
|
+
...optionsHeaders,
|
|
165
|
+
...additionalHeaders, // config.HEADERS takes precedence when set (for DRT.init())
|
|
166
|
+
})
|
|
167
|
+
.filter(([_, value]) => isDefined(value))
|
|
168
|
+
.reduce(
|
|
169
|
+
(headers, [key, value]) => ({
|
|
170
|
+
...headers,
|
|
171
|
+
[key]: String(value),
|
|
172
|
+
}),
|
|
173
|
+
{} as Record<string, string>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (isStringWithValue(token)) {
|
|
177
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
181
|
+
const credentials = base64(`${username}:${password}`);
|
|
182
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (options.body !== undefined) {
|
|
186
|
+
if (options.mediaType) {
|
|
187
|
+
headers["Content-Type"] = options.mediaType;
|
|
188
|
+
} else if (isBlob(options.body)) {
|
|
189
|
+
headers["Content-Type"] = options.body.type || "application/octet-stream";
|
|
190
|
+
} else if (isString(options.body)) {
|
|
191
|
+
headers["Content-Type"] = "text/plain";
|
|
192
|
+
} else if (!isFormData(options.body)) {
|
|
193
|
+
headers["Content-Type"] = "application/json";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return new Headers(headers);
|
|
180
198
|
};
|
|
181
199
|
|
|
182
200
|
export const getRequestBody = (options: ApiRequestOptions): any => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
if (options.body !== undefined) {
|
|
202
|
+
if (options.mediaType?.includes("/json")) {
|
|
203
|
+
return JSON.stringify(options.body);
|
|
204
|
+
} else if (
|
|
205
|
+
isString(options.body) ||
|
|
206
|
+
isBlob(options.body) ||
|
|
207
|
+
isFormData(options.body)
|
|
208
|
+
) {
|
|
209
|
+
return options.body;
|
|
210
|
+
} else {
|
|
211
|
+
return JSON.stringify(options.body);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
193
215
|
};
|
|
194
216
|
|
|
195
217
|
export const sendRequest = async (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
218
|
+
config: OpenAPIConfig,
|
|
219
|
+
options: ApiRequestOptions,
|
|
220
|
+
url: string,
|
|
221
|
+
body: any,
|
|
222
|
+
formData: FormData | undefined,
|
|
223
|
+
headers: Headers,
|
|
224
|
+
onCancel: OnCancel
|
|
203
225
|
): Promise<Response> => {
|
|
204
|
-
|
|
226
|
+
const controller = new AbortController();
|
|
205
227
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
228
|
+
const request: RequestInit = {
|
|
229
|
+
headers,
|
|
230
|
+
body: body ?? formData,
|
|
231
|
+
method: options.method,
|
|
232
|
+
signal: controller.signal,
|
|
233
|
+
};
|
|
212
234
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
235
|
+
if (config.WITH_CREDENTIALS) {
|
|
236
|
+
request.credentials = config.CREDENTIALS;
|
|
237
|
+
}
|
|
216
238
|
|
|
217
|
-
|
|
239
|
+
onCancel(() => controller.abort());
|
|
218
240
|
|
|
219
|
-
|
|
241
|
+
return await fetch(url, request);
|
|
220
242
|
};
|
|
221
243
|
|
|
222
|
-
export const getResponseHeader = (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
244
|
+
export const getResponseHeader = (
|
|
245
|
+
response: Response,
|
|
246
|
+
responseHeader?: string
|
|
247
|
+
): string | undefined => {
|
|
248
|
+
if (responseHeader) {
|
|
249
|
+
const content = response.headers.get(responseHeader);
|
|
250
|
+
if (isString(content)) {
|
|
251
|
+
return content;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
230
255
|
};
|
|
231
256
|
|
|
232
257
|
export const getResponseBody = async (response: Response): Promise<any> => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
258
|
+
if (response.status !== 204) {
|
|
259
|
+
try {
|
|
260
|
+
const contentType = response.headers.get("Content-Type");
|
|
261
|
+
if (contentType) {
|
|
262
|
+
const jsonTypes = ["application/json", "application/problem+json"];
|
|
263
|
+
const isJSON = jsonTypes.some((type) =>
|
|
264
|
+
contentType.toLowerCase().startsWith(type)
|
|
265
|
+
);
|
|
266
|
+
if (isJSON) {
|
|
267
|
+
return await response.json();
|
|
268
|
+
} else {
|
|
269
|
+
return await response.text();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error(error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return undefined;
|
|
250
277
|
};
|
|
251
278
|
|
|
252
|
-
export const catchErrorCodes = (
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
279
|
+
export const catchErrorCodes = (
|
|
280
|
+
options: ApiRequestOptions,
|
|
281
|
+
result: ApiResult
|
|
282
|
+
): void => {
|
|
283
|
+
const errors: Record<number, string> = {
|
|
284
|
+
400: "Bad Request",
|
|
285
|
+
401: "Unauthorized",
|
|
286
|
+
403: "Forbidden",
|
|
287
|
+
404: "Not Found",
|
|
288
|
+
500: "Internal Server Error",
|
|
289
|
+
502: "Bad Gateway",
|
|
290
|
+
503: "Service Unavailable",
|
|
291
|
+
...options.errors,
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const error = errors[result.status];
|
|
295
|
+
if (error) {
|
|
296
|
+
throw new ApiError(options, result, error);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!result.ok) {
|
|
300
|
+
const errorStatus = result.status ?? "unknown";
|
|
301
|
+
const errorStatusText = result.statusText ?? "unknown";
|
|
302
|
+
const errorBody = (() => {
|
|
303
|
+
try {
|
|
304
|
+
return JSON.stringify(result.body, null, 2);
|
|
305
|
+
} catch (e) {
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
})();
|
|
309
|
+
|
|
310
|
+
throw new ApiError(
|
|
311
|
+
options,
|
|
312
|
+
result,
|
|
313
|
+
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
284
316
|
};
|
|
285
317
|
|
|
318
|
+
let globalCookieHeader: string | undefined;
|
|
319
|
+
|
|
286
320
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* @param options The request options from the service
|
|
290
|
-
* @returns CancelablePromise<T>
|
|
291
|
-
* @throws ApiError
|
|
321
|
+
* Wraps sendRequest to capture cookies on login
|
|
322
|
+
* and attach cookies on other requests
|
|
292
323
|
*/
|
|
293
|
-
export const request = <T>(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
324
|
+
export const request = <T>(
|
|
325
|
+
config: OpenAPIConfig,
|
|
326
|
+
options: ApiRequestOptions
|
|
327
|
+
): CancelablePromise<T> => {
|
|
328
|
+
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
329
|
+
try {
|
|
330
|
+
const url = getUrl(config, options);
|
|
331
|
+
const formData = getFormData(options);
|
|
332
|
+
const body = getRequestBody(options);
|
|
333
|
+
|
|
334
|
+
// Before making headers, possibly attach cookie if we have it
|
|
335
|
+
const baseHeaders = await getHeaders(config, options);
|
|
336
|
+
// We will build combined headers
|
|
337
|
+
const headerObj: Record<string, string> = {};
|
|
338
|
+
baseHeaders.forEach((value, key) => {
|
|
339
|
+
headerObj[key] = value;
|
|
340
|
+
});
|
|
341
|
+
if (globalCookieHeader) {
|
|
342
|
+
// Attach stored cookie
|
|
343
|
+
headerObj["Cookie"] = globalCookieHeader;
|
|
344
|
+
}
|
|
345
|
+
const headers = new Headers(headerObj);
|
|
346
|
+
|
|
347
|
+
if (!onCancel.isCancelled) {
|
|
348
|
+
const response = await sendRequest(
|
|
349
|
+
config,
|
|
350
|
+
options,
|
|
351
|
+
url,
|
|
352
|
+
body,
|
|
353
|
+
formData,
|
|
354
|
+
headers,
|
|
355
|
+
onCancel
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
// Capture Set-Cookie if present
|
|
359
|
+
const setCookie = response.headers.get("set-cookie");
|
|
360
|
+
if (setCookie) {
|
|
361
|
+
// Overwrite or append as needed
|
|
362
|
+
globalCookieHeader = setCookie;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const responseBody = await getResponseBody(response);
|
|
366
|
+
const responseHeader = getResponseHeader(
|
|
367
|
+
response,
|
|
368
|
+
options.responseHeader
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const result: ApiResult = {
|
|
372
|
+
url,
|
|
373
|
+
ok: response.ok,
|
|
374
|
+
status: response.status,
|
|
375
|
+
statusText: response.statusText,
|
|
376
|
+
body: responseHeader ?? responseBody,
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
catchErrorCodes(options, result);
|
|
380
|
+
|
|
381
|
+
resolve(result.body as T);
|
|
382
|
+
}
|
|
383
|
+
} catch (error) {
|
|
384
|
+
reject(error);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
322
387
|
};
|