@wordpress/api-fetch 7.32.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/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/http-v1.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\n/**\n * Set of HTTP methods which are eligible to be overridden.\n */\nconst OVERRIDE_METHODS = new Set( [ 'PATCH', 'PUT', 'DELETE' ] );\n\n/**\n * Default request method.\n *\n * \"A request has an associated method (a method). Unless stated otherwise it\n * is `GET`.\"\n *\n * @see https://fetch.spec.whatwg.org/#requests\n */\nconst DEFAULT_METHOD = 'GET';\n\n/**\n * API Fetch middleware which overrides the request method for HTTP v1\n * compatibility leveraging the REST API X-HTTP-Method-Override header.\n *\n * @param options\n * @param next\n */\nconst httpV1Middleware: APIFetchMiddleware = ( options, next ) => {\n\tconst { method = DEFAULT_METHOD } = options;\n\tif ( OVERRIDE_METHODS.has( method.toUpperCase() ) ) {\n\t\toptions = {\n\t\t\t...options,\n\t\t\theaders: {\n\t\t\t\t...options.headers,\n\t\t\t\t'X-HTTP-Method-Override': method,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t},\n\t\t\tmethod: 'POST',\n\t\t};\n\t}\n\n\treturn next( options );\n};\n\nexport default httpV1Middleware;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,mBAAmB,oBAAI,IAAK,CAAE,SAAS,OAAO,QAAS,CAAE;AAU/D,MAAM,iBAAiB;AASvB,MAAM,mBAAuC,CAAE,SAAS,SAAU;AACjE,QAAM,EAAE,SAAS,eAAe,IAAI;AACpC,MAAK,iBAAiB,IAAK,OAAO,YAAY,CAAE,GAAI;AACnD,cAAU;AAAA,MACT,GAAG;AAAA,MACH,SAAS;AAAA,QACR,GAAG,QAAQ;AAAA,QACX,0BAA0B;AAAA,QAC1B,gBAAgB;AAAA,MACjB;AAAA,MACA,QAAQ;AAAA,IACT;AAAA,EACD;AAEA,SAAO,KAAM,OAAQ;AACtB;AAEA,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,53 +1,45 @@
|
|
|
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 media_upload_exports = {};
|
|
20
|
+
__export(media_upload_exports, {
|
|
21
|
+
default: () => media_upload_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
/**
|
|
10
|
-
* WordPress dependencies
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param options
|
|
19
|
-
* @return True if the request is for media upload.
|
|
20
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(media_upload_exports);
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
var import_response = require("../utils/response");
|
|
21
26
|
function isMediaUploadRequest(options) {
|
|
22
|
-
const isCreateMethod = !!options.method && options.method ===
|
|
23
|
-
const isMediaEndpoint = !!options.path && options.path.indexOf(
|
|
27
|
+
const isCreateMethod = !!options.method && options.method === "POST";
|
|
28
|
+
const isMediaEndpoint = !!options.path && options.path.indexOf("/wp/v2/media") !== -1 || !!options.url && options.url.indexOf("/wp/v2/media") !== -1;
|
|
24
29
|
return isMediaEndpoint && isCreateMethod;
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Middleware handling media upload failures and retries.
|
|
29
|
-
* @param options
|
|
30
|
-
* @param next
|
|
31
|
-
*/
|
|
32
31
|
const mediaUploadMiddleware = (options, next) => {
|
|
33
32
|
if (!isMediaUploadRequest(options)) {
|
|
34
33
|
return next(options);
|
|
35
34
|
}
|
|
36
35
|
let retries = 0;
|
|
37
36
|
const maxRetries = 5;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param attachmentId
|
|
41
|
-
* @return Processed post response.
|
|
42
|
-
*/
|
|
43
|
-
const postProcess = attachmentId => {
|
|
37
|
+
const postProcess = (attachmentId) => {
|
|
44
38
|
retries++;
|
|
45
39
|
return next({
|
|
46
40
|
path: `/wp/v2/media/${attachmentId}/post-process`,
|
|
47
|
-
method:
|
|
48
|
-
data: {
|
|
49
|
-
action: 'create-image-subsizes'
|
|
50
|
-
},
|
|
41
|
+
method: "POST",
|
|
42
|
+
data: { action: "create-image-subsizes" },
|
|
51
43
|
parse: false
|
|
52
44
|
}).catch(() => {
|
|
53
45
|
if (retries < maxRetries) {
|
|
@@ -55,33 +47,35 @@ const mediaUploadMiddleware = (options, next) => {
|
|
|
55
47
|
}
|
|
56
48
|
next({
|
|
57
49
|
path: `/wp/v2/media/${attachmentId}?force=true`,
|
|
58
|
-
method:
|
|
50
|
+
method: "DELETE"
|
|
59
51
|
});
|
|
60
52
|
return Promise.reject();
|
|
61
53
|
});
|
|
62
54
|
};
|
|
63
|
-
return next({
|
|
64
|
-
...options,
|
|
65
|
-
parse: false
|
|
66
|
-
}).catch(response => {
|
|
67
|
-
// `response` could actually be an error thrown by `defaultFetchHandler`.
|
|
55
|
+
return next({ ...options, parse: false }).catch((response) => {
|
|
68
56
|
if (!(response instanceof globalThis.Response)) {
|
|
69
57
|
return Promise.reject(response);
|
|
70
58
|
}
|
|
71
|
-
const attachmentId = response.headers.get(
|
|
59
|
+
const attachmentId = response.headers.get(
|
|
60
|
+
"x-wp-upload-attachment-id"
|
|
61
|
+
);
|
|
72
62
|
if (response.status >= 500 && response.status < 600 && attachmentId) {
|
|
73
63
|
return postProcess(attachmentId).catch(() => {
|
|
74
64
|
if (options.parse !== false) {
|
|
75
65
|
return Promise.reject({
|
|
76
|
-
code:
|
|
77
|
-
message: (0,
|
|
66
|
+
code: "post_process",
|
|
67
|
+
message: (0, import_i18n.__)(
|
|
68
|
+
"Media upload failed. If this is a photo or a large image, please scale it down and try again."
|
|
69
|
+
)
|
|
78
70
|
});
|
|
79
71
|
}
|
|
80
72
|
return Promise.reject(response);
|
|
81
73
|
});
|
|
82
74
|
}
|
|
83
|
-
return (0,
|
|
84
|
-
}).then(
|
|
75
|
+
return (0, import_response.parseAndThrowError)(response, options.parse);
|
|
76
|
+
}).then(
|
|
77
|
+
(response) => (0, import_response.parseResponseAndNormalizeError)(response, options.parse)
|
|
78
|
+
);
|
|
85
79
|
};
|
|
86
|
-
var
|
|
87
|
-
//# sourceMappingURL=media-upload.js.map
|
|
80
|
+
var media_upload_default = mediaUploadMiddleware;
|
|
81
|
+
//# sourceMappingURL=media-upload.js.map
|
|
@@ -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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAKnB,sBAGO;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,aAAS;AAAA,cACR;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAEA,eAAO,QAAQ,OAAQ,QAAS;AAAA,MACjC,CAAE;AAAA,IACH;AACA,eAAO,oCAAoB,UAAU,QAAQ,KAAM;AAAA,EACpD,CAAE,EACD;AAAA,IAAM,CAAE,iBACR,gDAAgC,UAAU,QAAQ,KAAM;AAAA,EACzD;AACF;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,34 @@
|
|
|
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 namespace_endpoint_exports = {};
|
|
20
|
+
__export(namespace_endpoint_exports, {
|
|
21
|
+
default: () => namespace_endpoint_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
23
|
+
module.exports = __toCommonJS(namespace_endpoint_exports);
|
|
11
24
|
const namespaceAndEndpointMiddleware = (options, next) => {
|
|
12
25
|
let path = options.path;
|
|
13
26
|
let namespaceTrimmed, endpointTrimmed;
|
|
14
|
-
if (typeof options.namespace ===
|
|
15
|
-
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g,
|
|
16
|
-
endpointTrimmed = options.endpoint.replace(/^\//,
|
|
27
|
+
if (typeof options.namespace === "string" && typeof options.endpoint === "string") {
|
|
28
|
+
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, "");
|
|
29
|
+
endpointTrimmed = options.endpoint.replace(/^\//, "");
|
|
17
30
|
if (endpointTrimmed) {
|
|
18
|
-
path = namespaceTrimmed +
|
|
31
|
+
path = namespaceTrimmed + "/" + endpointTrimmed;
|
|
19
32
|
} else {
|
|
20
33
|
path = namespaceTrimmed;
|
|
21
34
|
}
|
|
@@ -27,5 +40,5 @@ const namespaceAndEndpointMiddleware = (options, next) => {
|
|
|
27
40
|
path
|
|
28
41
|
});
|
|
29
42
|
};
|
|
30
|
-
var
|
|
31
|
-
//# sourceMappingURL=namespace-endpoint.js.map
|
|
43
|
+
var namespace_endpoint_default = namespaceAndEndpointMiddleware;
|
|
44
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,28 +1,31 @@
|
|
|
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 nonce_exports = {};
|
|
20
|
+
__export(nonce_exports, {
|
|
21
|
+
default: () => nonce_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param nonce
|
|
13
|
-
*
|
|
14
|
-
* @return A middleware to enhance a request with a nonce.
|
|
15
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(nonce_exports);
|
|
16
24
|
function createNonceMiddleware(nonce) {
|
|
17
25
|
const middleware = (options, next) => {
|
|
18
|
-
const {
|
|
19
|
-
headers = {}
|
|
20
|
-
} = options;
|
|
21
|
-
|
|
22
|
-
// If an 'X-WP-Nonce' header (or any case-insensitive variation
|
|
23
|
-
// thereof) was specified, no need to add a nonce header.
|
|
26
|
+
const { headers = {} } = options;
|
|
24
27
|
for (const headerName in headers) {
|
|
25
|
-
if (headerName.toLowerCase() ===
|
|
28
|
+
if (headerName.toLowerCase() === "x-wp-nonce" && headers[headerName] === middleware.nonce) {
|
|
26
29
|
return next(options);
|
|
27
30
|
}
|
|
28
31
|
}
|
|
@@ -30,12 +33,12 @@ function createNonceMiddleware(nonce) {
|
|
|
30
33
|
...options,
|
|
31
34
|
headers: {
|
|
32
35
|
...headers,
|
|
33
|
-
|
|
36
|
+
"X-WP-Nonce": middleware.nonce
|
|
34
37
|
}
|
|
35
38
|
});
|
|
36
39
|
};
|
|
37
40
|
middleware.nonce = nonce;
|
|
38
41
|
return middleware;
|
|
39
42
|
}
|
|
40
|
-
var
|
|
41
|
-
//# sourceMappingURL=nonce.js.map
|
|
43
|
+
var nonce_default = createNonceMiddleware;
|
|
44
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,90 +1,93 @@
|
|
|
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 preloading_exports = {};
|
|
20
|
+
__export(preloading_exports, {
|
|
21
|
+
default: () => preloading_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
/**
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param preloadedData
|
|
18
|
-
* @return Preloading middleware.
|
|
19
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(preloading_exports);
|
|
24
|
+
var import_url = require("@wordpress/url");
|
|
20
25
|
function createPreloadingMiddleware(preloadedData) {
|
|
21
|
-
const cache = Object.fromEntries(
|
|
26
|
+
const cache = Object.fromEntries(
|
|
27
|
+
Object.entries(preloadedData).map(([path, data]) => [
|
|
28
|
+
(0, import_url.normalizePath)(path),
|
|
29
|
+
data
|
|
30
|
+
])
|
|
31
|
+
);
|
|
22
32
|
return (options, next) => {
|
|
23
|
-
const {
|
|
24
|
-
parse = true
|
|
25
|
-
} = options;
|
|
33
|
+
const { parse = true } = options;
|
|
26
34
|
let rawPath = options.path;
|
|
27
35
|
if (!rawPath && options.url) {
|
|
28
|
-
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
rawPath = (0, _url.addQueryArgs)(pathFromQuery, queryArgs);
|
|
36
|
+
const { rest_route: pathFromQuery, ...queryArgs } = (0, import_url.getQueryArgs)(
|
|
37
|
+
options.url
|
|
38
|
+
);
|
|
39
|
+
if (typeof pathFromQuery === "string") {
|
|
40
|
+
rawPath = (0, import_url.addQueryArgs)(pathFromQuery, queryArgs);
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
|
-
if (typeof rawPath !==
|
|
43
|
+
if (typeof rawPath !== "string") {
|
|
37
44
|
return next(options);
|
|
38
45
|
}
|
|
39
|
-
const method = options.method ||
|
|
40
|
-
const path = (0,
|
|
41
|
-
if (
|
|
46
|
+
const method = options.method || "GET";
|
|
47
|
+
const path = (0, import_url.normalizePath)(rawPath);
|
|
48
|
+
if ("GET" === method && cache[path]) {
|
|
42
49
|
const cacheData = cache[path];
|
|
43
|
-
|
|
44
|
-
// Unsetting the cache key ensures that the data is only used a single time.
|
|
45
50
|
delete cache[path];
|
|
46
51
|
return prepareResponse(cacheData, !!parse);
|
|
47
|
-
} else if (
|
|
52
|
+
} else if ("OPTIONS" === method && cache[method] && cache[method][path]) {
|
|
48
53
|
const cacheData = cache[method][path];
|
|
49
|
-
|
|
50
|
-
// Unsetting the cache key ensures that the data is only used a single time.
|
|
51
54
|
delete cache[method][path];
|
|
52
55
|
return prepareResponse(cacheData, !!parse);
|
|
53
56
|
}
|
|
54
57
|
return next(options);
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* This is a helper function that sends a success response.
|
|
60
|
-
*
|
|
61
|
-
* @param responseData
|
|
62
|
-
* @param parse
|
|
63
|
-
* @return Promise with the response.
|
|
64
|
-
*/
|
|
65
60
|
function prepareResponse(responseData, parse) {
|
|
66
61
|
if (parse) {
|
|
67
62
|
return Promise.resolve(responseData.body);
|
|
68
63
|
}
|
|
69
64
|
try {
|
|
70
|
-
return Promise.resolve(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
return Promise.resolve(
|
|
66
|
+
new window.Response(JSON.stringify(responseData.body), {
|
|
67
|
+
status: 200,
|
|
68
|
+
statusText: "OK",
|
|
69
|
+
headers: responseData.headers
|
|
70
|
+
})
|
|
71
|
+
);
|
|
75
72
|
} catch {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
Object.entries(
|
|
74
|
+
responseData.headers
|
|
75
|
+
).forEach(([key, value]) => {
|
|
76
|
+
if (key.toLowerCase() === "link") {
|
|
77
|
+
responseData.headers[key] = value.replace(
|
|
78
|
+
/<([^>]+)>/,
|
|
79
|
+
(_, url) => `<${encodeURI(url)}>`
|
|
80
|
+
);
|
|
80
81
|
}
|
|
81
82
|
});
|
|
82
|
-
return Promise.resolve(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
return Promise.resolve(
|
|
84
|
+
parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
|
|
85
|
+
status: 200,
|
|
86
|
+
statusText: "OK",
|
|
87
|
+
headers: responseData.headers
|
|
88
|
+
})
|
|
89
|
+
);
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
|
-
var
|
|
90
|
-
//# sourceMappingURL=preloading.js.map
|
|
92
|
+
var preloading_default = createPreloadingMiddleware;
|
|
93
|
+
//# 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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0D;AAW1D,SAAS,2BACR,eACqB;AACrB,QAAM,QAAQ,OAAO;AAAA,IACpB,OAAO,QAAS,aAAc,EAAE,IAAK,CAAE,CAAE,MAAM,IAAK,MAAO;AAAA,UAC1D,0BAAe,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,QAAI;AAAA,QACnD,QAAQ;AAAA,MACT;AAEA,UAAK,OAAO,kBAAkB,UAAW;AACxC,sBAAU,yBAAc,eAAe,SAAU;AAAA,MAClD;AAAA,IACD;AAEA,QAAK,OAAO,YAAY,UAAW;AAClC,aAAO,KAAM,OAAQ;AAAA,IACtB;AAEA,UAAM,SAAS,QAAQ,UAAU;AACjC,UAAM,WAAO,0BAAe,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,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
|
+
}
|