decap-cms-lib-util 3.7.1 → 3.8.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/dist/esm/backendUtil.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import flow from 'lodash/flow';
|
|
2
2
|
import fromPairs from 'lodash/fromPairs';
|
|
3
3
|
import { map } from 'lodash/fp';
|
|
4
|
-
import {
|
|
4
|
+
import { Map as ImmutableMap } from 'immutable';
|
|
5
5
|
import unsentRequest from './unsentRequest';
|
|
6
6
|
import APIError from './APIError';
|
|
7
|
+
|
|
8
|
+
// A formatter yields a string, a Blob or parsed JSON depending on the requested
|
|
9
|
+
// format, so its result is only known at the call site - hence `any`. Callers
|
|
10
|
+
// narrow it themselves (e.g. `.then<Blob | string>(...)`).
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
|
|
7
13
|
export function filterByExtension(file, extension) {
|
|
8
14
|
const path = file?.path || '';
|
|
9
15
|
return path.endsWith(extension.startsWith('.') ? extension : `.${extension}`);
|
|
@@ -17,7 +23,10 @@ function catchFormatErrors(format, formatter) {
|
|
|
17
23
|
}
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
|
|
27
|
+
// NOTE: `Map` rather than `fromJS` on purpose - the values are functions, which
|
|
28
|
+
// `fromJS` would leave untouched anyway, and `Map` keeps them properly typed.
|
|
29
|
+
const responseFormatters = ImmutableMap({
|
|
21
30
|
json: async res => {
|
|
22
31
|
const contentType = res.headers.get('Content-Type') || '';
|
|
23
32
|
if (!contentType.startsWith('application/json') && !contentType.startsWith('text/json')) {
|
|
@@ -31,6 +31,29 @@ function fetchWithTimeout(input, init) {
|
|
|
31
31
|
function decodeParams(paramsString) {
|
|
32
32
|
return List(paramsString.split('&')).map(s => List(s.split('=')).map(decodeURIComponent)).update(Map);
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
// Only `params` and `headers` are ever traversed as collections by the helpers
|
|
36
|
+
// below; every other value of a request is passed straight through to `fetch`.
|
|
37
|
+
const NESTED_REQUEST_KEYS = ['params', 'headers'];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Turns a request-like object into a Map, converting only the keys the request
|
|
41
|
+
* helpers actually operate on.
|
|
42
|
+
*
|
|
43
|
+
* NOTE: this cannot be `fromJS`. immutable 4 recurses into any iterable, not
|
|
44
|
+
* just plain objects and arrays, so a `FormData` or `URLSearchParams` body
|
|
45
|
+
* would be turned into a collection and the `toJS()` in `toFetchArguments`
|
|
46
|
+
* would then hand `fetch` a plain object instead of the original body.
|
|
47
|
+
*/
|
|
48
|
+
function toRequestMap(req) {
|
|
49
|
+
return Map(req).withMutations(map => {
|
|
50
|
+
NESTED_REQUEST_KEYS.forEach(key => {
|
|
51
|
+
if (map.has(key)) {
|
|
52
|
+
map.set(key, fromJS(map.get(key)));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
34
57
|
function fromURL(wholeURL) {
|
|
35
58
|
const [url, allParamsString] = wholeURL.split('?');
|
|
36
59
|
return Map({
|
|
@@ -41,7 +64,7 @@ function fromURL(wholeURL) {
|
|
|
41
64
|
});
|
|
42
65
|
}
|
|
43
66
|
function fromFetchArguments(wholeURL, options) {
|
|
44
|
-
return fromURL(wholeURL).merge((options ?
|
|
67
|
+
return fromURL(wholeURL).merge((options ? toRequestMap(options) : Map()).remove('url').remove('params'));
|
|
45
68
|
}
|
|
46
69
|
function encodeParams(params) {
|
|
47
70
|
return params.entrySeq().map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
|
|
@@ -57,7 +80,7 @@ function maybeRequestArg(req) {
|
|
|
57
80
|
return fromURL(req);
|
|
58
81
|
}
|
|
59
82
|
if (req) {
|
|
60
|
-
return
|
|
83
|
+
return toRequestMap(req);
|
|
61
84
|
}
|
|
62
85
|
return Map();
|
|
63
86
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-lib-util",
|
|
3
3
|
"description": "Shared utilities for Decap CMS.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.8.1",
|
|
5
5
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-lib-util",
|
|
6
6
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
7
7
|
"module": "dist/esm/index.js",
|
|
@@ -15,21 +15,22 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"scripts": {
|
|
18
|
-
"develop": "
|
|
18
|
+
"develop": "pnpm run build:esm --watch",
|
|
19
19
|
"build": "cross-env NODE_ENV=production webpack",
|
|
20
20
|
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore \"**/__tests__\" --root-mode upward --extensions \".js,.jsx,.ts,.tsx\""
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"js-sha256": "
|
|
24
|
-
"localforage": "
|
|
25
|
-
"semaphore": "
|
|
23
|
+
"js-sha256": "catalog:",
|
|
24
|
+
"localforage": "catalog:",
|
|
25
|
+
"semaphore": "catalog:"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"common-tags": "catalog:",
|
|
29
|
+
"immutable": "catalog:",
|
|
30
|
+
"lodash": "catalog:"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"common-tags": "
|
|
33
|
+
"common-tags": "catalog:"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "570c3e7fbc399c455729964b9b5fdec079846393"
|
|
35
36
|
}
|