@wordpress/api-fetch 7.29.1-next.f34ab90e9.0 → 7.30.1-next.6870dfe5b.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 +50 -51
- package/build/index.js.map +1 -1
- package/build/middlewares/fetch-all-middleware.js +14 -14
- package/build/middlewares/fetch-all-middleware.js.map +1 -1
- package/build/middlewares/http-v1.js +6 -5
- package/build/middlewares/http-v1.js.map +1 -1
- package/build/middlewares/media-upload.js +7 -7
- package/build/middlewares/media-upload.js.map +1 -1
- package/build/middlewares/namespace-endpoint.js +2 -1
- package/build/middlewares/namespace-endpoint.js.map +1 -1
- package/build/middlewares/nonce.js +7 -5
- package/build/middlewares/nonce.js.map +1 -1
- package/build/middlewares/preloading.js +10 -7
- package/build/middlewares/preloading.js.map +1 -1
- package/build/middlewares/root-url.js +2 -2
- package/build/middlewares/root-url.js.map +1 -1
- package/build/middlewares/theme-preview.js +6 -2
- package/build/middlewares/theme-preview.js.map +1 -1
- package/build/middlewares/user-locale.js +2 -1
- package/build/middlewares/user-locale.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils/response.js +31 -50
- package/build/utils/response.js.map +1 -1
- package/build-module/index.js +38 -52
- package/build-module/index.js.map +1 -1
- package/build-module/middlewares/fetch-all-middleware.js +14 -15
- package/build-module/middlewares/fetch-all-middleware.js.map +1 -1
- package/build-module/middlewares/http-v1.js +6 -5
- package/build-module/middlewares/http-v1.js.map +1 -1
- package/build-module/middlewares/media-upload.js +7 -8
- package/build-module/middlewares/media-upload.js.map +1 -1
- package/build-module/middlewares/namespace-endpoint.js +2 -1
- package/build-module/middlewares/namespace-endpoint.js.map +1 -1
- package/build-module/middlewares/nonce.js +7 -5
- package/build-module/middlewares/nonce.js.map +1 -1
- package/build-module/middlewares/preloading.js +10 -7
- package/build-module/middlewares/preloading.js.map +1 -1
- package/build-module/middlewares/root-url.js +3 -2
- package/build-module/middlewares/root-url.js.map +1 -1
- package/build-module/middlewares/theme-preview.js +5 -2
- package/build-module/middlewares/theme-preview.js.map +1 -1
- package/build-module/middlewares/user-locale.js +2 -1
- package/build-module/middlewares/user-locale.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils/response.js +30 -48
- package/build-module/utils/response.js.map +1 -1
- package/build-types/index.d.ts +25 -32
- package/build-types/index.d.ts.map +1 -1
- package/build-types/middlewares/fetch-all-middleware.d.ts +5 -4
- package/build-types/middlewares/fetch-all-middleware.d.ts.map +1 -1
- package/build-types/middlewares/http-v1.d.ts +8 -3
- package/build-types/middlewares/http-v1.d.ts.map +1 -1
- package/build-types/middlewares/media-upload.d.ts +5 -4
- package/build-types/middlewares/media-upload.d.ts.map +1 -1
- package/build-types/middlewares/namespace-endpoint.d.ts +4 -3
- package/build-types/middlewares/namespace-endpoint.d.ts.map +1 -1
- package/build-types/middlewares/nonce.d.ts +9 -4
- package/build-types/middlewares/nonce.d.ts.map +1 -1
- package/build-types/middlewares/preloading.d.ts +8 -4
- package/build-types/middlewares/preloading.d.ts.map +1 -1
- package/build-types/middlewares/root-url.d.ts +8 -4
- package/build-types/middlewares/root-url.d.ts.map +1 -1
- package/build-types/middlewares/theme-preview.d.ts +8 -4
- package/build-types/middlewares/theme-preview.d.ts.map +1 -1
- package/build-types/middlewares/user-locale.d.ts +4 -3
- package/build-types/middlewares/user-locale.d.ts.map +1 -1
- package/build-types/types.d.ts +4 -3
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/response.d.ts +13 -5
- package/build-types/utils/response.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/{index.js → index.ts} +78 -69
- package/src/middlewares/{fetch-all-middleware.js → fetch-all-middleware.ts} +24 -20
- package/src/middlewares/{http-v1.js → http-v1.ts} +8 -6
- package/src/middlewares/{media-upload.js → media-upload.ts} +13 -12
- package/src/middlewares/{namespace-endpoint.js → namespace-endpoint.ts} +7 -2
- package/src/middlewares/{nonce.js → nonce.ts} +15 -7
- package/src/middlewares/{preloading.js → preloading.ts} +21 -11
- package/src/middlewares/root-url.ts +47 -0
- package/src/middlewares/test/{fetch-all-middleware.js → fetch-all-middleware.ts} +1 -1
- package/src/middlewares/test/{http-v1.js → http-v1.ts} +7 -4
- package/src/middlewares/test/{media-upload.js → media-upload.ts} +2 -1
- package/src/middlewares/test/{namespace-endpoint.js → namespace-endpoint.ts} +2 -1
- package/src/middlewares/test/{nonce.js → nonce.ts} +5 -4
- package/src/middlewares/test/{preloading.js → preloading.ts} +31 -11
- package/src/middlewares/test/{root-url.js → root-url.ts} +2 -1
- package/src/middlewares/test/{user-locale.js → user-locale.ts} +9 -8
- package/src/middlewares/theme-preview.ts +60 -0
- package/src/middlewares/{user-locale.js → user-locale.ts} +4 -2
- package/src/test/index.js +218 -147
- package/src/types.ts +10 -5
- package/src/utils/response.ts +64 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/middlewares/root-url.js +0 -44
- package/src/middlewares/theme-preview.js +0 -42
- package/src/utils/response.js +0 -85
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Set of HTTP methods which are eligible to be overridden.
|
|
3
|
-
*
|
|
4
|
-
* @type {Set<string>}
|
|
5
7
|
*/
|
|
6
8
|
const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
|
|
7
9
|
|
|
@@ -12,8 +14,6 @@ const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
|
|
|
12
14
|
* is `GET`."
|
|
13
15
|
*
|
|
14
16
|
* @see https://fetch.spec.whatwg.org/#requests
|
|
15
|
-
*
|
|
16
|
-
* @type {string}
|
|
17
17
|
*/
|
|
18
18
|
const DEFAULT_METHOD = 'GET';
|
|
19
19
|
|
|
@@ -21,7 +21,8 @@ const DEFAULT_METHOD = 'GET';
|
|
|
21
21
|
* API Fetch middleware which overrides the request method for HTTP v1
|
|
22
22
|
* compatibility leveraging the REST API X-HTTP-Method-Override header.
|
|
23
23
|
*
|
|
24
|
-
* @
|
|
24
|
+
* @param options
|
|
25
|
+
* @param next
|
|
25
26
|
*/
|
|
26
27
|
const httpV1Middleware = (options, next) => {
|
|
27
28
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OVERRIDE_METHODS","Set","DEFAULT_METHOD","httpV1Middleware","options","next","method","has","toUpperCase","headers"],"sources":["@wordpress/api-fetch/src/middlewares/http-v1.
|
|
1
|
+
{"version":3,"names":["OVERRIDE_METHODS","Set","DEFAULT_METHOD","httpV1Middleware","options","next","method","has","toUpperCase","headers"],"sources":["@wordpress/api-fetch/src/middlewares/http-v1.ts"],"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"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,MAAMA,gBAAgB,GAAG,IAAIC,GAAG,CAAE,CAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAG,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,KAAK;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAoC,GAAGA,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACjE,MAAM;IAAEC,MAAM,GAAGJ;EAAe,CAAC,GAAGE,OAAO;EAC3C,IAAKJ,gBAAgB,CAACO,GAAG,CAAED,MAAM,CAACE,WAAW,CAAC,CAAE,CAAC,EAAG;IACnDJ,OAAO,GAAG;MACT,GAAGA,OAAO;MACVK,OAAO,EAAE;QACR,GAAGL,OAAO,CAACK,OAAO;QAClB,wBAAwB,EAAEH,MAAM;QAChC,cAAc,EAAE;MACjB,CAAC;MACDA,MAAM,EAAE;IACT,CAAC;EACF;EAEA,OAAOD,IAAI,CAAED,OAAQ,CAAC;AACvB,CAAC;AAED,eAAeD,gBAAgB","ignoreList":[]}
|
|
@@ -7,10 +7,9 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { parseAndThrowError, parseResponseAndNormalizeError } from '../utils/response';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
|
-
* @param
|
|
13
|
-
* @return
|
|
11
|
+
* @param options
|
|
12
|
+
* @return True if the request is for media upload.
|
|
14
13
|
*/
|
|
15
14
|
function isMediaUploadRequest(options) {
|
|
16
15
|
const isCreateMethod = !!options.method && options.method === 'POST';
|
|
@@ -20,8 +19,8 @@ function isMediaUploadRequest(options) {
|
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Middleware handling media upload failures and retries.
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
22
|
+
* @param options
|
|
23
|
+
* @param next
|
|
25
24
|
*/
|
|
26
25
|
const mediaUploadMiddleware = (options, next) => {
|
|
27
26
|
if (!isMediaUploadRequest(options)) {
|
|
@@ -31,8 +30,8 @@ const mediaUploadMiddleware = (options, next) => {
|
|
|
31
30
|
const maxRetries = 5;
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
|
-
* @param
|
|
35
|
-
* @return
|
|
33
|
+
* @param attachmentId
|
|
34
|
+
* @return Processed post response.
|
|
36
35
|
*/
|
|
37
36
|
const postProcess = attachmentId => {
|
|
38
37
|
retries++;
|
|
@@ -59,7 +58,7 @@ const mediaUploadMiddleware = (options, next) => {
|
|
|
59
58
|
parse: false
|
|
60
59
|
}).catch(response => {
|
|
61
60
|
// `response` could actually be an error thrown by `defaultFetchHandler`.
|
|
62
|
-
if (!response.
|
|
61
|
+
if (!(response instanceof globalThis.Response)) {
|
|
63
62
|
return Promise.reject(response);
|
|
64
63
|
}
|
|
65
64
|
const attachmentId = response.headers.get('x-wp-upload-attachment-id');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","parseAndThrowError","parseResponseAndNormalizeError","isMediaUploadRequest","options","isCreateMethod","method","isMediaEndpoint","path","indexOf","url","mediaUploadMiddleware","next","retries","maxRetries","postProcess","attachmentId","data","action","parse","catch","Promise","reject","response","headers","get","status","code","message","then"],"sources":["@wordpress/api-fetch/src/middlewares/media-upload.
|
|
1
|
+
{"version":3,"names":["__","parseAndThrowError","parseResponseAndNormalizeError","isMediaUploadRequest","options","isCreateMethod","method","isMediaEndpoint","path","indexOf","url","mediaUploadMiddleware","next","retries","maxRetries","postProcess","attachmentId","data","action","parse","catch","Promise","reject","response","globalThis","Response","headers","get","status","code","message","then"],"sources":["@wordpress/api-fetch/src/middlewares/media-upload.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SACCC,kBAAkB,EAClBC,8BAA8B,QACxB,mBAAmB;AAG1B;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAEC,OAAwB,EAAG;EACzD,MAAMC,cAAc,GAAG,CAAC,CAAED,OAAO,CAACE,MAAM,IAAIF,OAAO,CAACE,MAAM,KAAK,MAAM;EACrE,MAAMC,eAAe,GAClB,CAAC,CAAEH,OAAO,CAACI,IAAI,IAAIJ,OAAO,CAACI,IAAI,CAACC,OAAO,CAAE,cAAe,CAAC,KAAK,CAAC,CAAC,IAChE,CAAC,CAAEL,OAAO,CAACM,GAAG,IAAIN,OAAO,CAACM,GAAG,CAACD,OAAO,CAAE,cAAe,CAAC,KAAK,CAAC,CAAG;EAEnE,OAAOF,eAAe,IAAIF,cAAc;AACzC;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMM,qBAAyC,GAAGA,CAAEP,OAAO,EAAEQ,IAAI,KAAM;EACtE,IAAK,CAAET,oBAAoB,CAAEC,OAAQ,CAAC,EAAG;IACxC,OAAOQ,IAAI,CAAER,OAAQ,CAAC;EACvB;EAEA,IAAIS,OAAO,GAAG,CAAC;EACf,MAAMC,UAAU,GAAG,CAAC;;EAEpB;AACD;AACA;AACA;EACC,MAAMC,WAAW,GAAKC,YAAoB,IAAsB;IAC/DH,OAAO,EAAE;IACT,OAAOD,IAAI,CAAE;MACZJ,IAAI,EAAE,gBAAiBQ,YAAY,eAAgB;MACnDV,MAAM,EAAE,MAAM;MACdW,IAAI,EAAE;QAAEC,MAAM,EAAE;MAAwB,CAAC;MACzCC,KAAK,EAAE;IACR,CAAE,CAAC,CAACC,KAAK,CAAE,MAAM;MAChB,IAAKP,OAAO,GAAGC,UAAU,EAAG;QAC3B,OAAOC,WAAW,CAAEC,YAAa,CAAC;MACnC;MACAJ,IAAI,CAAE;QACLJ,IAAI,EAAE,gBAAiBQ,YAAY,aAAc;QACjDV,MAAM,EAAE;MACT,CAAE,CAAC;MAEH,OAAOe,OAAO,CAACC,MAAM,CAAC,CAAC;IACxB,CAAE,CAAC;EACJ,CAAC;EAED,OAAOV,IAAI,CAAE;IAAE,GAAGR,OAAO;IAAEe,KAAK,EAAE;EAAM,CAAE,CAAC,CACzCC,KAAK,CAAIG,QAAkB,IAAM;IACjC;IACA,IAAK,EAAIA,QAAQ,YAAYC,UAAU,CAACC,QAAQ,CAAE,EAAG;MACpD,OAAOJ,OAAO,CAACC,MAAM,CAAEC,QAAS,CAAC;IAClC;IAEA,MAAMP,YAAY,GAAGO,QAAQ,CAACG,OAAO,CAACC,GAAG,CACxC,2BACD,CAAC;IACD,IACCJ,QAAQ,CAACK,MAAM,IAAI,GAAG,IACtBL,QAAQ,CAACK,MAAM,GAAG,GAAG,IACrBZ,YAAY,EACX;MACD,OAAOD,WAAW,CAAEC,YAAa,CAAC,CAACI,KAAK,CAAE,MAAM;QAC/C,IAAKhB,OAAO,CAACe,KAAK,KAAK,KAAK,EAAG;UAC9B,OAAOE,OAAO,CAACC,MAAM,CAAE;YACtBO,IAAI,EAAE,cAAc;YACpBC,OAAO,EAAE9B,EAAE,CACV,+FACD;UACD,CAAE,CAAC;QACJ;QAEA,OAAOqB,OAAO,CAACC,MAAM,CAAEC,QAAS,CAAC;MAClC,CAAE,CAAC;IACJ;IACA,OAAOtB,kBAAkB,CAAEsB,QAAQ,EAAEnB,OAAO,CAACe,KAAM,CAAC;EACrD,CAAE,CAAC,CACFY,IAAI,CAAIR,QAAkB,IAC1BrB,8BAA8B,CAAEqB,QAAQ,EAAEnB,OAAO,CAACe,KAAM,CACzD,CAAC;AACH,CAAC;AAED,eAAeR,qBAAqB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["namespaceAndEndpointMiddleware","options","next","path","namespaceTrimmed","endpointTrimmed","namespace","endpoint","replace"],"sources":["@wordpress/api-fetch/src/middlewares/namespace-endpoint.
|
|
1
|
+
{"version":3,"names":["namespaceAndEndpointMiddleware","options","next","path","namespaceTrimmed","endpointTrimmed","namespace","endpoint","replace"],"sources":["@wordpress/api-fetch/src/middlewares/namespace-endpoint.ts"],"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"],"mappings":"AAAA;AACA;AACA;;AAGA,MAAMA,8BAAkD,GAAGA,CAC1DC,OAAO,EACPC,IAAI,KACA;EACJ,IAAIC,IAAI,GAAGF,OAAO,CAACE,IAAI;EACvB,IAAIC,gBAAgB,EAAEC,eAAe;EAErC,IACC,OAAOJ,OAAO,CAACK,SAAS,KAAK,QAAQ,IACrC,OAAOL,OAAO,CAACM,QAAQ,KAAK,QAAQ,EACnC;IACDH,gBAAgB,GAAGH,OAAO,CAACK,SAAS,CAACE,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC;IAC9DH,eAAe,GAAGJ,OAAO,CAACM,QAAQ,CAACC,OAAO,CAAE,KAAK,EAAE,EAAG,CAAC;IACvD,IAAKH,eAAe,EAAG;MACtBF,IAAI,GAAGC,gBAAgB,GAAG,GAAG,GAAGC,eAAe;IAChD,CAAC,MAAM;MACNF,IAAI,GAAGC,gBAAgB;IACxB;EACD;EAEA,OAAOH,OAAO,CAACK,SAAS;EACxB,OAAOL,OAAO,CAACM,QAAQ;EAEvB,OAAOL,IAAI,CAAE;IACZ,GAAGD,OAAO;IACVE;EACD,CAAE,CAAC;AACJ,CAAC;AAED,eAAeH,8BAA8B","ignoreList":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param nonce
|
|
7
|
+
*
|
|
8
|
+
* @return A middleware to enhance a request with a nonce.
|
|
4
9
|
*/
|
|
5
10
|
function createNonceMiddleware(nonce) {
|
|
6
|
-
/**
|
|
7
|
-
* @type {import('../types').APIFetchMiddleware & { nonce: string }}
|
|
8
|
-
*/
|
|
9
11
|
const middleware = (options, next) => {
|
|
10
12
|
const {
|
|
11
13
|
headers = {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createNonceMiddleware","nonce","middleware","options","next","headers","headerName","toLowerCase"],"sources":["@wordpress/api-fetch/src/middlewares/nonce.
|
|
1
|
+
{"version":3,"names":["createNonceMiddleware","nonce","middleware","options","next","headers","headerName","toLowerCase"],"sources":["@wordpress/api-fetch/src/middlewares/nonce.ts"],"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"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASA,qBAAqBA,CAC7BC,KAAa,EAC4B;EACzC,MAAMC,UAAkD,GAAGA,CAC1DC,OAAO,EACPC,IAAI,KACA;IACJ,MAAM;MAAEC,OAAO,GAAG,CAAC;IAAE,CAAC,GAAGF,OAAO;;IAEhC;IACA;IACA,KAAM,MAAMG,UAAU,IAAID,OAAO,EAAG;MACnC,IACCC,UAAU,CAACC,WAAW,CAAC,CAAC,KAAK,YAAY,IACzCF,OAAO,CAAEC,UAAU,CAAE,KAAKJ,UAAU,CAACD,KAAK,EACzC;QACD,OAAOG,IAAI,CAAED,OAAQ,CAAC;MACvB;IACD;IAEA,OAAOC,IAAI,CAAE;MACZ,GAAGD,OAAO;MACVE,OAAO,EAAE;QACR,GAAGA,OAAO;QACV,YAAY,EAAEH,UAAU,CAACD;MAC1B;IACD,CAAE,CAAC;EACJ,CAAC;EAEDC,UAAU,CAACD,KAAK,GAAGA,KAAK;EAExB,OAAOC,UAAU;AAClB;AAEA,eAAeF,qBAAqB","ignoreList":[]}
|
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
import { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param preloadedData
|
|
12
|
+
* @return Preloading middleware.
|
|
9
13
|
*/
|
|
10
14
|
function createPreloadingMiddleware(preloadedData) {
|
|
11
15
|
const cache = Object.fromEntries(Object.entries(preloadedData).map(([path, data]) => [normalizePath(path), data]));
|
|
@@ -13,7 +17,6 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
13
17
|
const {
|
|
14
18
|
parse = true
|
|
15
19
|
} = options;
|
|
16
|
-
/** @type {string | void} */
|
|
17
20
|
let rawPath = options.path;
|
|
18
21
|
if (!rawPath && options.url) {
|
|
19
22
|
const {
|
|
@@ -49,9 +52,9 @@ function createPreloadingMiddleware(preloadedData) {
|
|
|
49
52
|
/**
|
|
50
53
|
* This is a helper function that sends a success response.
|
|
51
54
|
*
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @return
|
|
55
|
+
* @param responseData
|
|
56
|
+
* @param parse
|
|
57
|
+
* @return Promise with the response.
|
|
55
58
|
*/
|
|
56
59
|
function prepareResponse(responseData, parse) {
|
|
57
60
|
if (parse) {
|
|
@@ -67,7 +70,7 @@ function prepareResponse(responseData, parse) {
|
|
|
67
70
|
// See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926.
|
|
68
71
|
Object.entries(responseData.headers).forEach(([key, value]) => {
|
|
69
72
|
if (key.toLowerCase() === 'link') {
|
|
70
|
-
responseData.headers[key] = value.replace(/<([^>]+)>/, (
|
|
73
|
+
responseData.headers[key] = value.replace(/<([^>]+)>/, (_, url) => `<${encodeURI(url)}>`);
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addQueryArgs","getQueryArgs","normalizePath","createPreloadingMiddleware","preloadedData","cache","Object","fromEntries","entries","map","path","data","options","next","parse","rawPath","url","rest_route","pathFromQuery","queryArgs","method","cacheData","prepareResponse","responseData","Promise","resolve","body","window","Response","JSON","stringify","status","statusText","headers","forEach","key","value","toLowerCase","replace","_","encodeURI"],"sources":["@wordpress/api-fetch/src/middlewares/preloading.
|
|
1
|
+
{"version":3,"names":["addQueryArgs","getQueryArgs","normalizePath","createPreloadingMiddleware","preloadedData","cache","Object","fromEntries","entries","map","path","data","options","next","parse","rawPath","url","rest_route","pathFromQuery","queryArgs","method","cacheData","prepareResponse","responseData","Promise","resolve","body","window","Response","JSON","stringify","status","statusText","headers","forEach","key","value","toLowerCase","replace","_","encodeURI"],"sources":["@wordpress/api-fetch/src/middlewares/preloading.ts"],"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"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import namespaceAndEndpointMiddleware from './namespace-endpoint';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* @param
|
|
8
|
-
* @return
|
|
8
|
+
* @param rootURL
|
|
9
|
+
* @return Root URL middleware.
|
|
9
10
|
*/
|
|
10
11
|
const createRootURLMiddleware = rootURL => (options, next) => {
|
|
11
12
|
return namespaceAndEndpointMiddleware(options, optionsWithPath => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["namespaceAndEndpointMiddleware","createRootURLMiddleware","rootURL","options","next","optionsWithPath","url","path","apiRoot","indexOf","replace"],"sources":["@wordpress/api-fetch/src/middlewares/root-url.
|
|
1
|
+
{"version":3,"names":["namespaceAndEndpointMiddleware","createRootURLMiddleware","rootURL","options","next","optionsWithPath","url","path","apiRoot","indexOf","replace"],"sources":["@wordpress/api-fetch/src/middlewares/root-url.ts"],"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"],"mappings":"AAAA;AACA;AACA;;AAEA,OAAOA,8BAA8B,MAAM,sBAAsB;;AAEjE;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAC1BC,OAAe,IACjB,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACpB,OAAOJ,8BAA8B,CAAEG,OAAO,EAAIE,eAAe,IAAM;IACtE,IAAIC,GAAG,GAAGD,eAAe,CAACC,GAAG;IAC7B,IAAIC,IAAI,GAAGF,eAAe,CAACE,IAAI;IAC/B,IAAIC,OAAO;IAEX,IAAK,OAAOD,IAAI,KAAK,QAAQ,EAAG;MAC/BC,OAAO,GAAGN,OAAO;MAEjB,IAAK,CAAC,CAAC,KAAKA,OAAO,CAACO,OAAO,CAAE,GAAI,CAAC,EAAG;QACpCF,IAAI,GAAGA,IAAI,CAACG,OAAO,CAAE,GAAG,EAAE,GAAI,CAAC;MAChC;MAEAH,IAAI,GAAGA,IAAI,CAACG,OAAO,CAAE,KAAK,EAAE,EAAG,CAAC;;MAEhC;MACA;MACA,IACC,QAAQ,KAAK,OAAOF,OAAO,IAC3B,CAAC,CAAC,KAAKA,OAAO,CAACC,OAAO,CAAE,GAAI,CAAC,EAC5B;QACDF,IAAI,GAAGA,IAAI,CAACG,OAAO,CAAE,GAAG,EAAE,GAAI,CAAC;MAChC;MAEAJ,GAAG,GAAGE,OAAO,GAAGD,IAAI;IACrB;IAEA,OAAOH,IAAI,CAAE;MACZ,GAAGC,eAAe;MAClBC;IACD,CAAE,CAAC;EACJ,CAAE,CAAC;AACJ,CAAC;AAEF,eAAeL,uBAAuB","ignoreList":[]}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* This appends a `wp_theme_preview` parameter to the REST API request URL if
|
|
@@ -10,8 +13,8 @@ import { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url';
|
|
|
10
13
|
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
|
|
11
14
|
* then bypass this middleware.
|
|
12
15
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @return
|
|
16
|
+
* @param themePath
|
|
17
|
+
* @return Preloading middleware.
|
|
15
18
|
*/
|
|
16
19
|
const createThemePreviewMiddleware = themePath => (options, next) => {
|
|
17
20
|
if (typeof options.url === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addQueryArgs","getQueryArg","removeQueryArgs","createThemePreviewMiddleware","themePath","options","next","url","wpThemePreview","undefined","wp_theme_preview","path"],"sources":["@wordpress/api-fetch/src/middlewares/theme-preview.
|
|
1
|
+
{"version":3,"names":["addQueryArgs","getQueryArg","removeQueryArgs","createThemePreviewMiddleware","themePath","options","next","url","wpThemePreview","undefined","wp_theme_preview","path"],"sources":["@wordpress/api-fetch/src/middlewares/theme-preview.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,WAAW,EAAEC,eAAe,QAAQ,gBAAgB;AAC3E;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,4BAA4B,GAC/BC,SAAgC,IAClC,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACpB,IAAK,OAAOD,OAAO,CAACE,GAAG,KAAK,QAAQ,EAAG;IACtC,MAAMC,cAAc,GAAGP,WAAW,CACjCI,OAAO,CAACE,GAAG,EACX,kBACD,CAAC;IACD,IAAKC,cAAc,KAAKC,SAAS,EAAG;MACnCJ,OAAO,CAACE,GAAG,GAAGP,YAAY,CAAEK,OAAO,CAACE,GAAG,EAAE;QACxCG,gBAAgB,EAAEN;MACnB,CAAE,CAAC;IACJ,CAAC,MAAM,IAAKI,cAAc,KAAK,EAAE,EAAG;MACnCH,OAAO,CAACE,GAAG,GAAGL,eAAe,CAC5BG,OAAO,CAACE,GAAG,EACX,kBACD,CAAC;IACF;EACD;EAEA,IAAK,OAAOF,OAAO,CAACM,IAAI,KAAK,QAAQ,EAAG;IACvC,MAAMH,cAAc,GAAGP,WAAW,CACjCI,OAAO,CAACM,IAAI,EACZ,kBACD,CAAC;IACD,IAAKH,cAAc,KAAKC,SAAS,EAAG;MACnCJ,OAAO,CAACM,IAAI,GAAGX,YAAY,CAAEK,OAAO,CAACM,IAAI,EAAE;QAC1CD,gBAAgB,EAAEN;MACnB,CAAE,CAAC;IACJ,CAAC,MAAM,IAAKI,cAAc,KAAK,EAAE,EAAG;MACnCH,OAAO,CAACM,IAAI,GAAGT,eAAe,CAC7BG,OAAO,CAACM,IAAI,EACZ,kBACD,CAAC;IACF;EACD;EAEA,OAAOL,IAAI,CAAED,OAAQ,CAAC;AACvB,CAAC;AAEF,eAAeF,4BAA4B","ignoreList":[]}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
import { addQueryArgs, hasQueryArg } from '@wordpress/url';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
const userLocaleMiddleware = (options, next) => {
|
|
10
11
|
if (typeof options.url === 'string' && !hasQueryArg(options.url, '_locale')) {
|
|
11
12
|
options.url = addQueryArgs(options.url, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addQueryArgs","hasQueryArg","userLocaleMiddleware","options","next","url","_locale","path"],"sources":["@wordpress/api-fetch/src/middlewares/user-locale.
|
|
1
|
+
{"version":3,"names":["addQueryArgs","hasQueryArg","userLocaleMiddleware","options","next","url","_locale","path"],"sources":["@wordpress/api-fetch/src/middlewares/user-locale.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,WAAW,QAAQ,gBAAgB;;AAE1D;AACA;AACA;;AAGA,MAAMC,oBAAwC,GAAGA,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACrE,IACC,OAAOD,OAAO,CAACE,GAAG,KAAK,QAAQ,IAC/B,CAAEJ,WAAW,CAAEE,OAAO,CAACE,GAAG,EAAE,SAAU,CAAC,EACtC;IACDF,OAAO,CAACE,GAAG,GAAGL,YAAY,CAAEG,OAAO,CAACE,GAAG,EAAE;MAAEC,OAAO,EAAE;IAAO,CAAE,CAAC;EAC/D;EAEA,IACC,OAAOH,OAAO,CAACI,IAAI,KAAK,QAAQ,IAChC,CAAEN,WAAW,CAAEE,OAAO,CAACI,IAAI,EAAE,SAAU,CAAC,EACvC;IACDJ,OAAO,CAACI,IAAI,GAAGP,YAAY,CAAEG,OAAO,CAACI,IAAI,EAAE;MAAED,OAAO,EAAE;IAAO,CAAE,CAAC;EACjE;EAEA,OAAOF,IAAI,CAAED,OAAQ,CAAC;AACvB,CAAC;AAED,eAAeD,oBAAoB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/api-fetch/src/types.ts"],"sourcesContent":["export interface APIFetchOptions extends 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?:
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/api-fetch/src/types.ts"],"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"],"mappings":"","ignoreList":[]}
|
|
@@ -3,73 +3,55 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Parses the apiFetch response.
|
|
8
|
-
*
|
|
9
|
-
* @param {Response} response
|
|
10
|
-
* @param {boolean} shouldParseResponse
|
|
11
|
-
*
|
|
12
|
-
* @return {Promise<any> | null | Response} Parsed response.
|
|
13
|
-
*/
|
|
14
|
-
const parseResponse = (response, shouldParseResponse = true) => {
|
|
15
|
-
if (shouldParseResponse) {
|
|
16
|
-
if (response.status === 204) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return response.json ? response.json() : Promise.reject(response);
|
|
20
|
-
}
|
|
21
|
-
return response;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
6
|
/**
|
|
25
7
|
* Calls the `json` function on the Response, throwing an error if the response
|
|
26
8
|
* doesn't have a json function or if parsing the json itself fails.
|
|
27
9
|
*
|
|
28
|
-
* @param
|
|
29
|
-
* @return
|
|
10
|
+
* @param response
|
|
11
|
+
* @return Parsed response.
|
|
30
12
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
13
|
+
async function parseJsonAndNormalizeError(response) {
|
|
14
|
+
try {
|
|
15
|
+
return await response.json();
|
|
16
|
+
} catch {
|
|
17
|
+
throw {
|
|
18
|
+
code: 'invalid_json',
|
|
19
|
+
message: __('The response is not a valid JSON response.')
|
|
20
|
+
};
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
throw invalidJsonError;
|
|
41
|
-
});
|
|
42
|
-
};
|
|
22
|
+
}
|
|
43
23
|
|
|
44
24
|
/**
|
|
45
25
|
* Parses the apiFetch response properly and normalize response errors.
|
|
46
26
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
27
|
+
* @param response
|
|
28
|
+
* @param shouldParseResponse
|
|
49
29
|
*
|
|
50
|
-
* @return
|
|
30
|
+
* @return Parsed response.
|
|
51
31
|
*/
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
export async function parseResponseAndNormalizeError(response, shouldParseResponse = true) {
|
|
33
|
+
if (!shouldParseResponse) {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
if (response.status === 204) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return await parseJsonAndNormalizeError(response);
|
|
40
|
+
}
|
|
55
41
|
|
|
56
42
|
/**
|
|
57
43
|
* Parses a response, throwing an error if parsing the response fails.
|
|
58
44
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @return
|
|
45
|
+
* @param response
|
|
46
|
+
* @param shouldParseResponse
|
|
47
|
+
* @return Never returns, always throws.
|
|
62
48
|
*/
|
|
63
|
-
export function parseAndThrowError(response, shouldParseResponse = true) {
|
|
49
|
+
export async function parseAndThrowError(response, shouldParseResponse = true) {
|
|
64
50
|
if (!shouldParseResponse) {
|
|
65
51
|
throw response;
|
|
66
52
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
message: __('An unknown error occurred.')
|
|
71
|
-
};
|
|
72
|
-
throw error || unknownError;
|
|
73
|
-
});
|
|
53
|
+
|
|
54
|
+
// Parse the response JSON and throw it as an error.
|
|
55
|
+
throw await parseJsonAndNormalizeError(response);
|
|
74
56
|
}
|
|
75
57
|
//# sourceMappingURL=response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__","
|
|
1
|
+
{"version":3,"names":["__","parseJsonAndNormalizeError","response","json","code","message","parseResponseAndNormalizeError","shouldParseResponse","status","parseAndThrowError"],"sources":["@wordpress/api-fetch/src/utils/response.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,0BAA0BA,CAAEC,QAAkB,EAAG;EAC/D,IAAI;IACH,OAAO,MAAMA,QAAQ,CAACC,IAAI,CAAC,CAAC;EAC7B,CAAC,CAAC,MAAM;IACP,MAAM;MACLC,IAAI,EAAE,cAAc;MACpBC,OAAO,EAAEL,EAAE,CAAE,4CAA6C;IAC3D,CAAC;EACF;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeM,8BAA8BA,CACnDJ,QAAkB,EAClBK,mBAAmB,GAAG,IAAI,EACzB;EACD,IAAK,CAAEA,mBAAmB,EAAG;IAC5B,OAAOL,QAAQ;EAChB;EAEA,IAAKA,QAAQ,CAACM,MAAM,KAAK,GAAG,EAAG;IAC9B,OAAO,IAAI;EACZ;EAEA,OAAO,MAAMP,0BAA0B,CAAEC,QAAS,CAAC;AACpD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeO,kBAAkBA,CACvCP,QAAkB,EAClBK,mBAAmB,GAAG,IAAI,EACzB;EACD,IAAK,CAAEA,mBAAmB,EAAG;IAC5B,MAAML,QAAQ;EACf;;EAEA;EACA,MAAM,MAAMD,0BAA0B,CAAEC,QAAS,CAAC;AACnD","ignoreList":[]}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1,40 +1,33 @@
|
|
|
1
|
-
export default apiFetch;
|
|
2
|
-
export type APIFetchMiddleware = import("./types").APIFetchMiddleware;
|
|
3
|
-
export type APIFetchOptions = import("./types").APIFetchOptions;
|
|
4
|
-
export type FetchHandler = (options: import("./types").APIFetchOptions) => Promise<any>;
|
|
5
|
-
/**
|
|
6
|
-
* @template T
|
|
7
|
-
* @param {import('./types').APIFetchOptions} options
|
|
8
|
-
* @return {Promise<T>} A promise representing the request processed via the registered middlewares.
|
|
9
|
-
*/
|
|
10
|
-
declare function apiFetch<T>(options: import("./types").APIFetchOptions): Promise<T>;
|
|
11
|
-
declare namespace apiFetch {
|
|
12
|
-
export { registerMiddleware as use };
|
|
13
|
-
export { setFetchHandler };
|
|
14
|
-
export { createNonceMiddleware };
|
|
15
|
-
export { createPreloadingMiddleware };
|
|
16
|
-
export { createRootURLMiddleware };
|
|
17
|
-
export { fetchAllMiddleware };
|
|
18
|
-
export { mediaUploadMiddleware };
|
|
19
|
-
export { createThemePreviewMiddleware };
|
|
20
|
-
}
|
|
21
1
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param {import('./types').APIFetchMiddleware} middleware
|
|
25
|
-
*/
|
|
26
|
-
declare function registerMiddleware(middleware: import("./types").APIFetchMiddleware): void;
|
|
27
|
-
/**
|
|
28
|
-
* Defines a custom fetch handler for making the requests that will override
|
|
29
|
-
* the default one using window.fetch
|
|
30
|
-
*
|
|
31
|
-
* @param {FetchHandler} newFetchHandler The new fetch handler
|
|
2
|
+
* Internal dependencies
|
|
32
3
|
*/
|
|
33
|
-
declare function setFetchHandler(newFetchHandler: FetchHandler): void;
|
|
34
4
|
import createNonceMiddleware from './middlewares/nonce';
|
|
35
|
-
import createPreloadingMiddleware from './middlewares/preloading';
|
|
36
5
|
import createRootURLMiddleware from './middlewares/root-url';
|
|
6
|
+
import createPreloadingMiddleware from './middlewares/preloading';
|
|
37
7
|
import fetchAllMiddleware from './middlewares/fetch-all-middleware';
|
|
38
8
|
import mediaUploadMiddleware from './middlewares/media-upload';
|
|
39
9
|
import createThemePreviewMiddleware from './middlewares/theme-preview';
|
|
10
|
+
import type { APIFetchMiddleware, APIFetchOptions, FetchHandler } from './types';
|
|
11
|
+
interface apiFetch {
|
|
12
|
+
<T, Parse extends boolean = true>(options: APIFetchOptions<Parse>): Promise<Parse extends true ? T : Response>;
|
|
13
|
+
nonceEndpoint?: string;
|
|
14
|
+
nonceMiddleware?: ReturnType<typeof createNonceMiddleware>;
|
|
15
|
+
use: (middleware: APIFetchMiddleware) => void;
|
|
16
|
+
setFetchHandler: (newFetchHandler: FetchHandler) => void;
|
|
17
|
+
createNonceMiddleware: typeof createNonceMiddleware;
|
|
18
|
+
createPreloadingMiddleware: typeof createPreloadingMiddleware;
|
|
19
|
+
createRootURLMiddleware: typeof createRootURLMiddleware;
|
|
20
|
+
fetchAllMiddleware: typeof fetchAllMiddleware;
|
|
21
|
+
mediaUploadMiddleware: typeof mediaUploadMiddleware;
|
|
22
|
+
createThemePreviewMiddleware: typeof createThemePreviewMiddleware;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetch
|
|
26
|
+
*
|
|
27
|
+
* @param options The options for the fetch.
|
|
28
|
+
* @return A promise representing the request processed via the registered middlewares.
|
|
29
|
+
*/
|
|
30
|
+
declare const apiFetch: apiFetch;
|
|
31
|
+
export default apiFetch;
|
|
32
|
+
export * from './types';
|
|
40
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,qBAAqB,MAAM,qBAAqB,CAAC;AACxD,OAAO,uBAAuB,MAAM,wBAAwB,CAAC;AAC7D,OAAO,0BAA0B,MAAM,0BAA0B,CAAC;AAClE,OAAO,kBAAkB,MAAM,oCAAoC,CAAC;AAIpE,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAC/D,OAAO,4BAA4B,MAAM,6BAA6B,CAAC;AAKvE,OAAO,KAAK,EACX,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,MAAM,SAAS,CAAC;AAgHjB,UAAU,QAAQ;IACjB,CAAE,CAAC,EAAE,KAAK,SAAS,OAAO,GAAG,IAAI,EAChC,OAAO,EAAE,eAAe,CAAE,KAAK,CAAE,GAC/B,OAAO,CAAE,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,QAAQ,CAAE,CAAC;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,UAAU,CAAE,OAAO,qBAAqB,CAAE,CAAC;IAC7D,GAAG,EAAE,CAAE,UAAU,EAAE,kBAAkB,KAAM,IAAI,CAAC;IAChD,eAAe,EAAE,CAAE,eAAe,EAAE,YAAY,KAAM,IAAI,CAAC;IAC3D,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IACpD,0BAA0B,EAAE,OAAO,0BAA0B,CAAC;IAC9D,uBAAuB,EAAE,OAAO,uBAAuB,CAAC;IACxD,kBAAkB,EAAE,OAAO,kBAAkB,CAAC;IAC9C,qBAAqB,EAAE,OAAO,qBAAqB,CAAC;IACpD,4BAA4B,EAAE,OAAO,4BAA4B,CAAC;CAClE;AAED;;;;;GAKG;AACH,QAAA,MAAM,QAAQ,EAAE,QAmCf,CAAC;AAYF,eAAe,QAAQ,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { APIFetchMiddleware } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* The REST API enforces an upper limit on the per_page option. To handle large
|
|
4
4
|
* collections, apiFetch consumers can pass `per_page=-1`; this middleware will
|
|
5
5
|
* then recursively assemble a full response array from all available pages.
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
6
|
+
* @param options
|
|
7
|
+
* @param next
|
|
8
8
|
*/
|
|
9
|
-
declare const fetchAllMiddleware:
|
|
9
|
+
declare const fetchAllMiddleware: APIFetchMiddleware;
|
|
10
|
+
export default fetchAllMiddleware;
|
|
10
11
|
//# sourceMappingURL=fetch-all-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-all-middleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/fetch-all-middleware.
|
|
1
|
+
{"version":3,"file":"fetch-all-middleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/fetch-all-middleware.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,UAAU,CAAC;AAgEpE;;;;;;GAMG;AACH,QAAA,MAAM,kBAAkB,EAAE,kBAiDzB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { APIFetchMiddleware } from '../types';
|
|
2
5
|
/**
|
|
3
6
|
* API Fetch middleware which overrides the request method for HTTP v1
|
|
4
7
|
* compatibility leveraging the REST API X-HTTP-Method-Override header.
|
|
5
8
|
*
|
|
6
|
-
* @
|
|
9
|
+
* @param options
|
|
10
|
+
* @param next
|
|
7
11
|
*/
|
|
8
|
-
declare const httpV1Middleware:
|
|
12
|
+
declare const httpV1Middleware: APIFetchMiddleware;
|
|
13
|
+
export default httpV1Middleware;
|
|
9
14
|
//# sourceMappingURL=http-v1.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-v1.d.ts","sourceRoot":"","sources":["../../src/middlewares/http-v1.
|
|
1
|
+
{"version":3,"file":"http-v1.d.ts","sourceRoot":"","sources":["../../src/middlewares/http-v1.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAiBnD;;;;;;GAMG;AACH,QAAA,MAAM,gBAAgB,EAAE,kBAevB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|