@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,35 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var root_url_exports = {};
|
|
30
|
+
__export(root_url_exports, {
|
|
31
|
+
default: () => root_url_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param rootURL
|
|
15
|
-
* @return Root URL middleware.
|
|
16
|
-
*/
|
|
17
|
-
const createRootURLMiddleware = rootURL => (options, next) => {
|
|
18
|
-
return (0, _namespaceEndpoint.default)(options, optionsWithPath => {
|
|
33
|
+
module.exports = __toCommonJS(root_url_exports);
|
|
34
|
+
var import_namespace_endpoint = __toESM(require("./namespace-endpoint"));
|
|
35
|
+
const createRootURLMiddleware = (rootURL) => (options, next) => {
|
|
36
|
+
return (0, import_namespace_endpoint.default)(options, (optionsWithPath) => {
|
|
19
37
|
let url = optionsWithPath.url;
|
|
20
38
|
let path = optionsWithPath.path;
|
|
21
39
|
let apiRoot;
|
|
22
|
-
if (typeof path ===
|
|
40
|
+
if (typeof path === "string") {
|
|
23
41
|
apiRoot = rootURL;
|
|
24
|
-
if (-1 !== rootURL.indexOf(
|
|
25
|
-
path = path.replace(
|
|
42
|
+
if (-1 !== rootURL.indexOf("?")) {
|
|
43
|
+
path = path.replace("?", "&");
|
|
26
44
|
}
|
|
27
|
-
path = path.replace(/^\//,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// configured to use plain permalinks.
|
|
31
|
-
if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
|
|
32
|
-
path = path.replace('?', '&');
|
|
45
|
+
path = path.replace(/^\//, "");
|
|
46
|
+
if ("string" === typeof apiRoot && -1 !== apiRoot.indexOf("?")) {
|
|
47
|
+
path = path.replace("?", "&");
|
|
33
48
|
}
|
|
34
49
|
url = apiRoot + path;
|
|
35
50
|
}
|
|
@@ -39,5 +54,5 @@ const createRootURLMiddleware = rootURL => (options, next) => {
|
|
|
39
54
|
});
|
|
40
55
|
});
|
|
41
56
|
};
|
|
42
|
-
var
|
|
43
|
-
//# sourceMappingURL=root-url.js.map
|
|
57
|
+
var root_url_default = createRootURLMiddleware;
|
|
58
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAA2C;AAM3C,MAAM,0BACL,CAAE,YACF,CAAE,SAAS,SAAU;AACpB,aAAO,0BAAAA,SAAgC,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": ["namespaceAndEndpointMiddleware"]
|
|
7
|
+
}
|
|
@@ -1,50 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var theme_preview_exports = {};
|
|
20
|
+
__export(theme_preview_exports, {
|
|
21
|
+
default: () => theme_preview_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* This appends a `wp_theme_preview` parameter to the REST API request URL if
|
|
18
|
-
* the admin URL contains a `theme` GET parameter.
|
|
19
|
-
*
|
|
20
|
-
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
|
|
21
|
-
* then bypass this middleware.
|
|
22
|
-
*
|
|
23
|
-
* @param themePath
|
|
24
|
-
* @return Preloading middleware.
|
|
25
|
-
*/
|
|
26
|
-
const createThemePreviewMiddleware = themePath => (options, next) => {
|
|
27
|
-
if (typeof options.url === 'string') {
|
|
28
|
-
const wpThemePreview = (0, _url.getQueryArg)(options.url, 'wp_theme_preview');
|
|
29
|
-
if (wpThemePreview === undefined) {
|
|
30
|
-
options.url = (0, _url.addQueryArgs)(options.url, {
|
|
23
|
+
module.exports = __toCommonJS(theme_preview_exports);
|
|
24
|
+
var import_url = require("@wordpress/url");
|
|
25
|
+
const createThemePreviewMiddleware = (themePath) => (options, next) => {
|
|
26
|
+
if (typeof options.url === "string") {
|
|
27
|
+
const wpThemePreview = (0, import_url.getQueryArg)(
|
|
28
|
+
options.url,
|
|
29
|
+
"wp_theme_preview"
|
|
30
|
+
);
|
|
31
|
+
if (wpThemePreview === void 0) {
|
|
32
|
+
options.url = (0, import_url.addQueryArgs)(options.url, {
|
|
31
33
|
wp_theme_preview: themePath
|
|
32
34
|
});
|
|
33
|
-
} else if (wpThemePreview ===
|
|
34
|
-
options.url = (0,
|
|
35
|
+
} else if (wpThemePreview === "") {
|
|
36
|
+
options.url = (0, import_url.removeQueryArgs)(
|
|
37
|
+
options.url,
|
|
38
|
+
"wp_theme_preview"
|
|
39
|
+
);
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
|
-
if (typeof options.path ===
|
|
38
|
-
const wpThemePreview = (0,
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
if (typeof options.path === "string") {
|
|
43
|
+
const wpThemePreview = (0, import_url.getQueryArg)(
|
|
44
|
+
options.path,
|
|
45
|
+
"wp_theme_preview"
|
|
46
|
+
);
|
|
47
|
+
if (wpThemePreview === void 0) {
|
|
48
|
+
options.path = (0, import_url.addQueryArgs)(options.path, {
|
|
41
49
|
wp_theme_preview: themePath
|
|
42
50
|
});
|
|
43
|
-
} else if (wpThemePreview ===
|
|
44
|
-
options.path = (0,
|
|
51
|
+
} else if (wpThemePreview === "") {
|
|
52
|
+
options.path = (0, import_url.removeQueryArgs)(
|
|
53
|
+
options.path,
|
|
54
|
+
"wp_theme_preview"
|
|
55
|
+
);
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
return next(options);
|
|
48
59
|
};
|
|
49
|
-
var
|
|
50
|
-
//# sourceMappingURL=theme-preview.js.map
|
|
60
|
+
var theme_preview_default = createThemePreviewMiddleware;
|
|
61
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA2D;AAgB3D,MAAM,+BACL,CAAE,cACF,CAAE,SAAS,SAAU;AACpB,MAAK,OAAO,QAAQ,QAAQ,UAAW;AACtC,UAAM,qBAAiB;AAAA,MACtB,QAAQ;AAAA,MACR;AAAA,IACD;AACA,QAAK,mBAAmB,QAAY;AACnC,cAAQ,UAAM,yBAAc,QAAQ,KAAK;AAAA,QACxC,kBAAkB;AAAA,MACnB,CAAE;AAAA,IACH,WAAY,mBAAmB,IAAK;AACnC,cAAQ,UAAM;AAAA,QACb,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAK,OAAO,QAAQ,SAAS,UAAW;AACvC,UAAM,qBAAiB;AAAA,MACtB,QAAQ;AAAA,MACR;AAAA,IACD;AACA,QAAK,mBAAmB,QAAY;AACnC,cAAQ,WAAO,yBAAc,QAAQ,MAAM;AAAA,QAC1C,kBAAkB;AAAA,MACnB,CAAE;AAAA,IACH,WAAY,mBAAmB,IAAK;AACnC,cAAQ,WAAO;AAAA,QACd,QAAQ;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO,KAAM,OAAQ;AACtB;AAED,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var user_locale_exports = {};
|
|
20
|
+
__export(user_locale_exports, {
|
|
21
|
+
default: () => user_locale_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
/**
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
23
|
+
module.exports = __toCommonJS(user_locale_exports);
|
|
24
|
+
var import_url = require("@wordpress/url");
|
|
16
25
|
const userLocaleMiddleware = (options, next) => {
|
|
17
|
-
if (typeof options.url ===
|
|
18
|
-
options.url = (0,
|
|
19
|
-
_locale: 'user'
|
|
20
|
-
});
|
|
26
|
+
if (typeof options.url === "string" && !(0, import_url.hasQueryArg)(options.url, "_locale")) {
|
|
27
|
+
options.url = (0, import_url.addQueryArgs)(options.url, { _locale: "user" });
|
|
21
28
|
}
|
|
22
|
-
if (typeof options.path ===
|
|
23
|
-
options.path = (0,
|
|
24
|
-
_locale: 'user'
|
|
25
|
-
});
|
|
29
|
+
if (typeof options.path === "string" && !(0, import_url.hasQueryArg)(options.path, "_locale")) {
|
|
30
|
+
options.path = (0, import_url.addQueryArgs)(options.path, { _locale: "user" });
|
|
26
31
|
}
|
|
27
32
|
return next(options);
|
|
28
33
|
};
|
|
29
|
-
var
|
|
30
|
-
//# sourceMappingURL=user-locale.js.map
|
|
34
|
+
var user_locale_default = userLocaleMiddleware;
|
|
35
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0C;AAO1C,MAAM,uBAA2C,CAAE,SAAS,SAAU;AACrE,MACC,OAAO,QAAQ,QAAQ,YACvB,KAAE,wBAAa,QAAQ,KAAK,SAAU,GACrC;AACD,YAAQ,UAAM,yBAAc,QAAQ,KAAK,EAAE,SAAS,OAAO,CAAE;AAAA,EAC9D;AAEA,MACC,OAAO,QAAQ,SAAS,YACxB,KAAE,wBAAa,QAAQ,MAAM,SAAU,GACtC;AACD,YAAQ,WAAO,yBAAc,QAAQ,MAAM,EAAE,SAAS,OAAO,CAAE;AAAA,EAChE;AAEA,SAAO,KAAM,OAAQ;AACtB;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["export interface APIFetchOptions< Parse extends boolean = boolean >\n\textends RequestInit {\n\t// Override headers, we only accept it as an object due to the `nonce` middleware\n\theaders?: Record< string, string >;\n\tpath?: string;\n\turl?: string;\n\t/**\n\t * @default true\n\t */\n\tparse?: Parse;\n\tdata?: any;\n\tnamespace?: string;\n\tendpoint?: string;\n}\n\nexport type FetchHandler< Parse extends boolean = boolean > = (\n\tnextOptions: APIFetchOptions< Parse >\n) => Promise< any >;\n\nexport type APIFetchMiddleware< Parse extends boolean = boolean > = (\n\toptions: APIFetchOptions< Parse >,\n\tnext: FetchHandler< Parse >\n) => Promise< any >;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/utils/response.js
CHANGED
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var response_exports = {};
|
|
20
|
+
__export(response_exports, {
|
|
21
|
+
parseAndThrowError: () => parseAndThrowError,
|
|
22
|
+
parseResponseAndNormalizeError: () => parseResponseAndNormalizeError
|
|
5
23
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _i18n = require("@wordpress/i18n");
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Calls the `json` function on the Response, throwing an error if the response
|
|
15
|
-
* doesn't have a json function or if parsing the json itself fails.
|
|
16
|
-
*
|
|
17
|
-
* @param response
|
|
18
|
-
* @return Parsed response.
|
|
19
|
-
*/
|
|
24
|
+
module.exports = __toCommonJS(response_exports);
|
|
25
|
+
var import_i18n = require("@wordpress/i18n");
|
|
20
26
|
async function parseJsonAndNormalizeError(response) {
|
|
21
27
|
try {
|
|
22
28
|
return await response.json();
|
|
23
29
|
} catch {
|
|
24
30
|
throw {
|
|
25
|
-
code:
|
|
26
|
-
message: (0,
|
|
31
|
+
code: "invalid_json",
|
|
32
|
+
message: (0, import_i18n.__)("The response is not a valid JSON response.")
|
|
27
33
|
};
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Parses the apiFetch response properly and normalize response errors.
|
|
33
|
-
*
|
|
34
|
-
* @param response
|
|
35
|
-
* @param shouldParseResponse
|
|
36
|
-
*
|
|
37
|
-
* @return Parsed response.
|
|
38
|
-
*/
|
|
39
36
|
async function parseResponseAndNormalizeError(response, shouldParseResponse = true) {
|
|
40
37
|
if (!shouldParseResponse) {
|
|
41
38
|
return response;
|
|
@@ -45,20 +42,15 @@ async function parseResponseAndNormalizeError(response, shouldParseResponse = tr
|
|
|
45
42
|
}
|
|
46
43
|
return await parseJsonAndNormalizeError(response);
|
|
47
44
|
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Parses a response, throwing an error if parsing the response fails.
|
|
51
|
-
*
|
|
52
|
-
* @param response
|
|
53
|
-
* @param shouldParseResponse
|
|
54
|
-
* @return Never returns, always throws.
|
|
55
|
-
*/
|
|
56
45
|
async function parseAndThrowError(response, shouldParseResponse = true) {
|
|
57
46
|
if (!shouldParseResponse) {
|
|
58
47
|
throw response;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
|
-
// Parse the response JSON and throw it as an error.
|
|
62
49
|
throw await parseJsonAndNormalizeError(response);
|
|
63
50
|
}
|
|
64
|
-
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
parseAndThrowError,
|
|
54
|
+
parseResponseAndNormalizeError
|
|
55
|
+
});
|
|
56
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AASnB,eAAe,2BAA4B,UAAqB;AAC/D,MAAI;AACH,WAAO,MAAM,SAAS,KAAK;AAAA,EAC5B,QAAQ;AACP,UAAM;AAAA,MACL,MAAM;AAAA,MACN,aAAS,gBAAI,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
|
+
}
|