@wordpress/api-fetch 7.31.1-next.f56bd8138.0 → 7.32.1-next.47f435fc9.0
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 +2 -0
- package/build/index.js +112 -145
- package/build/index.js.map +7 -1
- package/build/middlewares/fetch-all-middleware.js +48 -81
- package/build/middlewares/fetch-all-middleware.js.map +7 -1
- package/build/middlewares/http-v1.js +29 -38
- package/build/middlewares/http-v1.js.map +7 -1
- package/build/middlewares/media-upload.js +43 -49
- package/build/middlewares/media-upload.js.map +7 -1
- package/build/middlewares/namespace-endpoint.js +27 -14
- package/build/middlewares/namespace-endpoint.js.map +7 -1
- package/build/middlewares/nonce.js +26 -23
- package/build/middlewares/nonce.js.map +7 -1
- package/build/middlewares/preloading.js +63 -60
- package/build/middlewares/preloading.js.map +7 -1
- package/build/middlewares/root-url.js +42 -27
- package/build/middlewares/root-url.js.map +7 -1
- package/build/middlewares/theme-preview.js +49 -38
- package/build/middlewares/theme-preview.js.map +7 -1
- package/build/middlewares/user-locale.js +28 -23
- package/build/middlewares/user-locale.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/response.js +31 -39
- package/build/utils/response.js.map +7 -1
- package/build-module/index.js +76 -121
- package/build-module/index.js.map +7 -1
- package/build-module/middlewares/fetch-all-middleware.js +16 -71
- package/build-module/middlewares/fetch-all-middleware.js.map +7 -1
- package/build-module/middlewares/http-v1.js +11 -34
- package/build-module/middlewares/http-v1.js.map +7 -1
- package/build-module/middlewares/media-upload.js +27 -43
- package/build-module/middlewares/media-upload.js.map +7 -1
- package/build-module/middlewares/namespace-endpoint.js +9 -10
- package/build-module/middlewares/namespace-endpoint.js.map +7 -1
- package/build-module/middlewares/nonce.js +8 -19
- package/build-module/middlewares/nonce.js.map +7 -1
- package/build-module/middlewares/preloading.js +43 -54
- package/build-module/middlewares/preloading.js.map +7 -1
- package/build-module/middlewares/root-url.js +14 -23
- package/build-module/middlewares/root-url.js.map +7 -1
- package/build-module/middlewares/theme-preview.js +29 -31
- package/build-module/middlewares/theme-preview.js.map +7 -1
- package/build-module/middlewares/user-locale.js +10 -19
- package/build-module/middlewares/user-locale.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/response.js +10 -36
- package/build-module/utils/response.js.map +7 -1
- package/package.json +13 -5
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/media-upload.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tparseAndThrowError,\n\tparseResponseAndNormalizeError,\n} from '../utils/response';\nimport type { APIFetchOptions, APIFetchMiddleware } from '../types';\n\n/**\n * @param options\n * @return True if the request is for media upload.\n */\nfunction isMediaUploadRequest( options: APIFetchOptions ) {\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 * @param options\n * @param next\n */\nconst mediaUploadMiddleware: APIFetchMiddleware = ( 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 attachmentId\n\t * @return Processed post response.\n\t */\n\tconst postProcess = ( attachmentId: string ): Promise< any > => {\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: Response ) => {\n\t\t\t// `response` could actually be an error thrown by `defaultFetchHandler`.\n\t\t\tif ( ! ( response instanceof globalThis.Response ) ) {\n\t\t\t\treturn Promise.reject( response );\n\t\t\t}\n\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: Response ) =>\n\t\t\tparseResponseAndNormalizeError( response, options.parse )\n\t\t);\n};\n\nexport default mediaUploadMiddleware;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU;AAKnB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAOP,SAAS,qBAAsB,SAA2B;AACzD,QAAM,iBAAiB,CAAC,CAAE,QAAQ,UAAU,QAAQ,WAAW;AAC/D,QAAM,kBACH,CAAC,CAAE,QAAQ,QAAQ,QAAQ,KAAK,QAAS,cAAe,MAAM,MAC9D,CAAC,CAAE,QAAQ,OAAO,QAAQ,IAAI,QAAS,cAAe,MAAM;AAE/D,SAAO,mBAAmB;AAC3B;AAOA,MAAM,wBAA4C,CAAE,SAAS,SAAU;AACtE,MAAK,CAAE,qBAAsB,OAAQ,GAAI;AACxC,WAAO,KAAM,OAAQ;AAAA,EACtB;AAEA,MAAI,UAAU;AACd,QAAM,aAAa;AAMnB,QAAM,cAAc,CAAE,iBAA0C;AAC/D;AACA,WAAO,KAAM;AAAA,MACZ,MAAM,gBAAiB,YAAa;AAAA,MACpC,QAAQ;AAAA,MACR,MAAM,EAAE,QAAQ,wBAAwB;AAAA,MACxC,OAAO;AAAA,IACR,CAAE,EAAE,MAAO,MAAM;AAChB,UAAK,UAAU,YAAa;AAC3B,eAAO,YAAa,YAAa;AAAA,MAClC;AACA,WAAM;AAAA,QACL,MAAM,gBAAiB,YAAa;AAAA,QACpC,QAAQ;AAAA,MACT,CAAE;AAEF,aAAO,QAAQ,OAAO;AAAA,IACvB,CAAE;AAAA,EACH;AAEA,SAAO,KAAM,EAAE,GAAG,SAAS,OAAO,MAAM,CAAE,EACxC,MAAO,CAAE,aAAwB;AAEjC,QAAK,EAAI,oBAAoB,WAAW,WAAa;AACpD,aAAO,QAAQ,OAAQ,QAAS;AAAA,IACjC;AAEA,UAAM,eAAe,SAAS,QAAQ;AAAA,MACrC;AAAA,IACD;AACA,QACC,SAAS,UAAU,OACnB,SAAS,SAAS,OAClB,cACC;AACD,aAAO,YAAa,YAAa,EAAE,MAAO,MAAM;AAC/C,YAAK,QAAQ,UAAU,OAAQ;AAC9B,iBAAO,QAAQ,OAAQ;AAAA,YACtB,MAAM;AAAA,YACN,SAAS;AAAA,cACR;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAEA,eAAO,QAAQ,OAAQ,QAAS;AAAA,MACjC,CAAE;AAAA,IACH;AACA,WAAO,mBAAoB,UAAU,QAAQ,KAAM;AAAA,EACpD,CAAE,EACD;AAAA,IAAM,CAAE,aACR,+BAAgC,UAAU,QAAQ,KAAM;AAAA,EACzD;AACF;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
const namespaceAndEndpointMiddleware = (options, next) => {
|
|
6
2
|
let path = options.path;
|
|
7
3
|
let namespaceTrimmed, endpointTrimmed;
|
|
8
|
-
if (typeof options.namespace ===
|
|
9
|
-
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g,
|
|
10
|
-
endpointTrimmed = options.endpoint.replace(/^\//,
|
|
4
|
+
if (typeof options.namespace === "string" && typeof options.endpoint === "string") {
|
|
5
|
+
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, "");
|
|
6
|
+
endpointTrimmed = options.endpoint.replace(/^\//, "");
|
|
11
7
|
if (endpointTrimmed) {
|
|
12
|
-
path = namespaceTrimmed +
|
|
8
|
+
path = namespaceTrimmed + "/" + endpointTrimmed;
|
|
13
9
|
} else {
|
|
14
10
|
path = namespaceTrimmed;
|
|
15
11
|
}
|
|
@@ -21,5 +17,8 @@ const namespaceAndEndpointMiddleware = (options, next) => {
|
|
|
21
17
|
path
|
|
22
18
|
});
|
|
23
19
|
};
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
var namespace_endpoint_default = namespaceAndEndpointMiddleware;
|
|
21
|
+
export {
|
|
22
|
+
namespace_endpoint_default as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=namespace-endpoint.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/namespace-endpoint.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\nconst namespaceAndEndpointMiddleware: APIFetchMiddleware = (\n\toptions,\n\tnext\n) => {\n\tlet path = options.path;\n\tlet namespaceTrimmed, endpointTrimmed;\n\n\tif (\n\t\ttypeof options.namespace === 'string' &&\n\t\ttypeof options.endpoint === 'string'\n\t) {\n\t\tnamespaceTrimmed = options.namespace.replace( /^\\/|\\/$/g, '' );\n\t\tendpointTrimmed = options.endpoint.replace( /^\\//, '' );\n\t\tif ( endpointTrimmed ) {\n\t\t\tpath = namespaceTrimmed + '/' + endpointTrimmed;\n\t\t} else {\n\t\t\tpath = namespaceTrimmed;\n\t\t}\n\t}\n\n\tdelete options.namespace;\n\tdelete options.endpoint;\n\n\treturn next( {\n\t\t...options,\n\t\tpath,\n\t} );\n};\n\nexport default namespaceAndEndpointMiddleware;\n"],
|
|
5
|
+
"mappings": "AAKA,MAAM,iCAAqD,CAC1D,SACA,SACI;AACJ,MAAI,OAAO,QAAQ;AACnB,MAAI,kBAAkB;AAEtB,MACC,OAAO,QAAQ,cAAc,YAC7B,OAAO,QAAQ,aAAa,UAC3B;AACD,uBAAmB,QAAQ,UAAU,QAAS,YAAY,EAAG;AAC7D,sBAAkB,QAAQ,SAAS,QAAS,OAAO,EAAG;AACtD,QAAK,iBAAkB;AACtB,aAAO,mBAAmB,MAAM;AAAA,IACjC,OAAO;AACN,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO,QAAQ;AACf,SAAO,QAAQ;AAEf,SAAO,KAAM;AAAA,IACZ,GAAG;AAAA,IACH;AAAA,EACD,CAAE;AACH;AAEA,IAAO,6BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param nonce
|
|
7
|
-
*
|
|
8
|
-
* @return A middleware to enhance a request with a nonce.
|
|
9
|
-
*/
|
|
10
1
|
function createNonceMiddleware(nonce) {
|
|
11
2
|
const middleware = (options, next) => {
|
|
12
|
-
const {
|
|
13
|
-
headers = {}
|
|
14
|
-
} = options;
|
|
15
|
-
|
|
16
|
-
// If an 'X-WP-Nonce' header (or any case-insensitive variation
|
|
17
|
-
// thereof) was specified, no need to add a nonce header.
|
|
3
|
+
const { headers = {} } = options;
|
|
18
4
|
for (const headerName in headers) {
|
|
19
|
-
if (headerName.toLowerCase() ===
|
|
5
|
+
if (headerName.toLowerCase() === "x-wp-nonce" && headers[headerName] === middleware.nonce) {
|
|
20
6
|
return next(options);
|
|
21
7
|
}
|
|
22
8
|
}
|
|
@@ -24,12 +10,15 @@ function createNonceMiddleware(nonce) {
|
|
|
24
10
|
...options,
|
|
25
11
|
headers: {
|
|
26
12
|
...headers,
|
|
27
|
-
|
|
13
|
+
"X-WP-Nonce": middleware.nonce
|
|
28
14
|
}
|
|
29
15
|
});
|
|
30
16
|
};
|
|
31
17
|
middleware.nonce = nonce;
|
|
32
18
|
return middleware;
|
|
33
19
|
}
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
var nonce_default = createNonceMiddleware;
|
|
21
|
+
export {
|
|
22
|
+
nonce_default as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=nonce.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/nonce.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\n/**\n * @param nonce\n *\n * @return A middleware to enhance a request with a nonce.\n */\nfunction createNonceMiddleware(\n\tnonce: string\n): APIFetchMiddleware & { nonce: string } {\n\tconst middleware: APIFetchMiddleware & { nonce: string } = (\n\t\toptions,\n\t\tnext\n\t) => {\n\t\tconst { headers = {} } = options;\n\n\t\t// If an 'X-WP-Nonce' header (or any case-insensitive variation\n\t\t// thereof) was specified, no need to add a nonce header.\n\t\tfor ( const headerName in headers ) {\n\t\t\tif (\n\t\t\t\theaderName.toLowerCase() === 'x-wp-nonce' &&\n\t\t\t\theaders[ headerName ] === middleware.nonce\n\t\t\t) {\n\t\t\t\treturn next( options );\n\t\t\t}\n\t\t}\n\n\t\treturn next( {\n\t\t\t...options,\n\t\t\theaders: {\n\t\t\t\t...headers,\n\t\t\t\t'X-WP-Nonce': middleware.nonce,\n\t\t\t},\n\t\t} );\n\t};\n\n\tmiddleware.nonce = nonce;\n\n\treturn middleware;\n}\n\nexport default createNonceMiddleware;\n"],
|
|
5
|
+
"mappings": "AAUA,SAAS,sBACR,OACyC;AACzC,QAAM,aAAqD,CAC1D,SACA,SACI;AACJ,UAAM,EAAE,UAAU,CAAC,EAAE,IAAI;AAIzB,eAAY,cAAc,SAAU;AACnC,UACC,WAAW,YAAY,MAAM,gBAC7B,QAAS,UAAW,MAAM,WAAW,OACpC;AACD,eAAO,KAAM,OAAQ;AAAA,MACtB;AAAA,IACD;AAEA,WAAO,KAAM;AAAA,MACZ,GAAG;AAAA,MACH,SAAS;AAAA,QACR,GAAG;AAAA,QACH,cAAc,WAAW;AAAA,MAC1B;AAAA,IACD,CAAE;AAAA,EACH;AAEA,aAAW,QAAQ;AAEnB,SAAO;AACR;AAEA,IAAO,gBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,84 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param preloadedData
|
|
12
|
-
* @return Preloading middleware.
|
|
13
|
-
*/
|
|
1
|
+
import { addQueryArgs, getQueryArgs, normalizePath } from "@wordpress/url";
|
|
14
2
|
function createPreloadingMiddleware(preloadedData) {
|
|
15
|
-
const cache = Object.fromEntries(
|
|
3
|
+
const cache = Object.fromEntries(
|
|
4
|
+
Object.entries(preloadedData).map(([path, data]) => [
|
|
5
|
+
normalizePath(path),
|
|
6
|
+
data
|
|
7
|
+
])
|
|
8
|
+
);
|
|
16
9
|
return (options, next) => {
|
|
17
|
-
const {
|
|
18
|
-
parse = true
|
|
19
|
-
} = options;
|
|
10
|
+
const { parse = true } = options;
|
|
20
11
|
let rawPath = options.path;
|
|
21
12
|
if (!rawPath && options.url) {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (typeof pathFromQuery === 'string') {
|
|
13
|
+
const { rest_route: pathFromQuery, ...queryArgs } = getQueryArgs(
|
|
14
|
+
options.url
|
|
15
|
+
);
|
|
16
|
+
if (typeof pathFromQuery === "string") {
|
|
27
17
|
rawPath = addQueryArgs(pathFromQuery, queryArgs);
|
|
28
18
|
}
|
|
29
19
|
}
|
|
30
|
-
if (typeof rawPath !==
|
|
20
|
+
if (typeof rawPath !== "string") {
|
|
31
21
|
return next(options);
|
|
32
22
|
}
|
|
33
|
-
const method = options.method ||
|
|
23
|
+
const method = options.method || "GET";
|
|
34
24
|
const path = normalizePath(rawPath);
|
|
35
|
-
if (
|
|
25
|
+
if ("GET" === method && cache[path]) {
|
|
36
26
|
const cacheData = cache[path];
|
|
37
|
-
|
|
38
|
-
// Unsetting the cache key ensures that the data is only used a single time.
|
|
39
27
|
delete cache[path];
|
|
40
28
|
return prepareResponse(cacheData, !!parse);
|
|
41
|
-
} else if (
|
|
29
|
+
} else if ("OPTIONS" === method && cache[method] && cache[method][path]) {
|
|
42
30
|
const cacheData = cache[method][path];
|
|
43
|
-
|
|
44
|
-
// Unsetting the cache key ensures that the data is only used a single time.
|
|
45
31
|
delete cache[method][path];
|
|
46
32
|
return prepareResponse(cacheData, !!parse);
|
|
47
33
|
}
|
|
48
34
|
return next(options);
|
|
49
35
|
};
|
|
50
36
|
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* This is a helper function that sends a success response.
|
|
54
|
-
*
|
|
55
|
-
* @param responseData
|
|
56
|
-
* @param parse
|
|
57
|
-
* @return Promise with the response.
|
|
58
|
-
*/
|
|
59
37
|
function prepareResponse(responseData, parse) {
|
|
60
38
|
if (parse) {
|
|
61
39
|
return Promise.resolve(responseData.body);
|
|
62
40
|
}
|
|
63
41
|
try {
|
|
64
|
-
return Promise.resolve(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
return Promise.resolve(
|
|
43
|
+
new window.Response(JSON.stringify(responseData.body), {
|
|
44
|
+
status: 200,
|
|
45
|
+
statusText: "OK",
|
|
46
|
+
headers: responseData.headers
|
|
47
|
+
})
|
|
48
|
+
);
|
|
69
49
|
} catch {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
50
|
+
Object.entries(
|
|
51
|
+
responseData.headers
|
|
52
|
+
).forEach(([key, value]) => {
|
|
53
|
+
if (key.toLowerCase() === "link") {
|
|
54
|
+
responseData.headers[key] = value.replace(
|
|
55
|
+
/<([^>]+)>/,
|
|
56
|
+
(_, url) => `<${encodeURI(url)}>`
|
|
57
|
+
);
|
|
74
58
|
}
|
|
75
59
|
});
|
|
76
|
-
return Promise.resolve(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
return Promise.resolve(
|
|
61
|
+
parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
|
|
62
|
+
status: 200,
|
|
63
|
+
statusText: "OK",
|
|
64
|
+
headers: responseData.headers
|
|
65
|
+
})
|
|
66
|
+
);
|
|
81
67
|
}
|
|
82
68
|
}
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
var preloading_default = createPreloadingMiddleware;
|
|
70
|
+
export {
|
|
71
|
+
preloading_default as default
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=preloading.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/preloading.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\n/**\n * @param preloadedData\n * @return Preloading middleware.\n */\nfunction createPreloadingMiddleware(\n\tpreloadedData: Record< string, any >\n): APIFetchMiddleware {\n\tconst cache = Object.fromEntries(\n\t\tObject.entries( preloadedData ).map( ( [ path, data ] ) => [\n\t\t\tnormalizePath( path ),\n\t\t\tdata,\n\t\t] )\n\t);\n\n\treturn ( options, next ) => {\n\t\tconst { parse = true } = options;\n\t\tlet rawPath = options.path;\n\t\tif ( ! rawPath && options.url ) {\n\t\t\tconst { rest_route: pathFromQuery, ...queryArgs } = getQueryArgs(\n\t\t\t\toptions.url\n\t\t\t);\n\n\t\t\tif ( typeof pathFromQuery === 'string' ) {\n\t\t\t\trawPath = addQueryArgs( pathFromQuery, queryArgs );\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof rawPath !== 'string' ) {\n\t\t\treturn next( options );\n\t\t}\n\n\t\tconst method = options.method || 'GET';\n\t\tconst path = normalizePath( rawPath );\n\n\t\tif ( 'GET' === method && cache[ path ] ) {\n\t\t\tconst cacheData = cache[ path ];\n\n\t\t\t// Unsetting the cache key ensures that the data is only used a single time.\n\t\t\tdelete cache[ path ];\n\n\t\t\treturn prepareResponse( cacheData, !! parse );\n\t\t} else if (\n\t\t\t'OPTIONS' === method &&\n\t\t\tcache[ method ] &&\n\t\t\tcache[ method ][ path ]\n\t\t) {\n\t\t\tconst cacheData = cache[ method ][ path ];\n\n\t\t\t// Unsetting the cache key ensures that the data is only used a single time.\n\t\t\tdelete cache[ method ][ path ];\n\n\t\t\treturn prepareResponse( cacheData, !! parse );\n\t\t}\n\n\t\treturn next( options );\n\t};\n}\n\n/**\n * This is a helper function that sends a success response.\n *\n * @param responseData\n * @param parse\n * @return Promise with the response.\n */\nfunction prepareResponse(\n\tresponseData: Record< string, any >,\n\tparse: boolean\n) {\n\tif ( parse ) {\n\t\treturn Promise.resolve( responseData.body );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve(\n\t\t\tnew window.Response( JSON.stringify( responseData.body ), {\n\t\t\t\tstatus: 200,\n\t\t\t\tstatusText: 'OK',\n\t\t\t\theaders: responseData.headers,\n\t\t\t} )\n\t\t);\n\t} catch {\n\t\t// See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926.\n\t\tObject.entries(\n\t\t\tresponseData.headers as Record< string, string >\n\t\t).forEach( ( [ key, value ] ) => {\n\t\t\tif ( key.toLowerCase() === 'link' ) {\n\t\t\t\tresponseData.headers[ key ] = value.replace(\n\t\t\t\t\t/<([^>]+)>/,\n\t\t\t\t\t( _, url ) => `<${ encodeURI( url ) }>`\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t\treturn Promise.resolve(\n\t\t\tparse\n\t\t\t\t? responseData.body\n\t\t\t\t: new window.Response( JSON.stringify( responseData.body ), {\n\t\t\t\t\t\tstatus: 200,\n\t\t\t\t\t\tstatusText: 'OK',\n\t\t\t\t\t\theaders: responseData.headers,\n\t\t\t\t } )\n\t\t);\n\t}\n}\n\nexport default createPreloadingMiddleware;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,cAAc,cAAc,qBAAqB;AAW1D,SAAS,2BACR,eACqB;AACrB,QAAM,QAAQ,OAAO;AAAA,IACpB,OAAO,QAAS,aAAc,EAAE,IAAK,CAAE,CAAE,MAAM,IAAK,MAAO;AAAA,MAC1D,cAAe,IAAK;AAAA,MACpB;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO,CAAE,SAAS,SAAU;AAC3B,UAAM,EAAE,QAAQ,KAAK,IAAI;AACzB,QAAI,UAAU,QAAQ;AACtB,QAAK,CAAE,WAAW,QAAQ,KAAM;AAC/B,YAAM,EAAE,YAAY,eAAe,GAAG,UAAU,IAAI;AAAA,QACnD,QAAQ;AAAA,MACT;AAEA,UAAK,OAAO,kBAAkB,UAAW;AACxC,kBAAU,aAAc,eAAe,SAAU;AAAA,MAClD;AAAA,IACD;AAEA,QAAK,OAAO,YAAY,UAAW;AAClC,aAAO,KAAM,OAAQ;AAAA,IACtB;AAEA,UAAM,SAAS,QAAQ,UAAU;AACjC,UAAM,OAAO,cAAe,OAAQ;AAEpC,QAAK,UAAU,UAAU,MAAO,IAAK,GAAI;AACxC,YAAM,YAAY,MAAO,IAAK;AAG9B,aAAO,MAAO,IAAK;AAEnB,aAAO,gBAAiB,WAAW,CAAC,CAAE,KAAM;AAAA,IAC7C,WACC,cAAc,UACd,MAAO,MAAO,KACd,MAAO,MAAO,EAAG,IAAK,GACrB;AACD,YAAM,YAAY,MAAO,MAAO,EAAG,IAAK;AAGxC,aAAO,MAAO,MAAO,EAAG,IAAK;AAE7B,aAAO,gBAAiB,WAAW,CAAC,CAAE,KAAM;AAAA,IAC7C;AAEA,WAAO,KAAM,OAAQ;AAAA,EACtB;AACD;AASA,SAAS,gBACR,cACA,OACC;AACD,MAAK,OAAQ;AACZ,WAAO,QAAQ,QAAS,aAAa,IAAK;AAAA,EAC3C;AAEA,MAAI;AACH,WAAO,QAAQ;AAAA,MACd,IAAI,OAAO,SAAU,KAAK,UAAW,aAAa,IAAK,GAAG;AAAA,QACzD,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,SAAS,aAAa;AAAA,MACvB,CAAE;AAAA,IACH;AAAA,EACD,QAAQ;AAEP,WAAO;AAAA,MACN,aAAa;AAAA,IACd,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AAChC,UAAK,IAAI,YAAY,MAAM,QAAS;AACnC,qBAAa,QAAS,GAAI,IAAI,MAAM;AAAA,UACnC;AAAA,UACA,CAAE,GAAG,QAAS,IAAK,UAAW,GAAI,CAAE;AAAA,QACrC;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,QAAQ;AAAA,MACd,QACG,aAAa,OACb,IAAI,OAAO,SAAU,KAAK,UAAW,aAAa,IAAK,GAAG;AAAA,QAC1D,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,SAAS,aAAa;AAAA,MACtB,CAAE;AAAA,IACN;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import namespaceAndEndpointMiddleware from './namespace-endpoint';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param rootURL
|
|
9
|
-
* @return Root URL middleware.
|
|
10
|
-
*/
|
|
11
|
-
const createRootURLMiddleware = rootURL => (options, next) => {
|
|
12
|
-
return namespaceAndEndpointMiddleware(options, optionsWithPath => {
|
|
1
|
+
import namespaceAndEndpointMiddleware from "./namespace-endpoint";
|
|
2
|
+
const createRootURLMiddleware = (rootURL) => (options, next) => {
|
|
3
|
+
return namespaceAndEndpointMiddleware(options, (optionsWithPath) => {
|
|
13
4
|
let url = optionsWithPath.url;
|
|
14
5
|
let path = optionsWithPath.path;
|
|
15
6
|
let apiRoot;
|
|
16
|
-
if (typeof path ===
|
|
7
|
+
if (typeof path === "string") {
|
|
17
8
|
apiRoot = rootURL;
|
|
18
|
-
if (-1 !== rootURL.indexOf(
|
|
19
|
-
path = path.replace(
|
|
9
|
+
if (-1 !== rootURL.indexOf("?")) {
|
|
10
|
+
path = path.replace("?", "&");
|
|
20
11
|
}
|
|
21
|
-
path = path.replace(/^\//,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// configured to use plain permalinks.
|
|
25
|
-
if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
|
|
26
|
-
path = path.replace('?', '&');
|
|
12
|
+
path = path.replace(/^\//, "");
|
|
13
|
+
if ("string" === typeof apiRoot && -1 !== apiRoot.indexOf("?")) {
|
|
14
|
+
path = path.replace("?", "&");
|
|
27
15
|
}
|
|
28
16
|
url = apiRoot + path;
|
|
29
17
|
}
|
|
@@ -33,5 +21,8 @@ const createRootURLMiddleware = rootURL => (options, next) => {
|
|
|
33
21
|
});
|
|
34
22
|
});
|
|
35
23
|
};
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
var root_url_default = createRootURLMiddleware;
|
|
25
|
+
export {
|
|
26
|
+
root_url_default as default
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=root-url.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/root-url.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\nimport namespaceAndEndpointMiddleware from './namespace-endpoint';\n\n/**\n * @param rootURL\n * @return Root URL middleware.\n */\nconst createRootURLMiddleware =\n\t( rootURL: string ): APIFetchMiddleware =>\n\t( options, next ) => {\n\t\treturn namespaceAndEndpointMiddleware( options, ( optionsWithPath ) => {\n\t\t\tlet url = optionsWithPath.url;\n\t\t\tlet path = optionsWithPath.path;\n\t\t\tlet apiRoot;\n\n\t\t\tif ( typeof path === 'string' ) {\n\t\t\t\tapiRoot = rootURL;\n\n\t\t\t\tif ( -1 !== rootURL.indexOf( '?' ) ) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\tpath = path.replace( /^\\//, '' );\n\n\t\t\t\t// API root may already include query parameter prefix if site is\n\t\t\t\t// configured to use plain permalinks.\n\t\t\t\tif (\n\t\t\t\t\t'string' === typeof apiRoot &&\n\t\t\t\t\t-1 !== apiRoot.indexOf( '?' )\n\t\t\t\t) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\turl = apiRoot + path;\n\t\t\t}\n\n\t\t\treturn next( {\n\t\t\t\t...optionsWithPath,\n\t\t\t\turl,\n\t\t\t} );\n\t\t} );\n\t};\n\nexport default createRootURLMiddleware;\n"],
|
|
5
|
+
"mappings": "AAIA,OAAO,oCAAoC;AAM3C,MAAM,0BACL,CAAE,YACF,CAAE,SAAS,SAAU;AACpB,SAAO,+BAAgC,SAAS,CAAE,oBAAqB;AACtE,QAAI,MAAM,gBAAgB;AAC1B,QAAI,OAAO,gBAAgB;AAC3B,QAAI;AAEJ,QAAK,OAAO,SAAS,UAAW;AAC/B,gBAAU;AAEV,UAAK,OAAO,QAAQ,QAAS,GAAI,GAAI;AACpC,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,aAAO,KAAK,QAAS,OAAO,EAAG;AAI/B,UACC,aAAa,OAAO,WACpB,OAAO,QAAQ,QAAS,GAAI,GAC3B;AACD,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,YAAM,UAAU;AAAA,IACjB;AAEA,WAAO,KAAM;AAAA,MACZ,GAAG;AAAA,MACH;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACH;AAED,IAAO,mBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This appends a `wp_theme_preview` parameter to the REST API request URL if
|
|
11
|
-
* the admin URL contains a `theme` GET parameter.
|
|
12
|
-
*
|
|
13
|
-
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
|
|
14
|
-
* then bypass this middleware.
|
|
15
|
-
*
|
|
16
|
-
* @param themePath
|
|
17
|
-
* @return Preloading middleware.
|
|
18
|
-
*/
|
|
19
|
-
const createThemePreviewMiddleware = themePath => (options, next) => {
|
|
20
|
-
if (typeof options.url === 'string') {
|
|
21
|
-
const wpThemePreview = getQueryArg(options.url, 'wp_theme_preview');
|
|
22
|
-
if (wpThemePreview === undefined) {
|
|
1
|
+
import { addQueryArgs, getQueryArg, removeQueryArgs } from "@wordpress/url";
|
|
2
|
+
const createThemePreviewMiddleware = (themePath) => (options, next) => {
|
|
3
|
+
if (typeof options.url === "string") {
|
|
4
|
+
const wpThemePreview = getQueryArg(
|
|
5
|
+
options.url,
|
|
6
|
+
"wp_theme_preview"
|
|
7
|
+
);
|
|
8
|
+
if (wpThemePreview === void 0) {
|
|
23
9
|
options.url = addQueryArgs(options.url, {
|
|
24
10
|
wp_theme_preview: themePath
|
|
25
11
|
});
|
|
26
|
-
} else if (wpThemePreview ===
|
|
27
|
-
options.url = removeQueryArgs(
|
|
12
|
+
} else if (wpThemePreview === "") {
|
|
13
|
+
options.url = removeQueryArgs(
|
|
14
|
+
options.url,
|
|
15
|
+
"wp_theme_preview"
|
|
16
|
+
);
|
|
28
17
|
}
|
|
29
18
|
}
|
|
30
|
-
if (typeof options.path ===
|
|
31
|
-
const wpThemePreview = getQueryArg(
|
|
32
|
-
|
|
19
|
+
if (typeof options.path === "string") {
|
|
20
|
+
const wpThemePreview = getQueryArg(
|
|
21
|
+
options.path,
|
|
22
|
+
"wp_theme_preview"
|
|
23
|
+
);
|
|
24
|
+
if (wpThemePreview === void 0) {
|
|
33
25
|
options.path = addQueryArgs(options.path, {
|
|
34
26
|
wp_theme_preview: themePath
|
|
35
27
|
});
|
|
36
|
-
} else if (wpThemePreview ===
|
|
37
|
-
options.path = removeQueryArgs(
|
|
28
|
+
} else if (wpThemePreview === "") {
|
|
29
|
+
options.path = removeQueryArgs(
|
|
30
|
+
options.path,
|
|
31
|
+
"wp_theme_preview"
|
|
32
|
+
);
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
return next(options);
|
|
41
36
|
};
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
var theme_preview_default = createThemePreviewMiddleware;
|
|
38
|
+
export {
|
|
39
|
+
theme_preview_default as default
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=theme-preview.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/theme-preview.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url';\n/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\n/**\n * This appends a `wp_theme_preview` parameter to the REST API request URL if\n * the admin URL contains a `theme` GET parameter.\n *\n * If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,\n * then bypass this middleware.\n *\n * @param themePath\n * @return Preloading middleware.\n */\nconst createThemePreviewMiddleware =\n\t( themePath: Record< string, any > ): APIFetchMiddleware =>\n\t( options, next ) => {\n\t\tif ( typeof options.url === 'string' ) {\n\t\t\tconst wpThemePreview = getQueryArg(\n\t\t\t\toptions.url,\n\t\t\t\t'wp_theme_preview'\n\t\t\t);\n\t\t\tif ( wpThemePreview === undefined ) {\n\t\t\t\toptions.url = addQueryArgs( options.url, {\n\t\t\t\t\twp_theme_preview: themePath,\n\t\t\t\t} );\n\t\t\t} else if ( wpThemePreview === '' ) {\n\t\t\t\toptions.url = removeQueryArgs(\n\t\t\t\t\toptions.url,\n\t\t\t\t\t'wp_theme_preview'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof options.path === 'string' ) {\n\t\t\tconst wpThemePreview = getQueryArg(\n\t\t\t\toptions.path,\n\t\t\t\t'wp_theme_preview'\n\t\t\t);\n\t\t\tif ( wpThemePreview === undefined ) {\n\t\t\t\toptions.path = addQueryArgs( options.path, {\n\t\t\t\t\twp_theme_preview: themePath,\n\t\t\t\t} );\n\t\t\t} else if ( wpThemePreview === '' ) {\n\t\t\t\toptions.path = removeQueryArgs(\n\t\t\t\t\toptions.path,\n\t\t\t\t\t'wp_theme_preview'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn next( options );\n\t};\n\nexport default createThemePreviewMiddleware;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,cAAc,aAAa,uBAAuB;AAgB3D,MAAM,+BACL,CAAE,cACF,CAAE,SAAS,SAAU;AACpB,MAAK,OAAO,QAAQ,QAAQ,UAAW;AACtC,UAAM,iBAAiB;AAAA,MACtB,QAAQ;AAAA,MACR;AAAA,IACD;AACA,QAAK,mBAAmB,QAAY;AACnC,cAAQ,MAAM,aAAc,QAAQ,KAAK;AAAA,QACxC,kBAAkB;AAAA,MACnB,CAAE;AAAA,IACH,WAAY,mBAAmB,IAAK;AACnC,cAAQ,MAAM;AAAA,QACb,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAK,OAAO,QAAQ,SAAS,UAAW;AACvC,UAAM,iBAAiB;AAAA,MACtB,QAAQ;AAAA,MACR;AAAA,IACD;AACA,QAAK,mBAAmB,QAAY;AACnC,cAAQ,OAAO,aAAc,QAAQ,MAAM;AAAA,QAC1C,kBAAkB;AAAA,MACnB,CAAE;AAAA,IACH,WAAY,mBAAmB,IAAK;AACnC,cAAQ,OAAO;AAAA,QACd,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO,KAAM,OAAQ;AACtB;AAED,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { addQueryArgs, hasQueryArg } from '@wordpress/url';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
|
|
1
|
+
import { addQueryArgs, hasQueryArg } from "@wordpress/url";
|
|
10
2
|
const userLocaleMiddleware = (options, next) => {
|
|
11
|
-
if (typeof options.url ===
|
|
12
|
-
options.url = addQueryArgs(options.url, {
|
|
13
|
-
_locale: 'user'
|
|
14
|
-
});
|
|
3
|
+
if (typeof options.url === "string" && !hasQueryArg(options.url, "_locale")) {
|
|
4
|
+
options.url = addQueryArgs(options.url, { _locale: "user" });
|
|
15
5
|
}
|
|
16
|
-
if (typeof options.path ===
|
|
17
|
-
options.path = addQueryArgs(options.path, {
|
|
18
|
-
_locale: 'user'
|
|
19
|
-
});
|
|
6
|
+
if (typeof options.path === "string" && !hasQueryArg(options.path, "_locale")) {
|
|
7
|
+
options.path = addQueryArgs(options.path, { _locale: "user" });
|
|
20
8
|
}
|
|
21
9
|
return next(options);
|
|
22
10
|
};
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
var user_locale_default = userLocaleMiddleware;
|
|
12
|
+
export {
|
|
13
|
+
user_locale_default as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=user-locale.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/middlewares/user-locale.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, hasQueryArg } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\nconst userLocaleMiddleware: APIFetchMiddleware = ( options, next ) => {\n\tif (\n\t\ttypeof options.url === 'string' &&\n\t\t! hasQueryArg( options.url, '_locale' )\n\t) {\n\t\toptions.url = addQueryArgs( options.url, { _locale: 'user' } );\n\t}\n\n\tif (\n\t\ttypeof options.path === 'string' &&\n\t\t! hasQueryArg( options.path, '_locale' )\n\t) {\n\t\toptions.path = addQueryArgs( options.path, { _locale: 'user' } );\n\t}\n\n\treturn next( options );\n};\n\nexport default userLocaleMiddleware;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,cAAc,mBAAmB;AAO1C,MAAM,uBAA2C,CAAE,SAAS,SAAU;AACrE,MACC,OAAO,QAAQ,QAAQ,YACvB,CAAE,YAAa,QAAQ,KAAK,SAAU,GACrC;AACD,YAAQ,MAAM,aAAc,QAAQ,KAAK,EAAE,SAAS,OAAO,CAAE;AAAA,EAC9D;AAEA,MACC,OAAO,QAAQ,SAAS,YACxB,CAAE,YAAa,QAAQ,MAAM,SAAU,GACtC;AACD,YAAQ,OAAO,aAAc,QAAQ,MAAM,EAAE,SAAS,OAAO,CAAE;AAAA,EAChE;AAEA,SAAO,KAAM,OAAQ;AACtB;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": [],
|
|
4
|
+
"sourcesContent": [],
|
|
5
|
+
"mappings": "",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Calls the `json` function on the Response, throwing an error if the response
|
|
8
|
-
* doesn't have a json function or if parsing the json itself fails.
|
|
9
|
-
*
|
|
10
|
-
* @param response
|
|
11
|
-
* @return Parsed response.
|
|
12
|
-
*/
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
13
2
|
async function parseJsonAndNormalizeError(response) {
|
|
14
3
|
try {
|
|
15
4
|
return await response.json();
|
|
16
5
|
} catch {
|
|
17
6
|
throw {
|
|
18
|
-
code:
|
|
19
|
-
message: __(
|
|
7
|
+
code: "invalid_json",
|
|
8
|
+
message: __("The response is not a valid JSON response.")
|
|
20
9
|
};
|
|
21
10
|
}
|
|
22
11
|
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Parses the apiFetch response properly and normalize response errors.
|
|
26
|
-
*
|
|
27
|
-
* @param response
|
|
28
|
-
* @param shouldParseResponse
|
|
29
|
-
*
|
|
30
|
-
* @return Parsed response.
|
|
31
|
-
*/
|
|
32
|
-
export async function parseResponseAndNormalizeError(response, shouldParseResponse = true) {
|
|
12
|
+
async function parseResponseAndNormalizeError(response, shouldParseResponse = true) {
|
|
33
13
|
if (!shouldParseResponse) {
|
|
34
14
|
return response;
|
|
35
15
|
}
|
|
@@ -38,20 +18,14 @@ export async function parseResponseAndNormalizeError(response, shouldParseRespon
|
|
|
38
18
|
}
|
|
39
19
|
return await parseJsonAndNormalizeError(response);
|
|
40
20
|
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Parses a response, throwing an error if parsing the response fails.
|
|
44
|
-
*
|
|
45
|
-
* @param response
|
|
46
|
-
* @param shouldParseResponse
|
|
47
|
-
* @return Never returns, always throws.
|
|
48
|
-
*/
|
|
49
|
-
export async function parseAndThrowError(response, shouldParseResponse = true) {
|
|
21
|
+
async function parseAndThrowError(response, shouldParseResponse = true) {
|
|
50
22
|
if (!shouldParseResponse) {
|
|
51
23
|
throw response;
|
|
52
24
|
}
|
|
53
|
-
|
|
54
|
-
// Parse the response JSON and throw it as an error.
|
|
55
25
|
throw await parseJsonAndNormalizeError(response);
|
|
56
26
|
}
|
|
57
|
-
|
|
27
|
+
export {
|
|
28
|
+
parseAndThrowError,
|
|
29
|
+
parseResponseAndNormalizeError
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=response.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/response.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\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\n * @return Parsed response.\n */\nasync function parseJsonAndNormalizeError( response: Response ) {\n\ttry {\n\t\treturn await response.json();\n\t} catch {\n\t\tthrow {\n\t\t\tcode: 'invalid_json',\n\t\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t\t};\n\t}\n}\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param response\n * @param shouldParseResponse\n *\n * @return Parsed response.\n */\nexport async function parseResponseAndNormalizeError(\n\tresponse: Response,\n\tshouldParseResponse = true\n) {\n\tif ( ! shouldParseResponse ) {\n\t\treturn response;\n\t}\n\n\tif ( response.status === 204 ) {\n\t\treturn null;\n\t}\n\n\treturn await parseJsonAndNormalizeError( response );\n}\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param response\n * @param shouldParseResponse\n * @return Never returns, always throws.\n */\nexport async function parseAndThrowError(\n\tresponse: Response,\n\tshouldParseResponse = true\n) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\t// Parse the response JSON and throw it as an error.\n\tthrow await parseJsonAndNormalizeError( response );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU;AASnB,eAAe,2BAA4B,UAAqB;AAC/D,MAAI;AACH,WAAO,MAAM,SAAS,KAAK;AAAA,EAC5B,QAAQ;AACP,UAAM;AAAA,MACL,MAAM;AAAA,MACN,SAAS,GAAI,4CAA6C;AAAA,IAC3D;AAAA,EACD;AACD;AAUA,eAAsB,+BACrB,UACA,sBAAsB,MACrB;AACD,MAAK,CAAE,qBAAsB;AAC5B,WAAO;AAAA,EACR;AAEA,MAAK,SAAS,WAAW,KAAM;AAC9B,WAAO;AAAA,EACR;AAEA,SAAO,MAAM,2BAA4B,QAAS;AACnD;AASA,eAAsB,mBACrB,UACA,sBAAsB,MACrB;AACD,MAAK,CAAE,qBAAsB;AAC5B,UAAM;AAAA,EACP;AAGA,QAAM,MAAM,2BAA4B,QAAS;AAClD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|