@wordpress/api-fetch 7.32.0 → 7.32.1-next.b8c8708f3.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/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/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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/api-fetch",
|
|
3
|
-
"version": "7.32.0",
|
|
3
|
+
"version": "7.32.1-next.b8c8708f3.0",
|
|
4
4
|
"description": "Utility to make WordPress REST API requests.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,16 +25,24 @@
|
|
|
25
25
|
},
|
|
26
26
|
"main": "build/index.js",
|
|
27
27
|
"module": "build-module/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./build-types/index.d.ts",
|
|
31
|
+
"import": "./build-module/index.js",
|
|
32
|
+
"require": "./build/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
28
36
|
"react-native": "src/index",
|
|
29
37
|
"wpScript": true,
|
|
38
|
+
"wpScriptDefaultExport": true,
|
|
30
39
|
"types": "build-types",
|
|
31
40
|
"dependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@wordpress/
|
|
34
|
-
"@wordpress/url": "^4.32.0"
|
|
41
|
+
"@wordpress/i18n": "^6.5.1-next.b8c8708f3.0",
|
|
42
|
+
"@wordpress/url": "^4.32.1-next.b8c8708f3.0"
|
|
35
43
|
},
|
|
36
44
|
"publishConfig": {
|
|
37
45
|
"access": "public"
|
|
38
46
|
},
|
|
39
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "67cfd7e661931aeb0d06bec894599d287a4f8d0f"
|
|
40
48
|
}
|