@wordpress/api-fetch 5.2.2 → 5.2.6
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/CHANGELOG.md +6 -0
- package/README.md +10 -10
- package/build/middlewares/fetch-all-middleware.js +11 -8
- package/build/middlewares/fetch-all-middleware.js.map +1 -1
- package/build/middlewares/media-upload.js +12 -3
- package/build/middlewares/media-upload.js.map +1 -1
- package/build/middlewares/preloading.js +22 -31
- package/build/middlewares/preloading.js.map +1 -1
- package/build/types.js +4 -0
- package/build/utils/response.js +8 -3
- package/build/utils/response.js.map +1 -1
- package/build-module/middlewares/fetch-all-middleware.js +11 -8
- package/build-module/middlewares/fetch-all-middleware.js.map +1 -1
- package/build-module/middlewares/media-upload.js +12 -3
- package/build-module/middlewares/media-upload.js.map +1 -1
- package/build-module/middlewares/preloading.js +21 -29
- package/build-module/middlewares/preloading.js.map +1 -1
- package/build-module/types.js +1 -1
- package/build-module/utils/response.js +8 -3
- package/build-module/utils/response.js.map +1 -1
- package/build-types/middlewares/media-upload.d.ts.map +1 -1
- package/build-types/middlewares/preloading.d.ts +0 -10
- package/build-types/middlewares/preloading.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/middlewares/media-upload.js +15 -5
- package/src/middlewares/preloading.js +20 -41
- package/src/middlewares/test/media-upload.js +35 -0
- package/src/middlewares/test/preloading.js +29 -24
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 5.2.5 (2021-11-07)
|
|
6
|
+
|
|
7
|
+
### Internal
|
|
8
|
+
|
|
9
|
+
- Removed `getStablePath` function. Please use `normalizePath` from `@wordpress/url` package instead ([#35992](https://github.com/WordPress/gutenberg/pull/35992)).``
|
|
10
|
+
|
|
5
11
|
## 5.2.0 (2021-07-21)
|
|
6
12
|
|
|
7
13
|
### New feature
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Install the module
|
|
|
10
10
|
npm install @wordpress/api-fetch --save
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for
|
|
13
|
+
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
@@ -56,28 +56,28 @@ Shorthand to be used in place of `body`, accepts an object value to be stringifi
|
|
|
56
56
|
|
|
57
57
|
### Aborting a request
|
|
58
58
|
|
|
59
|
-
Aborting a request can be achieved through the use of [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) in the same way as you would when using the native `fetch` API.
|
|
59
|
+
Aborting a request can be achieved through the use of [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) in the same way as you would when using the native `fetch` API.
|
|
60
60
|
|
|
61
61
|
For legacy browsers that don't support `AbortController`, you can either:
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
- Provide your own polyfill of `AbortController` if you still want it to be abortable.
|
|
64
|
+
- Ignore it as shown in the example below.
|
|
65
65
|
|
|
66
66
|
**Example**
|
|
67
67
|
|
|
68
68
|
```js
|
|
69
|
-
const controller =
|
|
70
|
-
? undefined
|
|
71
|
-
: new AbortController();
|
|
69
|
+
const controller =
|
|
70
|
+
typeof AbortController === 'undefined' ? undefined : new AbortController();
|
|
72
71
|
|
|
73
|
-
apiFetch( { path: '/wp/v2/posts', signal: controller?.signal } )
|
|
74
|
-
|
|
72
|
+
apiFetch( { path: '/wp/v2/posts', signal: controller?.signal } ).catch(
|
|
73
|
+
( error ) => {
|
|
75
74
|
// If the browser doesn't support AbortController then the code below will never log.
|
|
76
75
|
// However, in most cases this should be fine as it can be considered to be a progressive enhancement.
|
|
77
76
|
if ( error.name === 'AbortError' ) {
|
|
78
77
|
console.log( 'Request has been aborted' );
|
|
79
78
|
}
|
|
80
|
-
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
81
|
|
|
82
82
|
controller?.abort();
|
|
83
83
|
```
|
|
@@ -26,14 +26,17 @@ var _ = _interopRequireDefault(require(".."));
|
|
|
26
26
|
* @param {Record<string, string | number>} queryArgs
|
|
27
27
|
* @return {import('../types').APIFetchOptions} The request with the modified query args
|
|
28
28
|
*/
|
|
29
|
-
const modifyQuery = ({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const modifyQuery = (_ref, queryArgs) => {
|
|
30
|
+
let {
|
|
31
|
+
path,
|
|
32
|
+
url,
|
|
33
|
+
...options
|
|
34
|
+
} = _ref;
|
|
35
|
+
return { ...options,
|
|
36
|
+
url: url && (0, _url.addQueryArgs)(url, queryArgs),
|
|
37
|
+
path: path && (0, _url.addQueryArgs)(path, queryArgs)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
37
40
|
/**
|
|
38
41
|
* Duplicates parsing functionality from apiFetch.
|
|
39
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["modifyQuery","path","url","options","
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["modifyQuery","queryArgs","path","url","options","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA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AM3B,aAAa,CAAEyB,YAAF,CAAvC;AACAF,IAAAA,aAAa,GAAGA,aAAa,CAACC,MAAd,CAAsBG,WAAtB,CAAhB;AACAL,IAAAA,QAAQ,GAAGb,cAAc,CAAEgB,YAAF,CAAzB;AACA;;AACD,SAAOF,aAAP;AACA,CAjDD;;eAmDeP,kB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}
|
|
@@ -17,15 +17,24 @@ var _response = require("../utils/response");
|
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @param {import('../types').APIFetchOptions} options
|
|
22
|
+
* @return {boolean} True if the request is for media upload.
|
|
23
|
+
*/
|
|
24
|
+
function isMediaUploadRequest(options) {
|
|
25
|
+
const isCreateMethod = !!options.method && options.method === 'POST';
|
|
26
|
+
const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
27
|
+
return isMediaEndpoint && isCreateMethod;
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* Middleware handling media upload failures and retries.
|
|
22
31
|
*
|
|
23
32
|
* @type {import('../types').APIFetchMiddleware}
|
|
24
33
|
*/
|
|
25
|
-
const mediaUploadMiddleware = (options, next) => {
|
|
26
|
-
const isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
|
|
36
|
+
const mediaUploadMiddleware = (options, next) => {
|
|
37
|
+
if (!isMediaUploadRequest(options)) {
|
|
29
38
|
return next(options);
|
|
30
39
|
}
|
|
31
40
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/media-upload.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/media-upload.js"],"names":["isMediaUploadRequest","options","isCreateMethod","method","isMediaEndpoint","path","indexOf","url","mediaUploadMiddleware","next","retries","maxRetries","postProcess","attachmentId","data","action","parse","catch","Promise","reject","response","headers","get","status","code","message","then"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA,SAASA,oBAAT,CAA+BC,OAA/B,EAAyC;AACxC,QAAMC,cAAc,GAAG,CAAC,CAAED,OAAO,CAACE,MAAX,IAAqBF,OAAO,CAACE,MAAR,KAAmB,MAA/D;AACA,QAAMC,eAAe,GAClB,CAAC,CAAEH,O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O,QAAQ,CAACC,OAAT,CAAiBC,GAAjB,CACpB,2BADoB,CAArB;;AAGA,QACCF,QAAQ,CAACG,MAAT,IAAmB,GAAnB,IACAH,QAAQ,CAACG,MAAT,GAAkB,GADlB,IAEAV,YAHD,EAIE;AACD,aAAOD,WAAW,CAAEC,YAAF,CAAX,CAA4BI,KAA5B,CAAmC,MAAM;AAC/C,YAAKhB,OAAO,CAACe,KAAR,KAAkB,KAAvB,EAA+B;AAC9B,iBAAOE,OAAO,CAACC,MAAR,CAAgB;AACtBK,YAAAA,IAAI,EAAE,cADgB;AAEtBC,YAAAA,OAAO,EAAE,cACR,+FADQ;AAFa,WAAhB,CAAP;AAMA;;AAED,eAAOP,OAAO,CAACC,MAAR,CAAgBC,QAAhB,CAAP;AACA,OAXM,CAAP;AAYA;;AACD,WAAO,kCAAoBA,QAApB,EAA8BnB,OAAO,CAACe,KAAtC,CAAP;AACA,GAxBK,EAyBLU,IAzBK,CAyBGN,QAAF,IACN,8CAAgCA,QAAhC,EAA0CnB,OAAO,CAACe,KAAlD,CA1BK,CAAP;AA4BA,CA5DD;;eA8DeR,qB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tparseAndThrowError,\n\tparseResponseAndNormalizeError,\n} from '../utils/response';\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request is for media upload.\n */\nfunction isMediaUploadRequest( options ) {\n\tconst isCreateMethod = !! options.method && options.method === 'POST';\n\tconst isMediaEndpoint =\n\t\t( !! options.path && options.path.indexOf( '/wp/v2/media' ) !== -1 ) ||\n\t\t( !! options.url && options.url.indexOf( '/wp/v2/media' ) !== -1 );\n\n\treturn isMediaEndpoint && isCreateMethod;\n}\n\n/**\n * Middleware handling media upload failures and retries.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst mediaUploadMiddleware = ( options, next ) => {\n\tif ( ! isMediaUploadRequest( options ) ) {\n\t\treturn next( options );\n\t}\n\n\tlet retries = 0;\n\tconst maxRetries = 5;\n\n\t/**\n\t * @param {string} attachmentId\n\t * @return {Promise<any>} Processed post response.\n\t */\n\tconst postProcess = ( attachmentId ) => {\n\t\tretries++;\n\t\treturn next( {\n\t\t\tpath: `/wp/v2/media/${ attachmentId }/post-process`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { action: 'create-image-subsizes' },\n\t\t\tparse: false,\n\t\t} ).catch( () => {\n\t\t\tif ( retries < maxRetries ) {\n\t\t\t\treturn postProcess( attachmentId );\n\t\t\t}\n\t\t\tnext( {\n\t\t\t\tpath: `/wp/v2/media/${ attachmentId }?force=true`,\n\t\t\t\tmethod: 'DELETE',\n\t\t\t} );\n\n\t\t\treturn Promise.reject();\n\t\t} );\n\t};\n\n\treturn next( { ...options, parse: false } )\n\t\t.catch( ( response ) => {\n\t\t\tconst attachmentId = response.headers.get(\n\t\t\t\t'x-wp-upload-attachment-id'\n\t\t\t);\n\t\t\tif (\n\t\t\t\tresponse.status >= 500 &&\n\t\t\t\tresponse.status < 600 &&\n\t\t\t\tattachmentId\n\t\t\t) {\n\t\t\t\treturn postProcess( attachmentId ).catch( () => {\n\t\t\t\t\tif ( options.parse !== false ) {\n\t\t\t\t\t\treturn Promise.reject( {\n\t\t\t\t\t\t\tcode: 'post_process',\n\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t'Media upload failed. If this is a photo or a large image, please scale it down and try again.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Promise.reject( response );\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn parseAndThrowError( response, options.parse );\n\t\t} )\n\t\t.then( ( response ) =>\n\t\t\tparseResponseAndNormalizeError( response, options.parse )\n\t\t);\n};\n\nexport default mediaUploadMiddleware;\n"]}
|
|
@@ -3,44 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getStablePath = getStablePath;
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
|
|
8
|
+
var _url = require("@wordpress/url");
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
* will be treated as identical, regardless of order they appear in the original
|
|
12
|
-
* text.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} path Original path.
|
|
15
|
-
*
|
|
16
|
-
* @return {string} Normalized path.
|
|
11
|
+
* WordPress dependencies
|
|
17
12
|
*/
|
|
18
|
-
function getStablePath(path) {
|
|
19
|
-
const splitted = path.split('?');
|
|
20
|
-
const query = splitted[1];
|
|
21
|
-
const base = splitted[0];
|
|
22
|
-
|
|
23
|
-
if (!query) {
|
|
24
|
-
return base;
|
|
25
|
-
} // 'b=1&c=2&a=5'
|
|
26
|
-
|
|
27
13
|
|
|
28
|
-
return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
|
|
29
|
-
.split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
30
|
-
.map(entry => entry.split('=')) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
31
|
-
.sort((a, b) => a[0].localeCompare(b[0])) // [ 'a=5', 'b=1', 'c=2' ]
|
|
32
|
-
.map(pair => pair.join('=')) // 'a=5&b=1&c=2'
|
|
33
|
-
.join('&');
|
|
34
|
-
}
|
|
35
14
|
/**
|
|
36
15
|
* @param {Record<string, any>} preloadedData
|
|
37
16
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
38
17
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
18
|
function createPreloadingMiddleware(preloadedData) {
|
|
42
19
|
const cache = Object.keys(preloadedData).reduce((result, path) => {
|
|
43
|
-
result[
|
|
20
|
+
result[(0, _url.normalizePath)(path)] = preloadedData[path];
|
|
44
21
|
return result;
|
|
45
22
|
},
|
|
46
23
|
/** @type {Record<string, any>} */
|
|
@@ -49,13 +26,24 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
49
26
|
const {
|
|
50
27
|
parse = true
|
|
51
28
|
} = options;
|
|
29
|
+
/** @type {string | void} */
|
|
52
30
|
|
|
53
|
-
|
|
31
|
+
let rawPath = options.path;
|
|
32
|
+
|
|
33
|
+
if (!rawPath && options.url) {
|
|
34
|
+
const pathFromQuery = (0, _url.getQueryArg)(options.url, 'rest_route');
|
|
35
|
+
|
|
36
|
+
if (typeof pathFromQuery === 'string') {
|
|
37
|
+
rawPath = pathFromQuery;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (typeof rawPath === 'string') {
|
|
54
42
|
const method = options.method || 'GET';
|
|
55
|
-
const path =
|
|
43
|
+
const path = (0, _url.normalizePath)(rawPath);
|
|
56
44
|
|
|
57
45
|
if ('GET' === method && cache[path]) {
|
|
58
|
-
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only
|
|
46
|
+
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time
|
|
59
47
|
|
|
60
48
|
delete cache[path];
|
|
61
49
|
return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
|
|
@@ -64,7 +52,10 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
64
52
|
headers: cacheData.headers
|
|
65
53
|
}));
|
|
66
54
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
|
67
|
-
|
|
55
|
+
const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time
|
|
56
|
+
|
|
57
|
+
delete cache[method][path];
|
|
58
|
+
return Promise.resolve(parse ? cacheData.body : cacheData);
|
|
68
59
|
}
|
|
69
60
|
}
|
|
70
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/preloading.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/preloading.js"],"names":["createPreloadingMiddleware","preloadedData","cache","Object","keys","reduce","result","path","options","next","parse","rawPath","url","pathFromQuery","method","cacheData","Promise","resolve","body","window","Response","JSON","stringify","status","statusText","headers"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,SAASA,0BAAT,CAAqCC,aAArC,EAAqD;AACpD,QAAMC,KAAK,GAAGC,MAAM,CAACC,IAAP,CAAaH,aAAb,EAA6BI,MAA7B,CAAqC,CAAEC,MAAF,EAAUC,IAAV,KAAoB;AACtED,IAAAA,MAAM,CAAE,wBAAeC,IAAf,CAAF,CAAN,GAAkCN,aAAa,CAAEM,IAAF,CAA/C;AACA,WAAOD,MAAP;AACA,GAHa;AAGX;AAAqC,IAH1B,CAAd;AAKA,SAAO,CAAEE,OAAF,EAAWC,IAAX,KAAqB;AAC3B,UAAM;AAAEC,MAAAA,KAAK,GAAG;AAAV,QAAmBF,OAAzB;AACA;;AACA,QAAIG,OAAO,GAAGH,OAAO,CAACD,IAAtB;;AACA,QAAK,CAAEI,OAAF,IAAaH,OAAO,CAACI,GAA1B,EAAgC;AAC/B,YAAMC,aAAa,GAAG,sBAAaL,OAAO,CAACI,GAArB,EAA0B,YAA1B,CAAtB;;AACA,UAAK,OAAOC,aAAP,KAAyB,QAA9B,EAAyC;AACxCF,QAAAA,OAAO,GAAGE,aAAV;AACA;AACD;;AACD,QAAK,OAAOF,OAAP,KAAmB,QAAxB,EAAmC;AAClC,YAAMG,MAAM,GAAGN,OAAO,CAACM,MAAR,IAAkB,KAAjC;AACA,YAAMP,IAAI,GAAG,wBAAeI,OAAf,CAAb;;AAEA,UAAK,UAAUG,MAAV,IAAoBZ,KAAK,CAAEK,IAAF,CAA9B,EAAyC;AACxC,cAAMQ,SAAS,GAAGb,KAAK,CAAEK,IAAF,CAAvB,CADwC,CAGxC;;AACA,eAAOL,KAAK,CAAEK,IAAF,CAAZ;AAEA,eAAOS,OAAO,CAACC,OAAR,CACNP,KAAK,GACFK,SAAS,CAACG,IADR,GAEF,IAAIC,MAAM,CAACC,QAAX,CACAC,IAAI,CAACC,SAAL,CAAgBP,SAAS,CAACG,IAA1B,CADA,EAEA;AACCK,UAAAA,MAAM,EAAE,GADT;AAECC,UAAAA,UAAU,EAAE,IAFb;AAGCC,UAAAA,OAAO,EAAEV,SAAS,CAACU;AAHpB,SAFA,CAHG,CAAP;AAYA,OAlBD,MAkBO,IACN,cAAcX,MAAd,IACAZ,KAAK,CAAEY,MAAF,CADL,IAEAZ,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAHM,EAIL;AACD,cAAMQ,SAAS,GAAGb,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAAlB,CADC,CAGD;;AACA,eAAOL,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAAP;AAEA,eAAOS,OAAO,CAACC,OAAR,CAAiBP,KAAK,GAAGK,SAAS,CAACG,IAAb,GAAoBH,SAA1C,CAAP;AACA;AACD;;AAED,WAAON,IAAI,CAAED,OAAF,CAAX;AACA,GA/CD;AAgDA;;eAEcR,0B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getQueryArg, normalizePath } from '@wordpress/url';\n\n/**\n * @param {Record<string, any>} preloadedData\n * @return {import('../types').APIFetchMiddleware} Preloading middleware.\n */\nfunction createPreloadingMiddleware( preloadedData ) {\n\tconst cache = Object.keys( preloadedData ).reduce( ( result, path ) => {\n\t\tresult[ normalizePath( path ) ] = preloadedData[ path ];\n\t\treturn result;\n\t}, /** @type {Record<string, any>} */ ( {} ) );\n\n\treturn ( options, next ) => {\n\t\tconst { parse = true } = options;\n\t\t/** @type {string | void} */\n\t\tlet rawPath = options.path;\n\t\tif ( ! rawPath && options.url ) {\n\t\t\tconst pathFromQuery = getQueryArg( options.url, 'rest_route' );\n\t\t\tif ( typeof pathFromQuery === 'string' ) {\n\t\t\t\trawPath = pathFromQuery;\n\t\t\t}\n\t\t}\n\t\tif ( typeof rawPath === 'string' ) {\n\t\t\tconst method = options.method || 'GET';\n\t\t\tconst path = normalizePath( rawPath );\n\n\t\t\tif ( 'GET' === method && cache[ path ] ) {\n\t\t\t\tconst cacheData = cache[ path ];\n\n\t\t\t\t// Unsetting the cache key ensures that the data is only used a single time\n\t\t\t\tdelete cache[ path ];\n\n\t\t\t\treturn Promise.resolve(\n\t\t\t\t\tparse\n\t\t\t\t\t\t? cacheData.body\n\t\t\t\t\t\t: new window.Response(\n\t\t\t\t\t\t\t\tJSON.stringify( cacheData.body ),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstatus: 200,\n\t\t\t\t\t\t\t\t\tstatusText: 'OK',\n\t\t\t\t\t\t\t\t\theaders: cacheData.headers,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t'OPTIONS' === method &&\n\t\t\t\tcache[ method ] &&\n\t\t\t\tcache[ method ][ path ]\n\t\t\t) {\n\t\t\t\tconst cacheData = cache[ method ][ path ];\n\n\t\t\t\t// Unsetting the cache key ensures that the data is only used a single time\n\t\t\t\tdelete cache[ method ][ path ];\n\n\t\t\t\treturn Promise.resolve( parse ? cacheData.body : cacheData );\n\t\t\t}\n\t\t}\n\n\t\treturn next( options );\n\t};\n}\n\nexport default createPreloadingMiddleware;\n"]}
|
package/build/types.js
CHANGED
package/build/utils/response.js
CHANGED
|
@@ -20,7 +20,9 @@ var _i18n = require("@wordpress/i18n");
|
|
|
20
20
|
*
|
|
21
21
|
* @return {Promise<any> | null | Response} Parsed response.
|
|
22
22
|
*/
|
|
23
|
-
const parseResponse = (response
|
|
23
|
+
const parseResponse = function (response) {
|
|
24
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
25
|
+
|
|
24
26
|
if (shouldParseResponse) {
|
|
25
27
|
if (response.status === 204) {
|
|
26
28
|
return null;
|
|
@@ -64,7 +66,8 @@ const parseJsonAndNormalizeError = response => {
|
|
|
64
66
|
*/
|
|
65
67
|
|
|
66
68
|
|
|
67
|
-
const parseResponseAndNormalizeError = (response
|
|
69
|
+
const parseResponseAndNormalizeError = function (response) {
|
|
70
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
68
71
|
return Promise.resolve(parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
|
|
69
72
|
};
|
|
70
73
|
/**
|
|
@@ -78,7 +81,9 @@ const parseResponseAndNormalizeError = (response, shouldParseResponse = true) =>
|
|
|
78
81
|
|
|
79
82
|
exports.parseResponseAndNormalizeError = parseResponseAndNormalizeError;
|
|
80
83
|
|
|
81
|
-
function parseAndThrowError(response
|
|
84
|
+
function parseAndThrowError(response) {
|
|
85
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
86
|
+
|
|
82
87
|
if (!shouldParseResponse) {
|
|
83
88
|
throw response;
|
|
84
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,UAAEC,QAAF,EAA4C;AAAA,MAAhCC,mBAAgC,uEAAV,IAAU;;AACjE,MAAKA,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AAI,EAAE,eADc;AAEpBC,MAAAA,OAAO,EAAE,cAAI,4BAAJ;AAFW,KAArB;AAKA,UAAMO,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\n\n/**\n * Calls the `json` function on the Response, throwing an error if the response\n * doesn't have a json function or if parsing the json itself fails.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}
|
|
@@ -15,14 +15,17 @@ import apiFetch from '..';
|
|
|
15
15
|
* @return {import('../types').APIFetchOptions} The request with the modified query args
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const modifyQuery = ({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
const modifyQuery = (_ref, queryArgs) => {
|
|
19
|
+
let {
|
|
20
|
+
path,
|
|
21
|
+
url,
|
|
22
|
+
...options
|
|
23
|
+
} = _ref;
|
|
24
|
+
return { ...options,
|
|
25
|
+
url: url && addQueryArgs(url, queryArgs),
|
|
26
|
+
path: path && addQueryArgs(path, queryArgs)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
26
29
|
/**
|
|
27
30
|
* Duplicates parsing functionality from apiFetch.
|
|
28
31
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["addQueryArgs","apiFetch","modifyQuery","path","url","options","
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["addQueryArgs","apiFetch","modifyQuery","queryArgs","path","url","options","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,IAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,OAA6BC,SAA7B;A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YAAF,CAAvC;AACAF,IAAAA,aAAa,GAAGA,aAAa,CAACC,MAAd,CAAsBG,WAAtB,CAAhB;AACAL,IAAAA,QAAQ,GAAGb,cAAc,CAAEgB,YAAF,CAAzB;AACA;;AACD,SAAOF,aAAP;AACA,CAjDD;;AAmDA,eAAeP,kBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}
|
|
@@ -7,16 +7,25 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { parseAndThrowError, parseResponseAndNormalizeError } from '../utils/response';
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('../types').APIFetchOptions} options
|
|
12
|
+
* @return {boolean} True if the request is for media upload.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function isMediaUploadRequest(options) {
|
|
16
|
+
const isCreateMethod = !!options.method && options.method === 'POST';
|
|
17
|
+
const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
18
|
+
return isMediaEndpoint && isCreateMethod;
|
|
19
|
+
}
|
|
10
20
|
/**
|
|
11
21
|
* Middleware handling media upload failures and retries.
|
|
12
22
|
*
|
|
13
23
|
* @type {import('../types').APIFetchMiddleware}
|
|
14
24
|
*/
|
|
15
25
|
|
|
16
|
-
const mediaUploadMiddleware = (options, next) => {
|
|
17
|
-
const isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
const mediaUploadMiddleware = (options, next) => {
|
|
28
|
+
if (!isMediaUploadRequest(options)) {
|
|
20
29
|
return next(options);
|
|
21
30
|
}
|
|
22
31
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/media-upload.js"],"names":["__","parseAndThrowError","parseResponseAndNormalizeError","
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/media-upload.js"],"names":["__","parseAndThrowError","parseResponseAndNormalizeError","isMediaUploadRequest","options","isCreateMethod","method","isMediaEndpoint","path","indexOf","url","mediaUploadMiddleware","next","retries","maxRetries","postProcess","attachmentId","data","action","parse","catch","Promise","reject","response","headers","get","status","code","message","then"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SACCC,kBADD,EAECC,8BAFD,QAGO,mBAHP;AAKA;AACA;AACA;AACA;;AACA,SAASC,oBAAT,CAA+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GAlBD;;AAoBA,SAAOV,IAAI,CAAE,EAAE,GAAGR,OAAL;AAAce,IAAAA,KAAK,EAAE;AAArB,GAAF,CAAJ,CACLC,KADK,CACIG,QAAF,IAAgB;AACvB,UAAMP,YAAY,GAAGO,QAAQ,CAACC,OAAT,CAAiBC,GAAjB,CACpB,2BADoB,CAArB;;AAGA,QACCF,QAAQ,CAACG,MAAT,IAAmB,GAAnB,IACAH,QAAQ,CAACG,MAAT,GAAkB,GADlB,IAEAV,YAHD,EAIE;AACD,aAAOD,WAAW,CAAEC,YAAF,CAAX,CAA4BI,KAA5B,CAAmC,MAAM;AAC/C,YAAKhB,OAAO,CAACe,KAAR,KAAkB,KAAvB,EAA+B;AAC9B,iBAAOE,OAAO,CAACC,MAAR,CAAgB;AACtBK,YAAAA,IAAI,EAAE,cADgB;AAEtBC,YAAAA,OAAO,EAAE5B,EAAE,CACV,+FADU;AAFW,WAAhB,CAAP;AAMA;;AAED,eAAOqB,OAAO,CAACC,MAAR,CAAgBC,QAAhB,CAAP;AACA,OAXM,CAAP;AAYA;;AACD,WAAOtB,kBAAkB,CAAEsB,QAAF,EAAYnB,OAAO,CAACe,KAApB,CAAzB;AACA,GAxBK,EAyBLU,IAzBK,CAyBGN,QAAF,IACNrB,8BAA8B,CAAEqB,QAAF,EAAYnB,OAAO,CAACe,KAApB,CA1BzB,CAAP;AA4BA,CA5DD;;AA8DA,eAAeR,qBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tparseAndThrowError,\n\tparseResponseAndNormalizeError,\n} from '../utils/response';\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request is for media upload.\n */\nfunction isMediaUploadRequest( options ) {\n\tconst isCreateMethod = !! options.method && options.method === 'POST';\n\tconst isMediaEndpoint =\n\t\t( !! options.path && options.path.indexOf( '/wp/v2/media' ) !== -1 ) ||\n\t\t( !! options.url && options.url.indexOf( '/wp/v2/media' ) !== -1 );\n\n\treturn isMediaEndpoint && isCreateMethod;\n}\n\n/**\n * Middleware handling media upload failures and retries.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst mediaUploadMiddleware = ( options, next ) => {\n\tif ( ! isMediaUploadRequest( options ) ) {\n\t\treturn next( options );\n\t}\n\n\tlet retries = 0;\n\tconst maxRetries = 5;\n\n\t/**\n\t * @param {string} attachmentId\n\t * @return {Promise<any>} Processed post response.\n\t */\n\tconst postProcess = ( attachmentId ) => {\n\t\tretries++;\n\t\treturn next( {\n\t\t\tpath: `/wp/v2/media/${ attachmentId }/post-process`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { action: 'create-image-subsizes' },\n\t\t\tparse: false,\n\t\t} ).catch( () => {\n\t\t\tif ( retries < maxRetries ) {\n\t\t\t\treturn postProcess( attachmentId );\n\t\t\t}\n\t\t\tnext( {\n\t\t\t\tpath: `/wp/v2/media/${ attachmentId }?force=true`,\n\t\t\t\tmethod: 'DELETE',\n\t\t\t} );\n\n\t\t\treturn Promise.reject();\n\t\t} );\n\t};\n\n\treturn next( { ...options, parse: false } )\n\t\t.catch( ( response ) => {\n\t\t\tconst attachmentId = response.headers.get(\n\t\t\t\t'x-wp-upload-attachment-id'\n\t\t\t);\n\t\t\tif (\n\t\t\t\tresponse.status >= 500 &&\n\t\t\t\tresponse.status < 600 &&\n\t\t\t\tattachmentId\n\t\t\t) {\n\t\t\t\treturn postProcess( attachmentId ).catch( () => {\n\t\t\t\t\tif ( options.parse !== false ) {\n\t\t\t\t\t\treturn Promise.reject( {\n\t\t\t\t\t\t\tcode: 'post_process',\n\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t'Media upload failed. If this is a photo or a large image, please scale it down and try again.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn Promise.reject( response );\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn parseAndThrowError( response, options.parse );\n\t\t} )\n\t\t.then( ( response ) =>\n\t\t\tparseResponseAndNormalizeError( response, options.parse )\n\t\t);\n};\n\nexport default mediaUploadMiddleware;\n"]}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
-
* text.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} path Original path.
|
|
7
|
-
*
|
|
8
|
-
* @return {string} Normalized path.
|
|
2
|
+
* WordPress dependencies
|
|
9
3
|
*/
|
|
10
|
-
|
|
11
|
-
const splitted = path.split('?');
|
|
12
|
-
const query = splitted[1];
|
|
13
|
-
const base = splitted[0];
|
|
14
|
-
|
|
15
|
-
if (!query) {
|
|
16
|
-
return base;
|
|
17
|
-
} // 'b=1&c=2&a=5'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
|
|
21
|
-
.split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
22
|
-
.map(entry => entry.split('=')) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
23
|
-
.sort((a, b) => a[0].localeCompare(b[0])) // [ 'a=5', 'b=1', 'c=2' ]
|
|
24
|
-
.map(pair => pair.join('=')) // 'a=5&b=1&c=2'
|
|
25
|
-
.join('&');
|
|
26
|
-
}
|
|
4
|
+
import { getQueryArg, normalizePath } from '@wordpress/url';
|
|
27
5
|
/**
|
|
28
6
|
* @param {Record<string, any>} preloadedData
|
|
29
7
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
@@ -31,7 +9,7 @@ export function getStablePath(path) {
|
|
|
31
9
|
|
|
32
10
|
function createPreloadingMiddleware(preloadedData) {
|
|
33
11
|
const cache = Object.keys(preloadedData).reduce((result, path) => {
|
|
34
|
-
result[
|
|
12
|
+
result[normalizePath(path)] = preloadedData[path];
|
|
35
13
|
return result;
|
|
36
14
|
},
|
|
37
15
|
/** @type {Record<string, any>} */
|
|
@@ -40,13 +18,24 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
40
18
|
const {
|
|
41
19
|
parse = true
|
|
42
20
|
} = options;
|
|
21
|
+
/** @type {string | void} */
|
|
22
|
+
|
|
23
|
+
let rawPath = options.path;
|
|
43
24
|
|
|
44
|
-
if (
|
|
25
|
+
if (!rawPath && options.url) {
|
|
26
|
+
const pathFromQuery = getQueryArg(options.url, 'rest_route');
|
|
27
|
+
|
|
28
|
+
if (typeof pathFromQuery === 'string') {
|
|
29
|
+
rawPath = pathFromQuery;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof rawPath === 'string') {
|
|
45
34
|
const method = options.method || 'GET';
|
|
46
|
-
const path =
|
|
35
|
+
const path = normalizePath(rawPath);
|
|
47
36
|
|
|
48
37
|
if ('GET' === method && cache[path]) {
|
|
49
|
-
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only
|
|
38
|
+
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time
|
|
50
39
|
|
|
51
40
|
delete cache[path];
|
|
52
41
|
return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
|
|
@@ -55,7 +44,10 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
55
44
|
headers: cacheData.headers
|
|
56
45
|
}));
|
|
57
46
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
|
58
|
-
|
|
47
|
+
const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time
|
|
48
|
+
|
|
49
|
+
delete cache[method][path];
|
|
50
|
+
return Promise.resolve(parse ? cacheData.body : cacheData);
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/preloading.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/preloading.js"],"names":["getQueryArg","normalizePath","createPreloadingMiddleware","preloadedData","cache","Object","keys","reduce","result","path","options","next","parse","rawPath","url","pathFromQuery","method","cacheData","Promise","resolve","body","window","Response","JSON","stringify","status","statusText","headers"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,aAAtB,QAA2C,gBAA3C;AAEA;AACA;AACA;AACA;;AACA,SAASC,0BAAT,CAAqCC,aAArC,EAAqD;AACpD,QAAMC,KAAK,GAAGC,MAAM,CAACC,IAAP,CAAaH,aAAb,EAA6BI,MAA7B,CAAqC,CAAEC,MAAF,EAAUC,IAAV,KAAoB;AACtED,IAAAA,MAAM,CAAEP,aAAa,CAAEQ,IAAF,CAAf,CAAN,GAAkCN,aAAa,CAAEM,IAAF,CAA/C;AACA,WAAOD,MAAP;AACA,GAHa;AAGX;AAAqC,IAH1B,CAAd;AAKA,SAAO,CAAEE,OAAF,EAAWC,IAAX,KAAqB;AAC3B,UAAM;AAAEC,MAAAA,KAAK,GAAG;AAAV,QAAmBF,OAAzB;AACA;;AACA,QAAIG,OAAO,GAAGH,OAAO,CAACD,IAAtB;;AACA,QAAK,CAAEI,OAAF,IAAaH,OAAO,CAACI,GAA1B,EAAgC;AAC/B,YAAMC,aAAa,GAAGf,WAAW,CAAEU,OAAO,CAACI,GAAV,EAAe,YAAf,CAAjC;;AACA,UAAK,OAAOC,aAAP,KAAyB,QAA9B,EAAyC;AACxCF,QAAAA,OAAO,GAAGE,aAAV;AACA;AACD;;AACD,QAAK,OAAOF,OAAP,KAAmB,QAAxB,EAAmC;AAClC,YAAMG,MAAM,GAAGN,OAAO,CAACM,MAAR,IAAkB,KAAjC;AACA,YAAMP,IAAI,GAAGR,aAAa,CAAEY,OAAF,CAA1B;;AAEA,UAAK,UAAUG,MAAV,IAAoBZ,KAAK,CAAEK,IAAF,CAA9B,EAAyC;AACxC,cAAMQ,SAAS,GAAGb,KAAK,CAAEK,IAAF,CAAvB,CADwC,CAGxC;;AACA,eAAOL,KAAK,CAAEK,IAAF,CAAZ;AAEA,eAAOS,OAAO,CAACC,OAAR,CACNP,KAAK,GACFK,SAAS,CAACG,IADR,GAEF,IAAIC,MAAM,CAACC,QAAX,CACAC,IAAI,CAACC,SAAL,CAAgBP,SAAS,CAACG,IAA1B,CADA,EAEA;AACCK,UAAAA,MAAM,EAAE,GADT;AAECC,UAAAA,UAAU,EAAE,IAFb;AAGCC,UAAAA,OAAO,EAAEV,SAAS,CAACU;AAHpB,SAFA,CAHG,CAAP;AAYA,OAlBD,MAkBO,IACN,cAAcX,MAAd,IACAZ,KAAK,CAAEY,MAAF,CADL,IAEAZ,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAHM,EAIL;AACD,cAAMQ,SAAS,GAAGb,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAAlB,CADC,CAGD;;AACA,eAAOL,KAAK,CAAEY,MAAF,CAAL,CAAiBP,IAAjB,CAAP;AAEA,eAAOS,OAAO,CAACC,OAAR,CAAiBP,KAAK,GAAGK,SAAS,CAACG,IAAb,GAAoBH,SAA1C,CAAP;AACA;AACD;;AAED,WAAON,IAAI,CAAED,OAAF,CAAX;AACA,GA/CD;AAgDA;;AAED,eAAeR,0BAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getQueryArg, normalizePath } from '@wordpress/url';\n\n/**\n * @param {Record<string, any>} preloadedData\n * @return {import('../types').APIFetchMiddleware} Preloading middleware.\n */\nfunction createPreloadingMiddleware( preloadedData ) {\n\tconst cache = Object.keys( preloadedData ).reduce( ( result, path ) => {\n\t\tresult[ normalizePath( path ) ] = preloadedData[ path ];\n\t\treturn result;\n\t}, /** @type {Record<string, any>} */ ( {} ) );\n\n\treturn ( options, next ) => {\n\t\tconst { parse = true } = options;\n\t\t/** @type {string | void} */\n\t\tlet rawPath = options.path;\n\t\tif ( ! rawPath && options.url ) {\n\t\t\tconst pathFromQuery = getQueryArg( options.url, 'rest_route' );\n\t\t\tif ( typeof pathFromQuery === 'string' ) {\n\t\t\t\trawPath = pathFromQuery;\n\t\t\t}\n\t\t}\n\t\tif ( typeof rawPath === 'string' ) {\n\t\t\tconst method = options.method || 'GET';\n\t\t\tconst path = normalizePath( rawPath );\n\n\t\t\tif ( 'GET' === method && cache[ path ] ) {\n\t\t\t\tconst cacheData = cache[ path ];\n\n\t\t\t\t// Unsetting the cache key ensures that the data is only used a single time\n\t\t\t\tdelete cache[ path ];\n\n\t\t\t\treturn Promise.resolve(\n\t\t\t\t\tparse\n\t\t\t\t\t\t? cacheData.body\n\t\t\t\t\t\t: new window.Response(\n\t\t\t\t\t\t\t\tJSON.stringify( cacheData.body ),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstatus: 200,\n\t\t\t\t\t\t\t\t\tstatusText: 'OK',\n\t\t\t\t\t\t\t\t\theaders: cacheData.headers,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t'OPTIONS' === method &&\n\t\t\t\tcache[ method ] &&\n\t\t\t\tcache[ method ][ path ]\n\t\t\t) {\n\t\t\t\tconst cacheData = cache[ method ][ path ];\n\n\t\t\t\t// Unsetting the cache key ensures that the data is only used a single time\n\t\t\t\tdelete cache[ method ][ path ];\n\n\t\t\t\treturn Promise.resolve( parse ? cacheData.body : cacheData );\n\t\t\t}\n\t\t}\n\n\t\treturn next( options );\n\t};\n}\n\nexport default createPreloadingMiddleware;\n"]}
|
package/build-module/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -11,7 +11,9 @@ import { __ } from '@wordpress/i18n';
|
|
|
11
11
|
* @return {Promise<any> | null | Response} Parsed response.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const parseResponse = (response
|
|
14
|
+
const parseResponse = function (response) {
|
|
15
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
16
|
+
|
|
15
17
|
if (shouldParseResponse) {
|
|
16
18
|
if (response.status === 204) {
|
|
17
19
|
return null;
|
|
@@ -55,7 +57,8 @@ const parseJsonAndNormalizeError = response => {
|
|
|
55
57
|
*/
|
|
56
58
|
|
|
57
59
|
|
|
58
|
-
export const parseResponseAndNormalizeError = (response
|
|
60
|
+
export const parseResponseAndNormalizeError = function (response) {
|
|
61
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
59
62
|
return Promise.resolve(parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
|
|
60
63
|
};
|
|
61
64
|
/**
|
|
@@ -66,7 +69,9 @@ export const parseResponseAndNormalizeError = (response, shouldParseResponse = t
|
|
|
66
69
|
* @return {Promise<any>} Parsed response.
|
|
67
70
|
*/
|
|
68
71
|
|
|
69
|
-
export function parseAndThrowError(response
|
|
72
|
+
export function parseAndThrowError(response) {
|
|
73
|
+
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
74
|
+
|
|
70
75
|
if (!shouldParseResponse) {
|
|
71
76
|
throw response;
|
|
72
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,aAAa,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","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AAAA,MAA7BC,mBAA6B,uEAAP,IAAO;;AAC1E,MAAK,CAAEA,mBAAP,EAA6B;AAC5B,UAAMD,QAAN;AACA;;AAED,SAAOM,0BAA0B,CAAEN,QAAF,CAA1B,CAAuCe,IAAvC,CAA+CC,KAAF,IAAa;AAChE,UAAMC,YAAY,GAAG;AACpBT,MAAAA,IAAI,EAAE,eADc;AAEpBC,MAAAA,OAAO,EAAEX,EAAE,CAAE,4BAAF;AAFS,KAArB;AAKA,UAAMkB,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\n\n/**\n * Calls the `json` function on the Response, throwing an error if the response\n * doesn't have a json function or if parsing the json itself fails.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-upload.d.ts","sourceRoot":"","sources":["../../src/middlewares/media-upload.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"media-upload.d.ts","sourceRoot":"","sources":["../../src/middlewares/media-upload.js"],"names":[],"mappings":";AA0BA;;;;GAIG;AACH,qCAFU,OAAO,UAAU,EAAE,kBAAkB,CA8D7C"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a path, returns a normalized path where equal query parameter values
|
|
3
|
-
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
-
* text.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} path Original path.
|
|
7
|
-
*
|
|
8
|
-
* @return {string} Normalized path.
|
|
9
|
-
*/
|
|
10
|
-
export function getStablePath(path: string): string;
|
|
11
1
|
export default createPreloadingMiddleware;
|
|
12
2
|
/**
|
|
13
3
|
* @param {Record<string, any>} preloadedData
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preloading.d.ts","sourceRoot":"","sources":["../../src/middlewares/preloading.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preloading.d.ts","sourceRoot":"","sources":["../../src/middlewares/preloading.js"],"names":[],"mappings":";AAKA;;;GAGG;AACH,2DAHW,OAAO,MAAM,EAAE,GAAG,CAAC,GAClB,OAAO,UAAU,EAAE,kBAAkB,CAwDhD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/api-fetch",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.6",
|
|
4
4
|
"description": "Utility to make WordPress REST API requests.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"react-native": "src/index",
|
|
28
28
|
"types": "build-types",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.
|
|
31
|
-
"@wordpress/i18n": "^4.2.
|
|
32
|
-
"@wordpress/url": "^3.
|
|
30
|
+
"@babel/runtime": "^7.16.0",
|
|
31
|
+
"@wordpress/i18n": "^4.2.4",
|
|
32
|
+
"@wordpress/url": "^3.3.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
|
|
38
38
|
}
|
|
@@ -11,19 +11,29 @@ import {
|
|
|
11
11
|
parseResponseAndNormalizeError,
|
|
12
12
|
} from '../utils/response';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('../types').APIFetchOptions} options
|
|
16
|
+
* @return {boolean} True if the request is for media upload.
|
|
17
|
+
*/
|
|
18
|
+
function isMediaUploadRequest( options ) {
|
|
19
|
+
const isCreateMethod = !! options.method && options.method === 'POST';
|
|
20
|
+
const isMediaEndpoint =
|
|
21
|
+
( !! options.path && options.path.indexOf( '/wp/v2/media' ) !== -1 ) ||
|
|
22
|
+
( !! options.url && options.url.indexOf( '/wp/v2/media' ) !== -1 );
|
|
23
|
+
|
|
24
|
+
return isMediaEndpoint && isCreateMethod;
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
/**
|
|
15
28
|
* Middleware handling media upload failures and retries.
|
|
16
29
|
*
|
|
17
30
|
* @type {import('../types').APIFetchMiddleware}
|
|
18
31
|
*/
|
|
19
32
|
const mediaUploadMiddleware = ( options, next ) => {
|
|
20
|
-
|
|
21
|
-
( options.path && options.path.indexOf( '/wp/v2/media' ) !== -1 ) ||
|
|
22
|
-
( options.url && options.url.indexOf( '/wp/v2/media' ) !== -1 );
|
|
23
|
-
|
|
24
|
-
if ( ! isMediaUploadRequest ) {
|
|
33
|
+
if ( ! isMediaUploadRequest( options ) ) {
|
|
25
34
|
return next( options );
|
|
26
35
|
}
|
|
36
|
+
|
|
27
37
|
let retries = 0;
|
|
28
38
|
const maxRetries = 5;
|
|
29
39
|
|
|
@@ -1,37 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* will be treated as identical, regardless of order they appear in the original
|
|
4
|
-
* text.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} path Original path.
|
|
7
|
-
*
|
|
8
|
-
* @return {string} Normalized path.
|
|
2
|
+
* WordPress dependencies
|
|
9
3
|
*/
|
|
10
|
-
|
|
11
|
-
const splitted = path.split( '?' );
|
|
12
|
-
const query = splitted[ 1 ];
|
|
13
|
-
const base = splitted[ 0 ];
|
|
14
|
-
if ( ! query ) {
|
|
15
|
-
return base;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 'b=1&c=2&a=5'
|
|
19
|
-
return (
|
|
20
|
-
base +
|
|
21
|
-
'?' +
|
|
22
|
-
query
|
|
23
|
-
// [ 'b=1', 'c=2', 'a=5' ]
|
|
24
|
-
.split( '&' )
|
|
25
|
-
// [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
|
26
|
-
.map( ( entry ) => entry.split( '=' ) )
|
|
27
|
-
// [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
|
|
28
|
-
.sort( ( a, b ) => a[ 0 ].localeCompare( b[ 0 ] ) )
|
|
29
|
-
// [ 'a=5', 'b=1', 'c=2' ]
|
|
30
|
-
.map( ( pair ) => pair.join( '=' ) )
|
|
31
|
-
// 'a=5&b=1&c=2'
|
|
32
|
-
.join( '&' )
|
|
33
|
-
);
|
|
34
|
-
}
|
|
4
|
+
import { getQueryArg, normalizePath } from '@wordpress/url';
|
|
35
5
|
|
|
36
6
|
/**
|
|
37
7
|
* @param {Record<string, any>} preloadedData
|
|
@@ -39,20 +9,28 @@ export function getStablePath( path ) {
|
|
|
39
9
|
*/
|
|
40
10
|
function createPreloadingMiddleware( preloadedData ) {
|
|
41
11
|
const cache = Object.keys( preloadedData ).reduce( ( result, path ) => {
|
|
42
|
-
result[
|
|
12
|
+
result[ normalizePath( path ) ] = preloadedData[ path ];
|
|
43
13
|
return result;
|
|
44
14
|
}, /** @type {Record<string, any>} */ ( {} ) );
|
|
45
15
|
|
|
46
16
|
return ( options, next ) => {
|
|
47
17
|
const { parse = true } = options;
|
|
48
|
-
|
|
18
|
+
/** @type {string | void} */
|
|
19
|
+
let rawPath = options.path;
|
|
20
|
+
if ( ! rawPath && options.url ) {
|
|
21
|
+
const pathFromQuery = getQueryArg( options.url, 'rest_route' );
|
|
22
|
+
if ( typeof pathFromQuery === 'string' ) {
|
|
23
|
+
rawPath = pathFromQuery;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if ( typeof rawPath === 'string' ) {
|
|
49
27
|
const method = options.method || 'GET';
|
|
50
|
-
const path =
|
|
28
|
+
const path = normalizePath( rawPath );
|
|
51
29
|
|
|
52
30
|
if ( 'GET' === method && cache[ path ] ) {
|
|
53
31
|
const cacheData = cache[ path ];
|
|
54
32
|
|
|
55
|
-
// Unsetting the cache key ensures that the data is only
|
|
33
|
+
// Unsetting the cache key ensures that the data is only used a single time
|
|
56
34
|
delete cache[ path ];
|
|
57
35
|
|
|
58
36
|
return Promise.resolve(
|
|
@@ -72,11 +50,12 @@ function createPreloadingMiddleware( preloadedData ) {
|
|
|
72
50
|
cache[ method ] &&
|
|
73
51
|
cache[ method ][ path ]
|
|
74
52
|
) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
53
|
+
const cacheData = cache[ method ][ path ];
|
|
54
|
+
|
|
55
|
+
// Unsetting the cache key ensures that the data is only used a single time
|
|
56
|
+
delete cache[ method ][ path ];
|
|
57
|
+
|
|
58
|
+
return Promise.resolve( parse ? cacheData.body : cacheData );
|
|
80
59
|
}
|
|
81
60
|
}
|
|
82
61
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import mediaUploadMiddleware from '../media-upload';
|
|
5
|
+
|
|
6
|
+
describe( 'Media Upload Middleware', () => {
|
|
7
|
+
it( 'should defer to the next middleware with the same options', () => {
|
|
8
|
+
expect.hasAssertions();
|
|
9
|
+
|
|
10
|
+
const originalOptions = { path: '/wp/v2/media' };
|
|
11
|
+
const next = ( options ) => {
|
|
12
|
+
expect( options ).toBe( originalOptions );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
mediaUploadMiddleware( originalOptions, next );
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
it( 'should change options not to parse', () => {
|
|
19
|
+
expect.hasAssertions();
|
|
20
|
+
|
|
21
|
+
const requestOptions = { method: 'POST', path: '/wp/v2/media' };
|
|
22
|
+
const next = ( options ) => {
|
|
23
|
+
expect( options.parse ).toBe( false );
|
|
24
|
+
|
|
25
|
+
return Promise.resolve( {
|
|
26
|
+
status: 200,
|
|
27
|
+
json() {
|
|
28
|
+
return Promise.resolve( [ 'item' ] );
|
|
29
|
+
},
|
|
30
|
+
} );
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
mediaUploadMiddleware( requestOptions, next );
|
|
34
|
+
} );
|
|
35
|
+
} );
|
|
@@ -1,32 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import createPreloadingMiddleware
|
|
4
|
+
import createPreloadingMiddleware from '../preloading';
|
|
5
5
|
|
|
6
6
|
describe( 'Preloading Middleware', () => {
|
|
7
|
-
describe( 'getStablePath', () => {
|
|
8
|
-
it( 'returns same value if no query parameters', () => {
|
|
9
|
-
const path = '/foo/bar';
|
|
10
|
-
|
|
11
|
-
expect( getStablePath( path ) ).toBe( path );
|
|
12
|
-
} );
|
|
13
|
-
|
|
14
|
-
it( 'returns a stable path', () => {
|
|
15
|
-
const abc = getStablePath( '/foo/bar?a=5&b=1&c=2' );
|
|
16
|
-
const bca = getStablePath( '/foo/bar?b=1&c=2&a=5' );
|
|
17
|
-
const bac = getStablePath( '/foo/bar?b=1&a=5&c=2' );
|
|
18
|
-
const acb = getStablePath( '/foo/bar?a=5&c=2&b=1' );
|
|
19
|
-
const cba = getStablePath( '/foo/bar?c=2&b=1&a=5' );
|
|
20
|
-
const cab = getStablePath( '/foo/bar?c=2&a=5&b=1' );
|
|
21
|
-
|
|
22
|
-
expect( abc ).toBe( bca );
|
|
23
|
-
expect( bca ).toBe( bac );
|
|
24
|
-
expect( bac ).toBe( acb );
|
|
25
|
-
expect( acb ).toBe( cba );
|
|
26
|
-
expect( cba ).toBe( cab );
|
|
27
|
-
} );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
7
|
describe( 'given preloaded data', () => {
|
|
31
8
|
describe( 'when data is requested from a preloaded endpoint', () => {
|
|
32
9
|
describe( 'and it is requested for the first time', () => {
|
|
@@ -199,6 +176,34 @@ describe( 'Preloading Middleware', () => {
|
|
|
199
176
|
expect( value ).toEqual( body );
|
|
200
177
|
} );
|
|
201
178
|
|
|
179
|
+
it( 'should remove OPTIONS type requests from the cache after the first hit', async () => {
|
|
180
|
+
const body = { content: 'example' };
|
|
181
|
+
const preloadedData = {
|
|
182
|
+
OPTIONS: {
|
|
183
|
+
'wp/v2/demo': { body },
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const preloadingMiddleware = createPreloadingMiddleware(
|
|
188
|
+
preloadedData
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const requestOptions = {
|
|
192
|
+
method: 'OPTIONS',
|
|
193
|
+
path: 'wp/v2/demo',
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const firstMiddleware = jest.fn();
|
|
197
|
+
preloadingMiddleware( requestOptions, firstMiddleware );
|
|
198
|
+
expect( firstMiddleware ).not.toHaveBeenCalled();
|
|
199
|
+
|
|
200
|
+
await preloadingMiddleware( requestOptions, firstMiddleware );
|
|
201
|
+
|
|
202
|
+
const secondMiddleware = jest.fn();
|
|
203
|
+
await preloadingMiddleware( requestOptions, secondMiddleware );
|
|
204
|
+
expect( secondMiddleware ).toHaveBeenCalledTimes( 1 );
|
|
205
|
+
} );
|
|
206
|
+
|
|
202
207
|
describe.each( [ [ 'GET' ], [ 'OPTIONS' ] ] )( '%s', ( method ) => {
|
|
203
208
|
describe.each( [
|
|
204
209
|
[ 'all empty', {} ],
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../i18n/build-types/sprintf.d.ts","../hooks/build-types/createaddhook.d.ts","../hooks/build-types/createremovehook.d.ts","../hooks/build-types/createhashook.d.ts","../hooks/build-types/createdoinghook.d.ts","../hooks/build-types/createdidhook.d.ts","../hooks/build-types/index.d.ts","../hooks/build-types/createhooks.d.ts","../i18n/build-types/create-i18n.d.ts","../i18n/build-types/default-i18n.d.ts","../i18n/build-types/index.d.ts","./src/types.ts","./src/middlewares/nonce.js","./src/middlewares/namespace-endpoint.js","./src/middlewares/root-url.js","./src/middlewares/preloading.js","../url/build-types/is-url.d.ts","../url/build-types/is-email.d.ts","../url/build-types/get-protocol.d.ts","../url/build-types/is-valid-protocol.d.ts","../url/build-types/get-authority.d.ts","../url/build-types/is-valid-authority.d.ts","../url/build-types/get-path.d.ts","../url/build-types/is-valid-path.d.ts","../url/build-types/get-query-string.d.ts","../url/build-types/build-query-string.d.ts","../url/build-types/is-valid-query-string.d.ts","../url/build-types/get-path-and-query-string.d.ts","../url/build-types/get-fragment.d.ts","../url/build-types/is-valid-fragment.d.ts","../url/build-types/add-query-args.d.ts","../url/build-types/get-query-arg.d.ts","../url/build-types/get-query-args.d.ts","../url/build-types/has-query-arg.d.ts","../url/build-types/remove-query-args.d.ts","../url/build-types/prepend-http.d.ts","../url/build-types/safe-decode-uri.d.ts","../url/build-types/safe-decode-uri-component.d.ts","../url/build-types/filter-url-for-display.d.ts","../url/build-types/clean-for-slug.d.ts","../url/build-types/get-filename.d.ts","../url/build-types/index.d.ts","./src/middlewares/fetch-all-middleware.js","./src/middlewares/http-v1.js","./src/middlewares/user-locale.js","./src/utils/response.js","./src/middlewares/media-upload.js","./src/index.js"],"fileInfos":[{"version":"aa9fb4c70f369237c2f45f9d969c9a59e0eae9a192962eb48581fe864aa609db","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940","eb75e89d63b3b72dd9ca8b0cac801cecae5be352307c004adeaa60bc9d6df51f","2cc028cd0bdb35b1b5eb723d84666a255933fffbea607f72cbd0c7c7b4bee144",{"version":"e54c8715a4954cfdc66cd69489f2b725c09ebf37492dbd91cff0a1688b1159e8","affectsGlobalScope":true},{"version":"51b8b27c21c066bf877646e320bf6a722b80d1ade65e686923cd9d4494aef1ca","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"2c8c5ee58f30e7c944e04ab1fb5506fdbb4dd507c9efa6972cf4b91cec90c503","affectsGlobalScope":true},{"version":"2bb4b3927299434052b37851a47bf5c39764f2ba88a888a107b32262e9292b7c","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"93544ca2f26a48716c1b6c5091842cad63129daac422dfa4bc52460465f22bb1","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"7435b75fdf3509622e79622dbe5091cf4b09688410ee2034e4fc17d0c99d0862","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"9f1817f7c3f02f6d56e0f403b927e90bb133f371dcebc36fa7d6d208ef6899da","affectsGlobalScope":true},{"version":"cd6efb9467a8b6338ece2e2855e37765700f2cd061ca54b01b33878cf5c7677e","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"4632665b87204bb1caa8b44d165bce0c50dfab177df5b561b345a567cabacf9a","affectsGlobalScope":true},"762bc52248d3fab9873c7af564caf622358312cb35de42a4393b71cc36e14621","d02ec79cefaf292fae64b3be5a4416e64b4e420a6429fd458fac6e1bb4c7950e","27abed653f600ea0d5c86e94181beb42824e0f3f16337e2f9e7e9e9c2c392edf","d7871e0e653aa7197fee88886db5678bee6d42164c1f36e4bce9421ddfa7ca49","11ed10bdb3bcc99893570507eac8fece4840add97ee1d4f5a7fbf41cbfdea0d4","429fb571d3db07d3eaa2e74d43eb4190ece3e0de832ed564aeeaf08873e598eb","406d52bf33d618d846aa0d831ee004290567e328edcd4517bbff2937cc977abf","d3060e0810fc0d0dc009e6f086ef413d3c8aeaaf07da25c8d25fd4e181646acf","9d8f457905054b69915abac57f33e356fdcebce3a10e5be7fcfccad5da5aa934","08f7e6ffa66c66a636aecc5acbeb998215d9d09ccba0c558afb7df7e218edeaf","f829eb39aea4487f0ff94a42c56a1a73bc5202bbdeb03f7a638e4ab3e290d017","d8c4f047684abe4a04c0f6bfc2dfca7b191c4bc7856f2bf63c0b8c04d3c3c59c","cea174bd7165f6473e9251e89b77677cc6fb980a0329964499ff39d7049941a9","3601498a0b299615d2b1871518f4e512837afa1ec33c10e5787c31297dba0e6b","b85af6a2052b84fadbe8e760359bec9d2cb765c404bab048d4bd20477c02bd89","acd1c97ca5c9cc36a47a4c5b96ad822d08422b6404c99cf2713bf96169ec88c7","91265e9c2705df9edc7d912afe177cb9dbe4bd4fe254cc43466885544c065013","81e7db9916d6ce0323656530cb9aba444450454e5a8f3d0108f04931abb36258","7858aa21ac91fef2c9cdf96b3ae00e025efed2920ffca40a75df452d4f5a9576","eb80dedcd92c17d93f403e736e1c3e2aef39379841070221a353a7c13b57369f","029f3a1e2534e85a7cd00f3e79781003e0bcf5147d96db93594ace839803c6cf","2eea9984a7ea08e576d2970ba65a65ebba02699bccdbd0d3a08bb141e15972a1","308246446616acc5397747f35fa8788de7e6ba6cd5dc0ec2752bd75eafefcdb9","9677ef56e52539a73f1d9b89c692cf866d05017b05d9d2fe8cd35a30b42c2d47","6048b5c50d6486b1084b036a7f7d6c76c032d90cc2186f79b344a12ceb488511","26885abe66e07fd38da599d5fc9b4fa8b2df803c56e9bba99a2505e0b982c042","507dc7647a71c90e8cce85259c624b355c22e0dee1833aa4ba20c15a4f5bd21a","c30aaf3d189be8c29b2d3a7761e94b5b532fec6ba0caa74d07a4c1056469acf0","454217fe7beba4cb5497d4bc7fd3116437ce85e5217eb66f3b367fbcbfd45861","65e1ffb7b2343a1814c5cb85164f7d26bce1477b2cf04e6736f37732bc4801d6","3f810d7cac3e3729241d52d667538dc4ca27687f5d40d91f4cb5bce955df5f94","a2bedf5636ce572e507823229c9b7d4e87d97830497822d76e95a971fee78c92","17ab13eba7cde42ca7c95110c7eda405ba6aba7471437d912078d67dfada98eb","f7e734ca25cb0e8c52247b9a7d98f81ffd6ac52485bf9d8938fdbd4d828f469c","5261283f0b521fc1f255a060dcd86986985bd516822b69bb5504392462962899","44e20ca481bcc2abec1f4fcf54139caa4389f1bc16e3ee9d19a10e522903e9ab","a31eda6fcbf86596f69f7c18e6d13af58191fdc9c9620bcc67595fd9e49043ab","c93085fa9e5e568c0a45f64caa05e713fd5438e93d32f5970753e44910bdd540","1e442333978b5864818023d54d4f2e2aa0cbdfb2b486a0d43c900a7a87d61d1d","f215ce6766668f37f5e4652d0facdf55816f24aa5fc6f68c5e33754dbe5219fb","e900ec60297a15c4de70ddaade026ea4fe635e27c286fedd82dd5e963daa1930","d77de11c508405928a38cffebd46ef7d724a0bd5489db32a4e1300fefc0b4708","73df30672e4cf303ecaa5bd1c0a228aec9bd972305b227ac47e53600b88eeb09","86113173dcf3a28562ae7493a30168e671b54a413095025d40eb462ebc55a4b5","e2ca321ccf84538d48bc2b24db351997d607695d37b6d6d50440385c8bffa7bc","b24db76807128fad060ace7e8dda79b87a1cbc3879e67e15f8255e788a8ebfaa","f0b6c900097e733eee79bc3d13722ecbbe35997d7bc25b0a79185a7dc17b5828","0a4ab7948650cf31fcbc3f2d9e0428f258cdd0b4a8530693b25ca9b15e955b04"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"importsNotUsedAsValues":2,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":true,"target":99},"fileIdsList":[[55,56,57,58,59,60,87,88,89,90,91],[56,86,92],[56],[55,56,90],[56,58],[56,86],[55],[51],[46,47,48,49,50,51],[46,47,48,49,50,52],[51,52],[53],[45,53,54],[76],[61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85]],"referencedMap":[[92,1],[87,2],[88,3],[91,4],[58,3],[57,3],[60,3],[59,5],[89,6],[90,7],[46,8],[50,8],[49,8],[48,8],[52,9],[47,8],[51,10],[53,11],[54,12],[55,13],[77,14],[86,15]],"exportedModulesMap":[[92,1],[87,2],[88,3],[91,4],[58,3],[57,3],[60,3],[59,5],[89,6],[90,7],[46,8],[50,8],[49,8],[48,8],[52,9],[47,8],[51,10],[53,11],[54,12],[55,13],[77,14],[86,15]],"semanticDiagnosticsPerFile":[10,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,40,36,37,38,39,8,41,42,43,1,9,44,92,87,88,91,58,57,60,59,89,56,90,46,50,49,48,52,47,51,53,54,55,45,75,70,84,83,65,85,73,72,67,63,76,77,69,78,86,62,61,66,74,68,64,71,80,79,82,81]},"version":"4.4.2"}
|
|
1
|
+
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../i18n/build-types/sprintf.d.ts","../hooks/build-types/createaddhook.d.ts","../hooks/build-types/createremovehook.d.ts","../hooks/build-types/createhashook.d.ts","../hooks/build-types/createdoinghook.d.ts","../hooks/build-types/createdidhook.d.ts","../hooks/build-types/index.d.ts","../hooks/build-types/createhooks.d.ts","../i18n/build-types/create-i18n.d.ts","../i18n/build-types/default-i18n.d.ts","../i18n/build-types/index.d.ts","./src/types.ts","./src/middlewares/nonce.js","./src/middlewares/namespace-endpoint.js","./src/middlewares/root-url.js","../url/build-types/is-url.d.ts","../url/build-types/is-email.d.ts","../url/build-types/get-protocol.d.ts","../url/build-types/is-valid-protocol.d.ts","../url/build-types/get-authority.d.ts","../url/build-types/is-valid-authority.d.ts","../url/build-types/get-path.d.ts","../url/build-types/is-valid-path.d.ts","../url/build-types/get-query-string.d.ts","../url/build-types/build-query-string.d.ts","../url/build-types/is-valid-query-string.d.ts","../url/build-types/get-path-and-query-string.d.ts","../url/build-types/get-fragment.d.ts","../url/build-types/is-valid-fragment.d.ts","../url/build-types/add-query-args.d.ts","../url/build-types/get-query-arg.d.ts","../url/build-types/get-query-args.d.ts","../url/build-types/has-query-arg.d.ts","../url/build-types/remove-query-args.d.ts","../url/build-types/prepend-http.d.ts","../url/build-types/safe-decode-uri.d.ts","../url/build-types/safe-decode-uri-component.d.ts","../url/build-types/filter-url-for-display.d.ts","../url/build-types/clean-for-slug.d.ts","../url/build-types/get-filename.d.ts","../url/build-types/normalize-path.d.ts","../url/build-types/index.d.ts","./src/middlewares/preloading.js","./src/middlewares/fetch-all-middleware.js","./src/middlewares/http-v1.js","./src/middlewares/user-locale.js","./src/utils/response.js","./src/middlewares/media-upload.js","./src/index.js"],"fileInfos":[{"version":"aa9fb4c70f369237c2f45f9d969c9a59e0eae9a192962eb48581fe864aa609db","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940","eb75e89d63b3b72dd9ca8b0cac801cecae5be352307c004adeaa60bc9d6df51f","2cc028cd0bdb35b1b5eb723d84666a255933fffbea607f72cbd0c7c7b4bee144",{"version":"e54c8715a4954cfdc66cd69489f2b725c09ebf37492dbd91cff0a1688b1159e8","affectsGlobalScope":true},{"version":"51b8b27c21c066bf877646e320bf6a722b80d1ade65e686923cd9d4494aef1ca","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"2c8c5ee58f30e7c944e04ab1fb5506fdbb4dd507c9efa6972cf4b91cec90c503","affectsGlobalScope":true},{"version":"2bb4b3927299434052b37851a47bf5c39764f2ba88a888a107b32262e9292b7c","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"93544ca2f26a48716c1b6c5091842cad63129daac422dfa4bc52460465f22bb1","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"7435b75fdf3509622e79622dbe5091cf4b09688410ee2034e4fc17d0c99d0862","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"9f1817f7c3f02f6d56e0f403b927e90bb133f371dcebc36fa7d6d208ef6899da","affectsGlobalScope":true},{"version":"cd6efb9467a8b6338ece2e2855e37765700f2cd061ca54b01b33878cf5c7677e","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"4632665b87204bb1caa8b44d165bce0c50dfab177df5b561b345a567cabacf9a","affectsGlobalScope":true},"762bc52248d3fab9873c7af564caf622358312cb35de42a4393b71cc36e14621","d02ec79cefaf292fae64b3be5a4416e64b4e420a6429fd458fac6e1bb4c7950e","27abed653f600ea0d5c86e94181beb42824e0f3f16337e2f9e7e9e9c2c392edf","d7871e0e653aa7197fee88886db5678bee6d42164c1f36e4bce9421ddfa7ca49","11ed10bdb3bcc99893570507eac8fece4840add97ee1d4f5a7fbf41cbfdea0d4","429fb571d3db07d3eaa2e74d43eb4190ece3e0de832ed564aeeaf08873e598eb","406d52bf33d618d846aa0d831ee004290567e328edcd4517bbff2937cc977abf","d3060e0810fc0d0dc009e6f086ef413d3c8aeaaf07da25c8d25fd4e181646acf","9d8f457905054b69915abac57f33e356fdcebce3a10e5be7fcfccad5da5aa934","08f7e6ffa66c66a636aecc5acbeb998215d9d09ccba0c558afb7df7e218edeaf","f829eb39aea4487f0ff94a42c56a1a73bc5202bbdeb03f7a638e4ab3e290d017","d8c4f047684abe4a04c0f6bfc2dfca7b191c4bc7856f2bf63c0b8c04d3c3c59c","cea174bd7165f6473e9251e89b77677cc6fb980a0329964499ff39d7049941a9","3601498a0b299615d2b1871518f4e512837afa1ec33c10e5787c31297dba0e6b","b85af6a2052b84fadbe8e760359bec9d2cb765c404bab048d4bd20477c02bd89","91265e9c2705df9edc7d912afe177cb9dbe4bd4fe254cc43466885544c065013","81e7db9916d6ce0323656530cb9aba444450454e5a8f3d0108f04931abb36258","7858aa21ac91fef2c9cdf96b3ae00e025efed2920ffca40a75df452d4f5a9576","eb80dedcd92c17d93f403e736e1c3e2aef39379841070221a353a7c13b57369f","029f3a1e2534e85a7cd00f3e79781003e0bcf5147d96db93594ace839803c6cf","2eea9984a7ea08e576d2970ba65a65ebba02699bccdbd0d3a08bb141e15972a1","308246446616acc5397747f35fa8788de7e6ba6cd5dc0ec2752bd75eafefcdb9","9677ef56e52539a73f1d9b89c692cf866d05017b05d9d2fe8cd35a30b42c2d47","6048b5c50d6486b1084b036a7f7d6c76c032d90cc2186f79b344a12ceb488511","26885abe66e07fd38da599d5fc9b4fa8b2df803c56e9bba99a2505e0b982c042","507dc7647a71c90e8cce85259c624b355c22e0dee1833aa4ba20c15a4f5bd21a","c30aaf3d189be8c29b2d3a7761e94b5b532fec6ba0caa74d07a4c1056469acf0","454217fe7beba4cb5497d4bc7fd3116437ce85e5217eb66f3b367fbcbfd45861","65e1ffb7b2343a1814c5cb85164f7d26bce1477b2cf04e6736f37732bc4801d6","3f810d7cac3e3729241d52d667538dc4ca27687f5d40d91f4cb5bce955df5f94","a2bedf5636ce572e507823229c9b7d4e87d97830497822d76e95a971fee78c92","17ab13eba7cde42ca7c95110c7eda405ba6aba7471437d912078d67dfada98eb","f7e734ca25cb0e8c52247b9a7d98f81ffd6ac52485bf9d8938fdbd4d828f469c","5261283f0b521fc1f255a060dcd86986985bd516822b69bb5504392462962899","44e20ca481bcc2abec1f4fcf54139caa4389f1bc16e3ee9d19a10e522903e9ab","a31eda6fcbf86596f69f7c18e6d13af58191fdc9c9620bcc67595fd9e49043ab","c93085fa9e5e568c0a45f64caa05e713fd5438e93d32f5970753e44910bdd540","1e442333978b5864818023d54d4f2e2aa0cbdfb2b486a0d43c900a7a87d61d1d","f215ce6766668f37f5e4652d0facdf55816f24aa5fc6f68c5e33754dbe5219fb","e900ec60297a15c4de70ddaade026ea4fe635e27c286fedd82dd5e963daa1930","e4e975c7339a9579209f12246e95f95216aa3558b8e7719fea2fbadaf28c574b","178efee8d4335cb61ec45c10e6de6d7afe48028963c5633f5937f25eaffa2387","3a8529919402692ba4d41e026e99cad2ed9a0141a7c55ab5cb3ab1cf93b7b3cd","73df30672e4cf303ecaa5bd1c0a228aec9bd972305b227ac47e53600b88eeb09","86113173dcf3a28562ae7493a30168e671b54a413095025d40eb462ebc55a4b5","e2ca321ccf84538d48bc2b24db351997d607695d37b6d6d50440385c8bffa7bc","b24db76807128fad060ace7e8dda79b87a1cbc3879e67e15f8255e788a8ebfaa","8947b5182e734afd1d79ac20b1a0856f6ece9924fe1c6a5163d4a117384c7b35","0a4ab7948650cf31fcbc3f2d9e0428f258cdd0b4a8530693b25ca9b15e955b04"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"importsNotUsedAsValues":2,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":true,"target":99},"fileIdsList":[[55,56,57,58,59,87,88,89,90,91,92],[56,86,93],[56],[55,56,91],[56,86],[56,58],[55],[51],[46,47,48,49,50,51],[46,47,48,49,50,52],[51,52],[53],[45,53,54],[75],[60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85]],"referencedMap":[[93,1],[88,2],[89,3],[92,4],[58,3],[57,3],[87,5],[59,6],[90,5],[91,7],[46,8],[50,8],[49,8],[48,8],[52,9],[47,8],[51,10],[53,11],[54,12],[55,13],[76,14],[86,15]],"exportedModulesMap":[[93,1],[88,2],[89,3],[92,4],[58,3],[57,3],[87,5],[59,6],[90,5],[91,7],[46,8],[50,8],[49,8],[48,8],[52,9],[47,8],[51,10],[53,11],[54,12],[55,13],[76,14],[86,15]],"semanticDiagnosticsPerFile":[10,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,40,36,37,38,39,8,41,42,43,1,9,44,93,88,89,92,58,57,87,59,90,56,91,46,50,49,48,52,47,51,53,54,55,45,74,69,83,82,64,84,72,71,66,62,75,76,68,77,86,61,60,65,73,67,63,70,85,79,78,81,80]},"version":"4.4.2"}
|