@ayasofyazilim/saas 0.0.6 → 0.0.8

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 (84) hide show
  1. package/ProjectService/core/ApiError.ts +15 -19
  2. package/ProjectService/core/ApiRequestOptions.ts +12 -16
  3. package/ProjectService/core/ApiResult.ts +7 -11
  4. package/ProjectService/core/CancelablePromise.ts +118 -123
  5. package/ProjectService/core/OpenAPI.ts +48 -24
  6. package/ProjectService/core/request.ts +280 -261
  7. package/ProjectService/index.ts +5 -82
  8. package/ProjectService/schemas.gen.ts +1578 -0
  9. package/ProjectService/services.gen.ts +521 -0
  10. package/ProjectService/types.gen.ts +1356 -0
  11. package/package.json +5 -2
  12. package/swagger.json +4795 -0
  13. package/ProjectService/ProjectServiceClient.ts +0 -46
  14. package/ProjectService/core/BaseHttpRequest.ts +0 -14
  15. package/ProjectService/core/FetchHttpRequest.ts +0 -26
  16. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSectionRelations_CreateProjectSectionRelationDto.ts +0 -11
  17. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSectionRelations_ProjectSectionRelationDto.ts +0 -11
  18. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSectionRelations_UpdateProjectSectionRelationDto.ts +0 -11
  19. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSections_CreateProjectSectionDto.ts +0 -11
  20. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSections_ProjectSectionDetailDto.ts +0 -9
  21. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSections_ProjectSectionDto.ts +0 -11
  22. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectSections_UpdateProjectSectionDto.ts +0 -10
  23. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectsDto_CreateProjectDto.ts +0 -21
  24. package/ProjectService/models/AbpForDeploy_ProjectService_ProjectsDto_UpdateProjectDto.ts +0 -22
  25. package/ProjectService/models/AbpForDeploy_ProjectService_Projects_ProjectDto.ts +0 -23
  26. package/ProjectService/models/AbpForDeploy_ProjectService_Samples_SampleDto.ts +0 -8
  27. package/ProjectService/models/Volo_Abp_Application_Dtos_PagedResultDto_1.ts +0 -10
  28. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationAuthConfigurationDto.ts +0 -8
  29. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationConfigurationDto.ts +0 -30
  30. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationFeatureConfigurationDto.ts +0 -8
  31. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationGlobalFeatureConfigurationDto.ts +0 -8
  32. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationLocalizationConfigurationDto.ts +0 -18
  33. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationLocalizationDto.ts +0 -9
  34. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationLocalizationResourceDto.ts +0 -9
  35. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ApplicationSettingConfigurationDto.ts +0 -8
  36. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ClockDto.ts +0 -8
  37. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_CurrentCultureDto.ts +0 -17
  38. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_CurrentUserDto.ts +0 -22
  39. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_DateTimeFormatDto.ts +0 -14
  40. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_IanaTimeZone.ts +0 -8
  41. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_EntityExtensionDto.ts +0 -10
  42. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionEnumDto.ts +0 -10
  43. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionEnumFieldDto.ts +0 -9
  44. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyApiCreateDto.ts +0 -8
  45. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyApiDto.ts +0 -13
  46. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyApiGetDto.ts +0 -8
  47. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyApiUpdateDto.ts +0 -8
  48. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyAttributeDto.ts +0 -9
  49. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyDto.ts +0 -19
  50. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyUiDto.ts +0 -14
  51. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyUiFormDto.ts +0 -8
  52. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyUiLookupDto.ts +0 -12
  53. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ExtensionPropertyUiTableDto.ts +0 -8
  54. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_LocalizableStringDto.ts +0 -9
  55. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ModuleExtensionDto.ts +0 -10
  56. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_ObjectExtending_ObjectExtensionsDto.ts +0 -11
  57. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_TimeZone.ts +0 -11
  58. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_TimingDto.ts +0 -9
  59. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_ApplicationConfigurations_WindowsTimeZone.ts +0 -8
  60. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_MultiTenancy_CurrentTenantDto.ts +0 -10
  61. package/ProjectService/models/Volo_Abp_AspNetCore_Mvc_MultiTenancy_MultiTenancyInfoDto.ts +0 -8
  62. package/ProjectService/models/Volo_Abp_Http_Modeling_ActionApiDescriptionModel.ts +0 -20
  63. package/ProjectService/models/Volo_Abp_Http_Modeling_ApplicationApiDescriptionModel.ts +0 -11
  64. package/ProjectService/models/Volo_Abp_Http_Modeling_ControllerApiDescriptionModel.ts +0 -17
  65. package/ProjectService/models/Volo_Abp_Http_Modeling_ControllerInterfaceApiDescriptionModel.ts +0 -11
  66. package/ProjectService/models/Volo_Abp_Http_Modeling_InterfaceMethodApiDescriptionModel.ts +0 -12
  67. package/ProjectService/models/Volo_Abp_Http_Modeling_MethodParameterApiDescriptionModel.ts +0 -13
  68. package/ProjectService/models/Volo_Abp_Http_Modeling_ModuleApiDescriptionModel.ts +0 -11
  69. package/ProjectService/models/Volo_Abp_Http_Modeling_ParameterApiDescriptionModel.ts +0 -17
  70. package/ProjectService/models/Volo_Abp_Http_Modeling_PropertyApiDescriptionModel.ts +0 -17
  71. package/ProjectService/models/Volo_Abp_Http_Modeling_ReturnValueApiDescriptionModel.ts +0 -9
  72. package/ProjectService/models/Volo_Abp_Http_Modeling_TypeApiDescriptionModel.ts +0 -14
  73. package/ProjectService/models/Volo_Abp_Http_RemoteServiceErrorInfo.ts +0 -13
  74. package/ProjectService/models/Volo_Abp_Http_RemoteServiceErrorResponse.ts +0 -9
  75. package/ProjectService/models/Volo_Abp_Http_RemoteServiceValidationErrorInfo.ts +0 -9
  76. package/ProjectService/models/Volo_Abp_Localization_LanguageInfo.ts +0 -12
  77. package/ProjectService/models/Volo_Abp_NameValue.ts +0 -9
  78. package/ProjectService/services/AbpApiDefinitionService.ts +0 -34
  79. package/ProjectService/services/AbpApplicationConfigurationService.ts +0 -34
  80. package/ProjectService/services/AbpApplicationLocalizationService.ts +0 -37
  81. package/ProjectService/services/ProjectSectionRelationService.ts +0 -143
  82. package/ProjectService/services/ProjectSectionService.ts +0 -143
  83. package/ProjectService/services/ProjectService.ts +0 -149
  84. package/ProjectService/services/ProjectServiceService.ts +0 -46
@@ -1,7 +1,3 @@
1
- /* generated using openapi-typescript-codegen -- do no edit */
2
- /* istanbul ignore file */
3
- /* tslint:disable */
4
- /* eslint-disable */
5
1
  import { ApiError } from './ApiError';
6
2
  import type { ApiRequestOptions } from './ApiRequestOptions';
7
3
  import type { ApiResult } from './ApiResult';
@@ -9,278 +5,296 @@ import { CancelablePromise } from './CancelablePromise';
9
5
  import type { OnCancel } from './CancelablePromise';
10
6
  import type { OpenAPIConfig } from './OpenAPI';
11
7
 
12
- export const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
13
- return value !== undefined && value !== null;
8
+ export const isString = (value: unknown): value is string => {
9
+ return typeof value === 'string';
14
10
  };
15
11
 
16
- export const isString = (value: any): value is string => {
17
- return typeof value === 'string';
18
- };
19
-
20
- export const isStringWithValue = (value: any): value is string => {
21
- return isString(value) && value !== '';
12
+ export const isStringWithValue = (value: unknown): value is string => {
13
+ return isString(value) && value !== '';
22
14
  };
23
15
 
24
16
  export const isBlob = (value: any): value is Blob => {
25
- return (
26
- typeof value === 'object' &&
27
- typeof value.type === 'string' &&
28
- typeof value.stream === 'function' &&
29
- typeof value.arrayBuffer === 'function' &&
30
- typeof value.constructor === 'function' &&
31
- typeof value.constructor.name === 'string' &&
32
- /^(Blob|File)$/.test(value.constructor.name) &&
33
- /^(Blob|File)$/.test(value[Symbol.toStringTag])
34
- );
17
+ return value instanceof Blob;
35
18
  };
36
19
 
37
- export const isFormData = (value: any): value is FormData => {
38
- return value instanceof FormData;
20
+ export const isFormData = (value: unknown): value is FormData => {
21
+ return value instanceof FormData;
39
22
  };
40
23
 
41
24
  export const base64 = (str: string): string => {
42
- try {
43
- return btoa(str);
44
- } catch (err) {
45
- // @ts-ignore
46
- return Buffer.from(str).toString('base64');
47
- }
25
+ try {
26
+ return btoa(str);
27
+ } catch (err) {
28
+ // @ts-ignore
29
+ return Buffer.from(str).toString('base64');
30
+ }
48
31
  };
49
32
 
50
- export const getQueryString = (params: Record<string, any>): string => {
51
- const qs: string[] = [];
52
-
53
- const append = (key: string, value: any) => {
54
- qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
55
- };
56
-
57
- const process = (key: string, value: any) => {
58
- if (isDefined(value)) {
59
- if (Array.isArray(value)) {
60
- value.forEach(v => {
61
- process(key, v);
62
- });
63
- } else if (typeof value === 'object') {
64
- Object.entries(value).forEach(([k, v]) => {
65
- process(`${key}[${k}]`, v);
66
- });
67
- } else {
68
- append(key, value);
69
- }
70
- }
71
- };
72
-
73
- Object.entries(params).forEach(([key, value]) => {
74
- process(key, value);
75
- });
76
-
77
- if (qs.length > 0) {
78
- return `?${qs.join('&')}`;
79
- }
80
-
81
- return '';
33
+ export const getQueryString = (params: Record<string, unknown>): string => {
34
+ const qs: string[] = [];
35
+
36
+ const append = (key: string, value: unknown) => {
37
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
38
+ };
39
+
40
+ const encodePair = (key: string, value: unknown) => {
41
+ if (value === undefined || value === null) {
42
+ return;
43
+ }
44
+
45
+ if (value instanceof Date) {
46
+ append(key, value.toISOString());
47
+ } else if (Array.isArray(value)) {
48
+ value.forEach(v => encodePair(key, v));
49
+ } else if (typeof value === 'object') {
50
+ Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v));
51
+ } else {
52
+ append(key, value);
53
+ }
54
+ };
55
+
56
+ Object.entries(params).forEach(([key, value]) => encodePair(key, value));
57
+
58
+ return qs.length ? `?${qs.join('&')}` : '';
82
59
  };
83
60
 
84
61
  const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
85
- const encoder = config.ENCODE_PATH || encodeURI;
86
-
87
- const path = options.url
88
- .replace('{api-version}', config.VERSION)
89
- .replace(/{(.*?)}/g, (substring: string, group: string) => {
90
- if (options.path?.hasOwnProperty(group)) {
91
- return encoder(String(options.path[group]));
92
- }
93
- return substring;
94
- });
95
-
96
- const url = `${config.BASE}${path}`;
97
- if (options.query) {
98
- return `${url}${getQueryString(options.query)}`;
99
- }
100
- return url;
62
+ const encoder = config.ENCODE_PATH || encodeURI;
63
+
64
+ const path = options.url
65
+ .replace('{api-version}', config.VERSION)
66
+ .replace(/{(.*?)}/g, (substring: string, group: string) => {
67
+ if (options.path?.hasOwnProperty(group)) {
68
+ return encoder(String(options.path[group]));
69
+ }
70
+ return substring;
71
+ });
72
+
73
+ const url = config.BASE + path;
74
+ return options.query ? url + getQueryString(options.query) : url;
101
75
  };
102
76
 
103
77
  export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
104
- if (options.formData) {
105
- const formData = new FormData();
106
-
107
- const process = (key: string, value: any) => {
108
- if (isString(value) || isBlob(value)) {
109
- formData.append(key, value);
110
- } else {
111
- formData.append(key, JSON.stringify(value));
112
- }
113
- };
114
-
115
- Object.entries(options.formData)
116
- .filter(([_, value]) => isDefined(value))
117
- .forEach(([key, value]) => {
118
- if (Array.isArray(value)) {
119
- value.forEach(v => process(key, v));
120
- } else {
121
- process(key, value);
122
- }
123
- });
124
-
125
- return formData;
126
- }
127
- return undefined;
78
+ if (options.formData) {
79
+ const formData = new FormData();
80
+
81
+ const process = (key: string, value: unknown) => {
82
+ if (isString(value) || isBlob(value)) {
83
+ formData.append(key, value);
84
+ } else {
85
+ formData.append(key, JSON.stringify(value));
86
+ }
87
+ };
88
+
89
+ Object.entries(options.formData)
90
+ .filter(([, value]) => value !== undefined && value !== null)
91
+ .forEach(([key, value]) => {
92
+ if (Array.isArray(value)) {
93
+ value.forEach(v => process(key, v));
94
+ } else {
95
+ process(key, value);
96
+ }
97
+ });
98
+
99
+ return formData;
100
+ }
101
+ return undefined;
128
102
  };
129
103
 
130
104
  type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
131
105
 
132
106
  export const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
133
- if (typeof resolver === 'function') {
134
- return (resolver as Resolver<T>)(options);
135
- }
136
- return resolver;
107
+ if (typeof resolver === 'function') {
108
+ return (resolver as Resolver<T>)(options);
109
+ }
110
+ return resolver;
137
111
  };
138
112
 
139
113
  export const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Promise<Headers> => {
140
- const [token, username, password, additionalHeaders] = await Promise.all([
141
- resolve(options, config.TOKEN),
142
- resolve(options, config.USERNAME),
143
- resolve(options, config.PASSWORD),
144
- resolve(options, config.HEADERS),
145
- ]);
146
-
147
- const headers = Object.entries({
148
- Accept: 'application/json',
149
- ...additionalHeaders,
150
- ...options.headers,
151
- })
152
- .filter(([_, value]) => isDefined(value))
153
- .reduce((headers, [key, value]) => ({
154
- ...headers,
155
- [key]: String(value),
156
- }), {} as Record<string, string>);
157
-
158
- if (isStringWithValue(token)) {
159
- headers['Authorization'] = `Bearer ${token}`;
160
- }
161
-
162
- if (isStringWithValue(username) && isStringWithValue(password)) {
163
- const credentials = base64(`${username}:${password}`);
164
- headers['Authorization'] = `Basic ${credentials}`;
165
- }
166
-
167
- if (options.body) {
168
- if (options.mediaType) {
169
- headers['Content-Type'] = options.mediaType;
170
- } else if (isBlob(options.body)) {
171
- headers['Content-Type'] = options.body.type || 'application/octet-stream';
172
- } else if (isString(options.body)) {
173
- headers['Content-Type'] = 'text/plain';
174
- } else if (!isFormData(options.body)) {
175
- headers['Content-Type'] = 'application/json';
176
- }
177
- }
178
-
179
- return new Headers(headers);
114
+ const [token, username, password, additionalHeaders] = await Promise.all([
115
+ resolve(options, config.TOKEN),
116
+ resolve(options, config.USERNAME),
117
+ resolve(options, config.PASSWORD),
118
+ resolve(options, config.HEADERS),
119
+ ]);
120
+
121
+ const headers = Object.entries({
122
+ Accept: 'application/json',
123
+ ...additionalHeaders,
124
+ ...options.headers,
125
+ })
126
+ .filter(([, value]) => value !== undefined && value !== null)
127
+ .reduce((headers, [key, value]) => ({
128
+ ...headers,
129
+ [key]: String(value),
130
+ }), {} as Record<string, string>);
131
+
132
+ if (isStringWithValue(token)) {
133
+ headers['Authorization'] = `Bearer ${token}`;
134
+ }
135
+
136
+ if (isStringWithValue(username) && isStringWithValue(password)) {
137
+ const credentials = base64(`${username}:${password}`);
138
+ headers['Authorization'] = `Basic ${credentials}`;
139
+ }
140
+
141
+ if (options.body !== undefined) {
142
+ if (options.mediaType) {
143
+ headers['Content-Type'] = options.mediaType;
144
+ } else if (isBlob(options.body)) {
145
+ headers['Content-Type'] = options.body.type || 'application/octet-stream';
146
+ } else if (isString(options.body)) {
147
+ headers['Content-Type'] = 'text/plain';
148
+ } else if (!isFormData(options.body)) {
149
+ headers['Content-Type'] = 'application/json';
150
+ }
151
+ }
152
+
153
+ return new Headers(headers);
180
154
  };
181
155
 
182
- export const getRequestBody = (options: ApiRequestOptions): any => {
183
- if (options.body !== undefined) {
184
- if (options.mediaType?.includes('/json')) {
185
- return JSON.stringify(options.body)
186
- } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
187
- return options.body;
188
- } else {
189
- return JSON.stringify(options.body);
190
- }
191
- }
192
- return undefined;
156
+ export const getRequestBody = (options: ApiRequestOptions): unknown => {
157
+ if (options.body !== undefined) {
158
+ if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
159
+ return JSON.stringify(options.body);
160
+ } else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
161
+ return options.body;
162
+ } else {
163
+ return JSON.stringify(options.body);
164
+ }
165
+ }
166
+ return undefined;
193
167
  };
194
168
 
195
169
  export const sendRequest = async (
196
- config: OpenAPIConfig,
197
- options: ApiRequestOptions,
198
- url: string,
199
- body: any,
200
- formData: FormData | undefined,
201
- headers: Headers,
202
- onCancel: OnCancel
170
+ config: OpenAPIConfig,
171
+ options: ApiRequestOptions,
172
+ url: string,
173
+ body: any,
174
+ formData: FormData | undefined,
175
+ headers: Headers,
176
+ onCancel: OnCancel
203
177
  ): Promise<Response> => {
204
- const controller = new AbortController();
178
+ const controller = new AbortController();
179
+
180
+ let request: RequestInit = {
181
+ headers,
182
+ body: body ?? formData,
183
+ method: options.method,
184
+ signal: controller.signal,
185
+ };
205
186
 
206
- const request: RequestInit = {
207
- headers,
208
- body: body ?? formData,
209
- method: options.method,
210
- signal: controller.signal,
211
- };
187
+ if (config.WITH_CREDENTIALS) {
188
+ request.credentials = config.CREDENTIALS;
189
+ }
212
190
 
213
- if (config.WITH_CREDENTIALS) {
214
- request.credentials = config.CREDENTIALS;
215
- }
191
+ for (const fn of config.interceptors.request._fns) {
192
+ request = await fn(request);
193
+ }
216
194
 
217
- onCancel(() => controller.abort());
195
+ onCancel(() => controller.abort());
218
196
 
219
- return await fetch(url, request);
197
+ return await fetch(url, request);
220
198
  };
221
199
 
222
200
  export const getResponseHeader = (response: Response, responseHeader?: string): string | undefined => {
223
- if (responseHeader) {
224
- const content = response.headers.get(responseHeader);
225
- if (isString(content)) {
226
- return content;
227
- }
228
- }
229
- return undefined;
201
+ if (responseHeader) {
202
+ const content = response.headers.get(responseHeader);
203
+ if (isString(content)) {
204
+ return content;
205
+ }
206
+ }
207
+ return undefined;
230
208
  };
231
209
 
232
- export const getResponseBody = async (response: Response): Promise<any> => {
233
- if (response.status !== 204) {
234
- try {
235
- const contentType = response.headers.get('Content-Type');
236
- if (contentType) {
237
- const jsonTypes = ['application/json', 'application/problem+json']
238
- const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
239
- if (isJSON) {
240
- return await response.json();
241
- } else {
242
- return await response.text();
243
- }
244
- }
245
- } catch (error) {
246
- console.error(error);
247
- }
248
- }
249
- return undefined;
210
+ export const getResponseBody = async (response: Response): Promise<unknown> => {
211
+ if (response.status !== 204) {
212
+ try {
213
+ const contentType = response.headers.get('Content-Type');
214
+ if (contentType) {
215
+ const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
216
+ if (contentType.includes('application/json') || contentType.includes('+json')) {
217
+ return await response.json();
218
+ } else if (binaryTypes.some(type => contentType.includes(type))) {
219
+ return await response.blob();
220
+ } else if (contentType.includes('multipart/form-data')) {
221
+ return await response.formData();
222
+ } else if (contentType.includes('text/')) {
223
+ return await response.text();
224
+ }
225
+ }
226
+ } catch (error) {
227
+ console.error(error);
228
+ }
229
+ }
230
+ return undefined;
250
231
  };
251
232
 
252
233
  export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
253
- const errors: Record<number, string> = {
254
- 400: 'Bad Request',
255
- 401: 'Unauthorized',
256
- 403: 'Forbidden',
257
- 404: 'Not Found',
258
- 500: 'Internal Server Error',
259
- 502: 'Bad Gateway',
260
- 503: 'Service Unavailable',
261
- ...options.errors,
262
- }
263
-
264
- const error = errors[result.status];
265
- if (error) {
266
- throw new ApiError(options, result, error);
267
- }
268
-
269
- if (!result.ok) {
270
- const errorStatus = result.status ?? 'unknown';
271
- const errorStatusText = result.statusText ?? 'unknown';
272
- const errorBody = (() => {
273
- try {
274
- return JSON.stringify(result.body, null, 2);
275
- } catch (e) {
276
- return undefined;
277
- }
278
- })();
279
-
280
- throw new ApiError(options, result,
281
- `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
282
- );
283
- }
234
+ const errors: Record<number, string> = {
235
+ 400: 'Bad Request',
236
+ 401: 'Unauthorized',
237
+ 402: 'Payment Required',
238
+ 403: 'Forbidden',
239
+ 404: 'Not Found',
240
+ 405: 'Method Not Allowed',
241
+ 406: 'Not Acceptable',
242
+ 407: 'Proxy Authentication Required',
243
+ 408: 'Request Timeout',
244
+ 409: 'Conflict',
245
+ 410: 'Gone',
246
+ 411: 'Length Required',
247
+ 412: 'Precondition Failed',
248
+ 413: 'Payload Too Large',
249
+ 414: 'URI Too Long',
250
+ 415: 'Unsupported Media Type',
251
+ 416: 'Range Not Satisfiable',
252
+ 417: 'Expectation Failed',
253
+ 418: 'Im a teapot',
254
+ 421: 'Misdirected Request',
255
+ 422: 'Unprocessable Content',
256
+ 423: 'Locked',
257
+ 424: 'Failed Dependency',
258
+ 425: 'Too Early',
259
+ 426: 'Upgrade Required',
260
+ 428: 'Precondition Required',
261
+ 429: 'Too Many Requests',
262
+ 431: 'Request Header Fields Too Large',
263
+ 451: 'Unavailable For Legal Reasons',
264
+ 500: 'Internal Server Error',
265
+ 501: 'Not Implemented',
266
+ 502: 'Bad Gateway',
267
+ 503: 'Service Unavailable',
268
+ 504: 'Gateway Timeout',
269
+ 505: 'HTTP Version Not Supported',
270
+ 506: 'Variant Also Negotiates',
271
+ 507: 'Insufficient Storage',
272
+ 508: 'Loop Detected',
273
+ 510: 'Not Extended',
274
+ 511: 'Network Authentication Required',
275
+ ...options.errors,
276
+ }
277
+
278
+ const error = errors[result.status];
279
+ if (error) {
280
+ throw new ApiError(options, result, error);
281
+ }
282
+
283
+ if (!result.ok) {
284
+ const errorStatus = result.status ?? 'unknown';
285
+ const errorStatusText = result.statusText ?? 'unknown';
286
+ const errorBody = (() => {
287
+ try {
288
+ return JSON.stringify(result.body, null, 2);
289
+ } catch (e) {
290
+ return undefined;
291
+ }
292
+ })();
293
+
294
+ throw new ApiError(options, result,
295
+ `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
296
+ );
297
+ }
284
298
  };
285
299
 
286
300
  /**
@@ -291,32 +305,37 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
291
305
  * @throws ApiError
292
306
  */
293
307
  export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {
294
- return new CancelablePromise(async (resolve, reject, onCancel) => {
295
- try {
296
- const url = getUrl(config, options);
297
- const formData = getFormData(options);
298
- const body = getRequestBody(options);
299
- const headers = await getHeaders(config, options);
300
-
301
- if (!onCancel.isCancelled) {
302
- const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
303
- const responseBody = await getResponseBody(response);
304
- const responseHeader = getResponseHeader(response, options.responseHeader);
305
-
306
- const result: ApiResult = {
307
- url,
308
- ok: response.ok,
309
- status: response.status,
310
- statusText: response.statusText,
311
- body: responseHeader ?? responseBody,
312
- };
313
-
314
- catchErrorCodes(options, result);
315
-
316
- resolve(result.body);
317
- }
318
- } catch (error) {
319
- reject(error);
320
- }
321
- });
322
- };
308
+ return new CancelablePromise(async (resolve, reject, onCancel) => {
309
+ try {
310
+ const url = getUrl(config, options);
311
+ const formData = getFormData(options);
312
+ const body = getRequestBody(options);
313
+ const headers = await getHeaders(config, options);
314
+
315
+ if (!onCancel.isCancelled) {
316
+ let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
317
+
318
+ for (const fn of config.interceptors.response._fns) {
319
+ response = await fn(response);
320
+ }
321
+
322
+ const responseBody = await getResponseBody(response);
323
+ const responseHeader = getResponseHeader(response, options.responseHeader);
324
+
325
+ const result: ApiResult = {
326
+ url,
327
+ ok: response.ok,
328
+ status: response.status,
329
+ statusText: response.statusText,
330
+ body: responseHeader ?? responseBody,
331
+ };
332
+
333
+ catchErrorCodes(options, result);
334
+
335
+ resolve(result.body);
336
+ }
337
+ } catch (error) {
338
+ reject(error);
339
+ }
340
+ });
341
+ };