@mittwald/api-client-commons 4.500.0 → 4.500.2
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.
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { ApiClientError } from "../core/index.js";
|
|
2
2
|
import assertStatus from "./assertStatus.js";
|
|
3
|
-
import { AxiosHeaders } from "axios";
|
|
4
3
|
const headerName = "x-pagination-totalcount";
|
|
5
4
|
const baseError = `Header '${headerName}' is not valid`;
|
|
5
|
+
/**
|
|
6
|
+
* Duck-typed instead of `instanceof AxiosHeaders`: with two axios copies in a
|
|
7
|
+
* consumer's dependency tree (e.g. their own axios instance passed to
|
|
8
|
+
* `ApiClientBase`), the headers come from the other copy's class and
|
|
9
|
+
* `instanceof` fails.
|
|
10
|
+
*/
|
|
11
|
+
const hasHeaderGetter = (headers) => typeof headers === "object" &&
|
|
12
|
+
headers !== null &&
|
|
13
|
+
typeof headers.get === "function";
|
|
6
14
|
export const extractTotalCountHeader = (response) => {
|
|
7
15
|
assertStatus(response, 200);
|
|
8
|
-
|
|
16
|
+
const headers = response.headers;
|
|
17
|
+
if (!hasHeaderGetter(headers)) {
|
|
9
18
|
throw ApiClientError.fromResponse(`${baseError}: Expected headers to be of type AxiosHeaders`, response);
|
|
10
19
|
}
|
|
11
|
-
const headerContent =
|
|
20
|
+
const headerContent = headers.get(headerName);
|
|
12
21
|
if (typeof headerContent !== "string") {
|
|
13
22
|
throw ApiClientError.fromResponse(`${baseError}: value is not of type string (is ${typeof headerContent} instead)`, response);
|
|
14
23
|
}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OmitIndexSignature, PartialOnUndefinedDeep } from "type-fest";
|
|
2
|
+
/**
|
|
3
|
+
* Deliberately not type-fest's `HasRequiredKeys`: from type-fest 4.39 on, it
|
|
4
|
+
* distributes over unions and reports `false` for primitives such as `string`.
|
|
5
|
+
* That turned required path parameters into optional ones (see
|
|
6
|
+
* `RequestFunction.test-types.ts`). These are the semantics of type-fest 4.30,
|
|
7
|
+
* kept here so that consumers get the same types whatever type-fest version
|
|
8
|
+
* their lockfile resolves.
|
|
9
|
+
*/
|
|
10
|
+
type RequiredKeysOf<T> = Exclude<{
|
|
11
|
+
[TKey in keyof T]: T extends Record<TKey, T[TKey]> ? TKey : never;
|
|
12
|
+
}[keyof T], undefined>;
|
|
13
|
+
type HasRequiredKeys<T> = RequiredKeysOf<T> extends never ? false : true;
|
|
2
14
|
type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{
|
|
3
15
|
[TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined;
|
|
4
16
|
}>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-client-commons",
|
|
3
|
-
"version": "4.500.
|
|
3
|
+
"version": "4.500.2",
|
|
4
4
|
"author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Common types and utilities for mittwald API clients",
|
|
@@ -43,10 +43,7 @@
|
|
|
43
43
|
"test:unit:coverage": "run test:unit --coverage"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"
|
|
47
|
-
"axios": "^1.15.2",
|
|
48
|
-
"parse-path": "^7.1.0",
|
|
49
|
-
"path-to-regexp": "^8.3.0",
|
|
46
|
+
"axios": "^1.20.0",
|
|
50
47
|
"type-fest": "^4.30.0"
|
|
51
48
|
},
|
|
52
49
|
"devDependencies": {
|
|
@@ -82,5 +79,5 @@
|
|
|
82
79
|
"optional": true
|
|
83
80
|
}
|
|
84
81
|
},
|
|
85
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "c76da980b3805476e69e193cc8476a4c03775ae1"
|
|
86
83
|
}
|