@duplicati/ngclient 0.0.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.
- package/.dockerignore +13 -0
- package/.github/workflows/npm-publish.yml +59 -0
- package/.prettierignore +13 -0
- package/.prettierrc +12 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +13 -0
- package/.vscode/settings.json +8 -0
- package/.vscode/tasks.json +24 -0
- package/Dockerfile +38 -0
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/angular.json +98 -0
- package/bun.lockb +0 -0
- package/openapi-ts.config.ts +13 -0
- package/package.json +46 -0
- package/scripts/generate-package-json.ts +15 -0
- package/src/app/about/about.component.html +15 -0
- package/src/app/about/about.component.scss +19 -0
- package/src/app/about/about.component.ts +13 -0
- package/src/app/about/changelog/changelog.component.html +3 -0
- package/src/app/about/changelog/changelog.component.scss +7 -0
- package/src/app/about/changelog/changelog.component.ts +18 -0
- package/src/app/about/general/general.component.html +9 -0
- package/src/app/about/general/general.component.scss +23 -0
- package/src/app/about/general/general.component.ts +30 -0
- package/src/app/about/libraries/libraries.component.html +3 -0
- package/src/app/about/libraries/libraries.component.scss +7 -0
- package/src/app/about/libraries/libraries.component.ts +18 -0
- package/src/app/about/logs/logs.component.html +5 -0
- package/src/app/about/logs/logs.component.scss +7 -0
- package/src/app/about/logs/logs.component.ts +18 -0
- package/src/app/about/system-info/system-info.component.html +3 -0
- package/src/app/about/system-info/system-info.component.scss +7 -0
- package/src/app/about/system-info/system-info.component.ts +17 -0
- package/src/app/add-backup/add-backup.component.html +29 -0
- package/src/app/add-backup/add-backup.component.scss +38 -0
- package/src/app/add-backup/add-backup.component.ts +14 -0
- package/src/app/app.component.ts +35 -0
- package/src/app/app.config.ts +23 -0
- package/src/app/app.routes.ts +121 -0
- package/src/app/core/components/file-tree/file-tree.component.html +87 -0
- package/src/app/core/components/file-tree/file-tree.component.scss +80 -0
- package/src/app/core/components/file-tree/file-tree.component.ts +485 -0
- package/src/app/core/components/logo/logo.component.html +22 -0
- package/src/app/core/components/logo/logo.component.scss +12 -0
- package/src/app/core/components/logo/logo.component.ts +11 -0
- package/src/app/core/components/status-bar/status-bar.component.html +38 -0
- package/src/app/core/components/status-bar/status-bar.component.scss +27 -0
- package/src/app/core/components/status-bar/status-bar.component.ts +33 -0
- package/src/app/core/components/status-bar/status-bar.state.ts +182 -0
- package/src/app/core/components/toggle-card/toggle-card.component.html +11 -0
- package/src/app/core/components/toggle-card/toggle-card.component.scss +49 -0
- package/src/app/core/components/toggle-card/toggle-card.component.ts +28 -0
- package/src/app/core/interceptors/http.interceptor.ts +69 -0
- package/src/app/core/interceptors/websocket.interceptor.ts +66 -0
- package/src/app/core/openapi/core/ApiError.ts +21 -0
- package/src/app/core/openapi/core/ApiRequestOptions.ts +21 -0
- package/src/app/core/openapi/core/ApiResult.ts +7 -0
- package/src/app/core/openapi/core/OpenAPI.ts +55 -0
- package/src/app/core/openapi/core/request.ts +337 -0
- package/src/app/core/openapi/index.ts +6 -0
- package/src/app/core/openapi/schemas.gen.ts +3611 -0
- package/src/app/core/openapi/services.gen.ts +1460 -0
- package/src/app/core/openapi/types.gen.ts +1510 -0
- package/src/app/core/pipes/duration.pipe.ts +27 -0
- package/src/app/core/pipes/relative-time.pipe.ts +14 -0
- package/src/app/core/providers/dayjs.ts +16 -0
- package/src/app/core/services/dict.en.ts +0 -0
- package/src/app/core/services/dictionary.service.ts +12 -0
- package/src/app/core/services/localstorage.token.ts +82 -0
- package/src/app/core/services/password-generator.service.ts +39 -0
- package/src/app/core/services/relay-websocket.service.ts +268 -0
- package/src/app/core/services/timespan-literals.service.ts +25 -0
- package/src/app/core/states/app-auth.state.ts +87 -0
- package/src/app/core/states/backups.state.ts +71 -0
- package/src/app/core/states/relayconfig.state.ts +23 -0
- package/src/app/core/states/sysinfo.state.ts +31 -0
- package/src/app/core/states/tasks.state.ts +34 -0
- package/src/app/core/types/subscribed.ts +7 -0
- package/src/app/core/validators/custom.validators.ts +120 -0
- package/src/app/create-edit-backup/create-edit-backup.component.html +28 -0
- package/src/app/create-edit-backup/create-edit-backup.component.scss +15 -0
- package/src/app/create-edit-backup/create-edit-backup.component.ts +33 -0
- package/src/app/create-edit-backup/create-edit-backup.state.ts +582 -0
- package/src/app/create-edit-backup/destination/destination.component.html +367 -0
- package/src/app/create-edit-backup/destination/destination.component.scss +85 -0
- package/src/app/create-edit-backup/destination/destination.component.ts +249 -0
- package/src/app/create-edit-backup/destination/destination.config.ts +103 -0
- package/src/app/create-edit-backup/destination/destination.mapper.ts +177 -0
- package/src/app/create-edit-backup/general/general.component.html +108 -0
- package/src/app/create-edit-backup/general/general.component.scss +34 -0
- package/src/app/create-edit-backup/general/general.component.ts +136 -0
- package/src/app/create-edit-backup/options/options.component.html +95 -0
- package/src/app/create-edit-backup/options/options.component.scss +42 -0
- package/src/app/create-edit-backup/options/options.component.ts +113 -0
- package/src/app/create-edit-backup/schedule/schedule.component.html +102 -0
- package/src/app/create-edit-backup/schedule/schedule.component.scss +38 -0
- package/src/app/create-edit-backup/schedule/schedule.component.ts +137 -0
- package/src/app/create-edit-backup/source-data/source-data.component.html +93 -0
- package/src/app/create-edit-backup/source-data/source-data.component.scss +41 -0
- package/src/app/create-edit-backup/source-data/source-data.component.ts +114 -0
- package/src/app/home/backup.const.ts +167 -0
- package/src/app/home/home.component.html +98 -0
- package/src/app/home/home.component.scss +88 -0
- package/src/app/home/home.component.ts +54 -0
- package/src/app/layout/layout.component.html +64 -0
- package/src/app/layout/layout.component.scss +24 -0
- package/src/app/layout/layout.component.ts +51 -0
- package/src/app/layout/layout.state.ts +70 -0
- package/src/app/login/login.component.html +12 -0
- package/src/app/login/login.component.scss +25 -0
- package/src/app/login/login.component.ts +34 -0
- package/src/app/logout/logout.component.html +1 -0
- package/src/app/logout/logout.component.scss +3 -0
- package/src/app/logout/logout.component.ts +18 -0
- package/src/app/restore/restore.component.html +56 -0
- package/src/app/restore/restore.component.scss +37 -0
- package/src/app/restore/restore.component.ts +55 -0
- package/src/app/restore-flow/options/options.component.html +57 -0
- package/src/app/restore-flow/options/options.component.scss +16 -0
- package/src/app/restore-flow/options/options.component.ts +58 -0
- package/src/app/restore-flow/restore-flow.component.html +14 -0
- package/src/app/restore-flow/restore-flow.component.scss +15 -0
- package/src/app/restore-flow/restore-flow.component.ts +23 -0
- package/src/app/restore-flow/restore-flow.state.ts +120 -0
- package/src/app/restore-flow/select-files/select-files.component.html +42 -0
- package/src/app/restore-flow/select-files/select-files.component.scss +16 -0
- package/src/app/restore-flow/select-files/select-files.component.ts +129 -0
- package/src/app/settings/settings.component.html +256 -0
- package/src/app/settings/settings.component.scss +106 -0
- package/src/app/settings/settings.component.ts +475 -0
- package/src/assets/duplicati-logo.png +0 -0
- package/src/assets/duplicati-logo.svg +10 -0
- package/src/assets/favicon.ico +0 -0
- package/src/assets/images/backup.png +0 -0
- package/src/assets/images/dark-theme.png +0 -0
- package/src/assets/images/folder.png +0 -0
- package/src/assets/images/light-theme.png +0 -0
- package/src/assets/images/new-backup.png +0 -0
- package/src/assets/images/restore.png +0 -0
- package/src/assets/images/system-theme.png +0 -0
- package/src/assets/spk.css +33 -0
- package/src/assets/spk.woff2 +0 -0
- package/src/environments/environment-token.ts +4 -0
- package/src/environments/environment.prod.ts +6 -0
- package/src/environments/environment.ts +6 -0
- package/src/index.html +15 -0
- package/src/main.ts +6 -0
- package/src/proxy.conf.mjs +6 -0
- package/src/styles.scss +41 -0
- package/tsconfig.app.json +15 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
2
|
+
import type { HttpResponse, HttpErrorResponse } from '@angular/common/http';
|
|
3
|
+
import { forkJoin, of, throwError } from 'rxjs';
|
|
4
|
+
import { catchError, map, switchMap } from 'rxjs/operators';
|
|
5
|
+
import type { Observable } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
import { ApiError } from './ApiError';
|
|
8
|
+
import type { ApiRequestOptions } from './ApiRequestOptions';
|
|
9
|
+
import type { ApiResult } from './ApiResult';
|
|
10
|
+
import type { OpenAPIConfig } from './OpenAPI';
|
|
11
|
+
|
|
12
|
+
export const isString = (value: unknown): value is string => {
|
|
13
|
+
return typeof value === 'string';
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const isStringWithValue = (value: unknown): value is string => {
|
|
17
|
+
return isString(value) && value !== '';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isBlob = (value: any): value is Blob => {
|
|
21
|
+
return value instanceof Blob;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const isFormData = (value: unknown): value is FormData => {
|
|
25
|
+
return value instanceof FormData;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const base64 = (str: string): string => {
|
|
29
|
+
try {
|
|
30
|
+
return btoa(str);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
return Buffer.from(str).toString('base64');
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getQueryString = (params: Record<string, unknown>): string => {
|
|
38
|
+
const qs: string[] = [];
|
|
39
|
+
|
|
40
|
+
const append = (key: string, value: unknown) => {
|
|
41
|
+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const encodePair = (key: string, value: unknown) => {
|
|
45
|
+
if (value === undefined || value === null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (value instanceof Date) {
|
|
50
|
+
append(key, value.toISOString());
|
|
51
|
+
} else if (Array.isArray(value)) {
|
|
52
|
+
value.forEach(v => encodePair(key, v));
|
|
53
|
+
} else if (typeof value === 'object') {
|
|
54
|
+
Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v));
|
|
55
|
+
} else {
|
|
56
|
+
append(key, value);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Object.entries(params).forEach(([key, value]) => encodePair(key, value));
|
|
61
|
+
|
|
62
|
+
return qs.length ? `?${qs.join('&')}` : '';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
|
66
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
67
|
+
|
|
68
|
+
const path = options.url
|
|
69
|
+
.replace('{api-version}', config.VERSION)
|
|
70
|
+
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
|
71
|
+
if (options.path?.hasOwnProperty(group)) {
|
|
72
|
+
return encoder(String(options.path[group]));
|
|
73
|
+
}
|
|
74
|
+
return substring;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const url = config.BASE + path;
|
|
78
|
+
return options.query ? url + getQueryString(options.query) : url;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const getFormData = (options: ApiRequestOptions): FormData | undefined => {
|
|
82
|
+
if (options.formData) {
|
|
83
|
+
const formData = new FormData();
|
|
84
|
+
|
|
85
|
+
const process = (key: string, value: unknown) => {
|
|
86
|
+
if (isString(value) || isBlob(value)) {
|
|
87
|
+
formData.append(key, value);
|
|
88
|
+
} else {
|
|
89
|
+
formData.append(key, JSON.stringify(value));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
Object.entries(options.formData)
|
|
94
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
95
|
+
.forEach(([key, value]) => {
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
value.forEach(v => process(key, v));
|
|
98
|
+
} else {
|
|
99
|
+
process(key, value);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return formData;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
|
|
109
|
+
|
|
110
|
+
export const resolve = async <T>(options: ApiRequestOptions<T>, resolver?: T | Resolver<T>): Promise<T | undefined> => {
|
|
111
|
+
if (typeof resolver === 'function') {
|
|
112
|
+
return (resolver as Resolver<T>)(options);
|
|
113
|
+
}
|
|
114
|
+
return resolver;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const getHeaders = <T>(config: OpenAPIConfig, options: ApiRequestOptions<T>): Observable<HttpHeaders> => {
|
|
118
|
+
return forkJoin({
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
token: resolve(options, config.TOKEN),
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
username: resolve(options, config.USERNAME),
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
password: resolve(options, config.PASSWORD),
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
additionalHeaders: resolve(options, config.HEADERS),
|
|
127
|
+
}).pipe(
|
|
128
|
+
map(({ token, username, password, additionalHeaders }) => {
|
|
129
|
+
const headers = Object.entries({
|
|
130
|
+
Accept: 'application/json',
|
|
131
|
+
...additionalHeaders,
|
|
132
|
+
...options.headers,
|
|
133
|
+
})
|
|
134
|
+
.filter(([, value]) => value !== undefined && value !== null)
|
|
135
|
+
.reduce((headers, [key, value]) => ({
|
|
136
|
+
...headers,
|
|
137
|
+
[key]: String(value),
|
|
138
|
+
}), {} as Record<string, string>);
|
|
139
|
+
|
|
140
|
+
if (isStringWithValue(token)) {
|
|
141
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
145
|
+
const credentials = base64(`${username}:${password}`);
|
|
146
|
+
headers['Authorization'] = `Basic ${credentials}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (options.body !== undefined) {
|
|
150
|
+
if (options.mediaType) {
|
|
151
|
+
headers['Content-Type'] = options.mediaType;
|
|
152
|
+
} else if (isBlob(options.body)) {
|
|
153
|
+
headers['Content-Type'] = options.body.type || 'application/octet-stream';
|
|
154
|
+
} else if (isString(options.body)) {
|
|
155
|
+
headers['Content-Type'] = 'text/plain';
|
|
156
|
+
} else if (!isFormData(options.body)) {
|
|
157
|
+
headers['Content-Type'] = 'application/json';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return new HttpHeaders(headers);
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
167
|
+
if (options.body) {
|
|
168
|
+
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
|
|
169
|
+
return JSON.stringify(options.body);
|
|
170
|
+
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
|
|
171
|
+
return options.body;
|
|
172
|
+
} else {
|
|
173
|
+
return JSON.stringify(options.body);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const sendRequest = <T>(
|
|
180
|
+
config: OpenAPIConfig,
|
|
181
|
+
options: ApiRequestOptions<T>,
|
|
182
|
+
http: HttpClient,
|
|
183
|
+
url: string,
|
|
184
|
+
body: unknown,
|
|
185
|
+
formData: FormData | undefined,
|
|
186
|
+
headers: HttpHeaders
|
|
187
|
+
): Observable<HttpResponse<T>> => {
|
|
188
|
+
return http.request<T>(options.method, url, {
|
|
189
|
+
headers,
|
|
190
|
+
body: body ?? formData,
|
|
191
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
192
|
+
observe: 'response',
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export const getResponseHeader = <T>(response: HttpResponse<T>, responseHeader?: string): string | undefined => {
|
|
197
|
+
if (responseHeader) {
|
|
198
|
+
const value = response.headers.get(responseHeader);
|
|
199
|
+
if (isString(value)) {
|
|
200
|
+
return value;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export const getResponseBody = <T>(response: HttpResponse<T>): T | undefined => {
|
|
207
|
+
if (response.status !== 204 && response.body !== null) {
|
|
208
|
+
return response.body;
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
|
|
214
|
+
const errors: Record<number, string> = {
|
|
215
|
+
400: 'Bad Request',
|
|
216
|
+
401: 'Unauthorized',
|
|
217
|
+
402: 'Payment Required',
|
|
218
|
+
403: 'Forbidden',
|
|
219
|
+
404: 'Not Found',
|
|
220
|
+
405: 'Method Not Allowed',
|
|
221
|
+
406: 'Not Acceptable',
|
|
222
|
+
407: 'Proxy Authentication Required',
|
|
223
|
+
408: 'Request Timeout',
|
|
224
|
+
409: 'Conflict',
|
|
225
|
+
410: 'Gone',
|
|
226
|
+
411: 'Length Required',
|
|
227
|
+
412: 'Precondition Failed',
|
|
228
|
+
413: 'Payload Too Large',
|
|
229
|
+
414: 'URI Too Long',
|
|
230
|
+
415: 'Unsupported Media Type',
|
|
231
|
+
416: 'Range Not Satisfiable',
|
|
232
|
+
417: 'Expectation Failed',
|
|
233
|
+
418: 'Im a teapot',
|
|
234
|
+
421: 'Misdirected Request',
|
|
235
|
+
422: 'Unprocessable Content',
|
|
236
|
+
423: 'Locked',
|
|
237
|
+
424: 'Failed Dependency',
|
|
238
|
+
425: 'Too Early',
|
|
239
|
+
426: 'Upgrade Required',
|
|
240
|
+
428: 'Precondition Required',
|
|
241
|
+
429: 'Too Many Requests',
|
|
242
|
+
431: 'Request Header Fields Too Large',
|
|
243
|
+
451: 'Unavailable For Legal Reasons',
|
|
244
|
+
500: 'Internal Server Error',
|
|
245
|
+
501: 'Not Implemented',
|
|
246
|
+
502: 'Bad Gateway',
|
|
247
|
+
503: 'Service Unavailable',
|
|
248
|
+
504: 'Gateway Timeout',
|
|
249
|
+
505: 'HTTP Version Not Supported',
|
|
250
|
+
506: 'Variant Also Negotiates',
|
|
251
|
+
507: 'Insufficient Storage',
|
|
252
|
+
508: 'Loop Detected',
|
|
253
|
+
510: 'Not Extended',
|
|
254
|
+
511: 'Network Authentication Required',
|
|
255
|
+
...options.errors,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const error = errors[result.status];
|
|
259
|
+
if (error) {
|
|
260
|
+
throw new ApiError(options, result, error);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!result.ok) {
|
|
264
|
+
const errorStatus = result.status ?? 'unknown';
|
|
265
|
+
const errorStatusText = result.statusText ?? 'unknown';
|
|
266
|
+
const errorBody = (() => {
|
|
267
|
+
try {
|
|
268
|
+
return JSON.stringify(result.body, null, 2);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
})();
|
|
273
|
+
|
|
274
|
+
throw new ApiError(options, result,
|
|
275
|
+
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Request method
|
|
282
|
+
* @param config The OpenAPI configuration object
|
|
283
|
+
* @param http The Angular HTTP client
|
|
284
|
+
* @param options The request options from the service
|
|
285
|
+
* @returns Observable<T>
|
|
286
|
+
* @throws ApiError
|
|
287
|
+
*/
|
|
288
|
+
export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: ApiRequestOptions<T>): Observable<T> => {
|
|
289
|
+
const url = getUrl(config, options);
|
|
290
|
+
const formData = getFormData(options);
|
|
291
|
+
const body = getRequestBody(options);
|
|
292
|
+
|
|
293
|
+
return getHeaders(config, options).pipe(
|
|
294
|
+
switchMap(headers => {
|
|
295
|
+
return sendRequest<T>(config, options, http, url, body, formData, headers);
|
|
296
|
+
}),
|
|
297
|
+
switchMap(async response => {
|
|
298
|
+
for (const fn of config.interceptors.response._fns) {
|
|
299
|
+
response = await fn(response);
|
|
300
|
+
}
|
|
301
|
+
const responseBody = getResponseBody(response);
|
|
302
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
303
|
+
|
|
304
|
+
let transformedBody = responseBody;
|
|
305
|
+
if (options.responseTransformer && response.ok) {
|
|
306
|
+
transformedBody = await options.responseTransformer(responseBody)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
url,
|
|
311
|
+
ok: response.ok,
|
|
312
|
+
status: response.status,
|
|
313
|
+
statusText: response.statusText,
|
|
314
|
+
body: responseHeader ?? transformedBody,
|
|
315
|
+
} as ApiResult;
|
|
316
|
+
}),
|
|
317
|
+
catchError((error: HttpErrorResponse) => {
|
|
318
|
+
if (!error.status) {
|
|
319
|
+
return throwError(() => error);
|
|
320
|
+
}
|
|
321
|
+
return of({
|
|
322
|
+
url,
|
|
323
|
+
ok: error.ok,
|
|
324
|
+
status: error.status,
|
|
325
|
+
statusText: error.statusText,
|
|
326
|
+
body: error.error ?? error.statusText,
|
|
327
|
+
} as ApiResult);
|
|
328
|
+
}),
|
|
329
|
+
map(result => {
|
|
330
|
+
catchErrorCodes(options, result);
|
|
331
|
+
return result.body as T;
|
|
332
|
+
}),
|
|
333
|
+
catchError((error: ApiError) => {
|
|
334
|
+
return throwError(() => error);
|
|
335
|
+
}),
|
|
336
|
+
);
|
|
337
|
+
};
|