You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@wordpress/api-fetch

Package Overview
Dependencies
Maintainers
23
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/api-fetch - npm Package Compare versions

Comparing version
5.2.5
to
5.2.6
+11
-8
build-module/middlewares/fetch-all-middleware.js

@@ -18,10 +18,13 @@ /**

const modifyQuery = ({
path,
url,
...options
}, queryArgs) => ({ ...options,
url: url && addQueryArgs(url, queryArgs),
path: path && addQueryArgs(path, queryArgs)
});
const modifyQuery = (_ref, queryArgs) => {
let {
path,
url,
...options
} = _ref;
return { ...options,
url: url && addQueryArgs(url, queryArgs),
path: path && addQueryArgs(path, queryArgs)
};
};
/**

@@ -28,0 +31,0 @@ * Duplicates parsing functionality from apiFetch.

@@ -1,1 +0,1 @@

{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["addQueryArgs","apiFetch","modifyQuery","path","url","options","queryArgs","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,IAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,CAAE;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,GAAR;AAAa,KAAGC;AAAhB,CAAF,EAA6BC,SAA7B,MAA8C,EACjE,GAAGD,OAD8D;AAEjED,EAAAA,GAAG,EAAEA,GAAG,IAAIJ,YAAY,CAAEI,GAAF,EAAOE,SAAP,CAFyC;AAGjEH,EAAAA,IAAI,EAAEA,IAAI,I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ryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["addQueryArgs","apiFetch","modifyQuery","queryArgs","path","url","options","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAA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AAAA,KAAK,EAAE;AAN6B,KAAF,CAAnC;AAQA,UAAMU,WAAW,GAAG,MAAM3B,aAAa,CAAEyB,YAAF,CAAvC;AACAF,IAAAA,aAAa,GAAGA,aAAa,CAACC,MAAd,CAAsBG,WAAtB,CAAhB;AACAL,IAAAA,QAAQ,GAAGb,cAAc,CAAEgB,YAAF,CAAzB;AACA;;AACD,SAAOF,aAAP;AACA,CAjDD;;AAmDA,eAAeP,kBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}

@@ -1,2 +0,2 @@

export {};
//# sourceMappingURL=types.js.map

@@ -14,3 +14,5 @@ /**

const parseResponse = (response, shouldParseResponse = true) => {
const parseResponse = function (response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (shouldParseResponse) {

@@ -59,3 +61,4 @@ if (response.status === 204) {

export const parseResponseAndNormalizeError = (response, shouldParseResponse = true) => {
export const parseResponseAndNormalizeError = function (response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return Promise.resolve(parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));

@@ -71,3 +74,5 @@ };

export function parseAndThrowError(response, shouldParseResponse = true) {
export function parseAndThrowError(response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!shouldParseResponse) {

@@ -74,0 +79,0 @@ throw response;

@@ -1,1 +0,1 @@

{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,aAAa,GAAG,CAAEC,QAAF,EAAYC,mBAAmB,GAAG,IAAlC,KAA4C;AACjE,MAAKA,mBAAL,EAA2B;AAC1B,QAAKD,QAAQ,CAACE,MAAT,KAAoB,GAAzB,EAA+B;AAC9B,aAAO,IAAP;AACA;;AAED,WAAOF,QAAQ,CAACG,IAAT,GAAgBH,QAAQ,CAACG,IAAT,EAAhB,GAAkCC,OAAO,CAACC,MAAR,CAAgBL,QAAhB,CAAzC;AACA;;AAED,SAAOA,QAAP;AACA,CAVD;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMM,0BAA0B,GAAKN,QAAF,IAAgB;AAClD,QAAMO,gBAAgB,GAAG;AACxBC,IAAAA,IAAI,EAAE,cADkB;AAExBC,IAAAA,OAAO,EAAEX,EAAE,CAAE,4CAAF;AAFa,GAAzB;;AAKA,MAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACG,IAA9B,EAAqC;AACpC,UAAMI,gBAAN;AACA;;AAED,SAAOP,QAAQ,CAACG,IAAT,GAAgBO,KAAhB,CAAuB,MAAM;AACnC,UAAMH,gBAAN;AACA,GAFM,CAAP;AAGA,CAbD;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMI,8BAA8B,GAAG,CAC7CX,QAD6C,EAE7CC,mBAAmB,GAAG,IAFuB,KAGzC;AACJ,SAAOG,OAAO,CAACQ,OAAR,CACNb,aAAa,CAAEC,QAAF,EAAYC,mBAAZ,CADP,EAELS,KAFK,CAEIG,GAAF,IAAWC,kBAAkB,CAAED,GAAF,EAAOZ,mBAAP,CAF/B,CAAP;AAGA,CAPM;AASP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASa,kBAAT,CAA6Bd,QAA7B,EAAuCC,mBAAmB,GAAG,IAA7D,EAAoE;AAC1E,MAAK,CAAEA,mBAAP,EAA6B;AAC5B,UAAMD,QAAN;AACA;;AAED,SAAOM,0BAA0B,CAAEN,QAAF,CAA1B,CAAuCe,IAAvC,CAA+CC,KAAF,IAAa;AAChE,UAAMC,YAAY,GAAG;AACpBT,MAAAA,IAAI,EAAE,eADc;AAEpBC,MAAAA,OAAO,EAAEX,EAAE,CAAE,4BAAF;AAFS,KAArB;AAKA,UAAMkB,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\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} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AAEA;AACA;A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B,UAAMD,QAAN;AACA;;AAED,SAAOM,0BAA0B,CAAEN,QAAF,CAA1B,CAAuCe,IAAvC,CAA+CC,KAAF,IAAa;AAChE,UAAMC,YAAY,GAAG;AACpBT,MAAAA,IAAI,EAAE,eADc;AAEpBC,MAAAA,OAAO,EAAEX,EAAE,CAAE,4BAAF;AAFS,KAArB;AAKA,UAAMkB,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\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} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}

@@ -29,10 +29,13 @@ "use strict";

*/
const modifyQuery = ({
path,
url,
...options
}, queryArgs) => ({ ...options,
url: url && (0, _url.addQueryArgs)(url, queryArgs),
path: path && (0, _url.addQueryArgs)(path, queryArgs)
});
const modifyQuery = (_ref, queryArgs) => {
let {
path,
url,
...options
} = _ref;
return { ...options,
url: url && (0, _url.addQueryArgs)(url, queryArgs),
path: path && (0, _url.addQueryArgs)(path, queryArgs)
};
};
/**

@@ -39,0 +42,0 @@ * Duplicates parsing functionality from apiFetch.

@@ -1,1 +0,1 @@

{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["modifyQuery","path","url","options","queryArgs","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,CAAE;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,GAAR;AAAa,KAAGC;AAAhB,CAAF,EAA6BC,SAA7B,MAA8C,EACjE,GAAGD,OAD8D;AAEjED,EAAAA,GAAG,EAAEA,GAAG,IAAI,uBAAcA,GAAd,EAAmBE,SAAnB,CAFqD;AAGjEH,EAAAA,IAAI,EAAEA,IAAI,IAAI,uBAAcA,IAAd,EAAoBG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T,IAAI,CAAEV,OAAF,CAAX;AACA;;AACD,MAAK,CAAEc,6BAA6B,CAAEd,OAAF,CAApC,EAAkD;AACjD;AACA,WAAOU,IAAI,CAAEV,OAAF,CAAX;AACA,GARoD,CAUrD;;;AACA,QAAMG,QAAQ,GAAG,MAAM,eAAU,EAChC,GAAGN,WAAW,CAAEG,OAAF,EAAW;AACxBoB,MAAAA,QAAQ,EAAE;AADc,KAAX,CADkB;AAIhC;AACAD,IAAAA,KAAK,EAAE;AALyB,GAAV,CAAvB;AAQA,QAAME,OAAO,GAAG,MAAMnB,aAAa,CAAEC,QAAF,CAAnC;;AAEA,MAAK,CAAEmB,KAAK,CAACC,OAAN,CAAeF,OAAf,CAAP,EAAkC;AACjC;AACA,WAAOA,OAAP;AACA;;AAED,MAAIG,QAAQ,GAAGb,cAAc,CAAER,QAAF,CAA7B;;AAEA,MAAK,CAAEqB,QAAP,EAAkB;AACjB;AACA,WAAOH,OAAP;AACA,GA/BoD,CAiCrD;;;AACA,MAAII,aAAa;AAAG;AAAuB,IAAF,CAAOC,MAAP,CAAeL,OAAf,CAAzC;;AACA,SAAQG,QAAR,EAAmB;AAClB,UAAMG,YAAY,GAAG,MAAM,eAAU,EACpC,GAAG3B,OADiC;AAEpC;AACAF,MAAAA,IAAI,EAAE8B,SAH8B;AAIpC7B,MAAAA,GAAG,EAAEyB,QAJ+B;AAKpC;AACAL,MAAAA,KAAK,EAAE;AAN6B,KAAV,CAA3B;AAQA,UAAMU,WAAW,GAAG,MAAM3B,aAAa,CAAEyB,YAAF,CAAvC;AACAF,IAAAA,aAAa,GAAGA,aAAa,CAACC,MAAd,CAAsBG,WAAtB,CAAhB;AACAL,IAAAA,QAAQ,GAAGb,cAAc,CAAEgB,YAAF,CAAzB;AACA;;AACD,SAAOF,aAAP;AACA,CAjDD;;eAmDeP,kB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}
{"version":3,"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.js"],"names":["modifyQuery","queryArgs","path","url","options","parseResponse","response","json","Promise","reject","parseLinkHeader","linkHeader","match","next","getNextPageUrl","headers","get","requestContainsUnboundedQuery","pathIsUnbounded","indexOf","urlIsUnbounded","fetchAllMiddleware","parse","per_page","results","Array","isArray","nextPage","mergedResults","concat","nextResponse","undefined","nextResults"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAAG,OAA6BC,SAA7B;AAAA,MAAE;AAAEC,IAAAA,IAA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d,CAAsBG,WAAtB,CAAhB;AACAL,IAAAA,QAAQ,GAAGb,cAAc,CAAEgB,YAAF,CAAzB;AACA;;AACD,SAAOF,aAAP;AACA,CAjDD;;eAmDeP,kB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {import('../types').APIFetchOptions} props\n * @param {Record<string, string | number>} queryArgs\n * @return {import('../types').APIFetchOptions} The request with the modified query args\n */\nconst modifyQuery = ( { path, url, ...options }, queryArgs ) => ( {\n\t...options,\n\turl: url && addQueryArgs( url, queryArgs ),\n\tpath: path && addQueryArgs( path, queryArgs ),\n} );\n\n/**\n * Duplicates parsing functionality from apiFetch.\n *\n * @param {Response} response\n * @return {Promise<any>} Parsed response json.\n */\nconst parseResponse = ( response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param {string | null} linkHeader\n * @return {{ next?: string }} The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader ) => {\n\tif ( ! linkHeader ) {\n\t\treturn {};\n\t}\n\tconst match = linkHeader.match( /<([^>]+)>; rel=\"next\"/ );\n\treturn match\n\t\t? {\n\t\t\t\tnext: match[ 1 ],\n\t\t }\n\t\t: {};\n};\n\n/**\n * @param {Response} response\n * @return {string | undefined} The next page URL.\n */\nconst getNextPageUrl = ( response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param {import('../types').APIFetchOptions} options\n * @return {boolean} True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options ) => {\n\tconst pathIsUnbounded =\n\t\t!! options.path && options.path.indexOf( 'per_page=-1' ) !== -1;\n\tconst urlIsUnbounded =\n\t\t!! options.url && options.url.indexOf( 'per_page=-1' ) !== -1;\n\treturn pathIsUnbounded || urlIsUnbounded;\n};\n\n/**\n * The REST API enforces an upper limit on the per_page option. To handle large\n * collections, apiFetch consumers can pass `per_page=-1`; this middleware will\n * then recursively assemble a full response array from all available pages.\n *\n * @type {import('../types').APIFetchMiddleware}\n */\nconst fetchAllMiddleware = async ( options, next ) => {\n\tif ( options.parse === false ) {\n\t\t// If a consumer has opted out of parsing, do not apply middleware.\n\t\treturn next( options );\n\t}\n\tif ( ! requestContainsUnboundedQuery( options ) ) {\n\t\t// If neither url nor path is requesting all items, do not apply middleware.\n\t\treturn next( options );\n\t}\n\n\t// Retrieve requested page of results.\n\tconst response = await apiFetch( {\n\t\t...modifyQuery( options, {\n\t\t\tper_page: 100,\n\t\t} ),\n\t\t// Ensure headers are returned for page 1.\n\t\tparse: false,\n\t} );\n\n\tconst results = await parseResponse( response );\n\n\tif ( ! Array.isArray( results ) ) {\n\t\t// We have no reliable way of merging non-array results.\n\t\treturn results;\n\t}\n\n\tlet nextPage = getNextPageUrl( response );\n\n\tif ( ! nextPage ) {\n\t\t// There are no further pages to request.\n\t\treturn results;\n\t}\n\n\t// Iteratively fetch all remaining pages until no \"next\" header is found.\n\tlet mergedResults = /** @type {any[]} */ ( [] ).concat( results );\n\twhile ( nextPage ) {\n\t\tconst nextResponse = await apiFetch( {\n\t\t\t...options,\n\t\t\t// Ensure the URL for the next page is used instead of any provided path.\n\t\t\tpath: undefined,\n\t\t\turl: nextPage,\n\t\t\t// Ensure we still get headers so we can identify the next page.\n\t\t\tparse: false,\n\t\t} );\n\t\tconst nextResults = await parseResponse( nextResponse );\n\t\tmergedResults = mergedResults.concat( nextResults );\n\t\tnextPage = getNextPageUrl( nextResponse );\n\t}\n\treturn mergedResults;\n};\n\nexport default fetchAllMiddleware;\n"]}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

@@ -23,3 +23,5 @@ "use strict";

*/
const parseResponse = (response, shouldParseResponse = true) => {
const parseResponse = function (response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (shouldParseResponse) {

@@ -68,3 +70,4 @@ if (response.status === 204) {

const parseResponseAndNormalizeError = (response, shouldParseResponse = true) => {
const parseResponseAndNormalizeError = function (response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
return Promise.resolve(parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));

@@ -83,3 +86,5 @@ };

function parseAndThrowError(response, shouldParseResponse = true) {
function parseAndThrowError(response) {
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!shouldParseResponse) {

@@ -86,0 +91,0 @@ throw response;

@@ -1,1 +0,1 @@

{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,CAAEC,QAAF,EAAYC,mBAAmB,GAAG,IAAlC,KAA4C;AACjE,MAAKA,mBAAL,EAA2B;AAC1B,QAAKD,QAAQ,CAACE,MAAT,KAAoB,GAAzB,EAA+B;AAC9B,aAAO,IAAP;AACA;;AAED,WAAOF,QAAQ,CAACG,IAAT,GAAgBH,QAAQ,CAACG,IAAT,EAAhB,GAAkCC,OAAO,CAACC,MAAR,CAAgBL,QAAhB,CAAzC;AACA;;AAED,SAAOA,QAAP;AACA,CAVD;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMM,0BAA0B,GAAKN,QAAF,IAAgB;AAClD,QAAMO,gBAAgB,GAAG;AACxBC,IAAAA,IAAI,EAAE,cADkB;AAExBC,IAAAA,OAAO,EAAE,cAAI,4CAAJ;AAFe,GAAzB;;AAKA,MAAK,CAAET,QAAF,IAAc,CAAEA,QAAQ,CAACG,IAA9B,EAAqC;AACpC,UAAMI,gBAAN;AACA;;AAED,SAAOP,QAAQ,CAACG,IAAT,GAAgBO,KAAhB,CAAuB,MAAM;AACnC,UAAMH,gBAAN;AACA,GAFM,CAAP;AAGA,CAbD;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMI,8BAA8B,GAAG,CAC7CX,QAD6C,EAE7CC,mBAAmB,GAAG,IAFuB,KAGzC;AACJ,SAAOG,OAAO,CAACQ,OAAR,CACNb,aAAa,CAAEC,QAAF,EAAYC,mBAAZ,CADP,EAELS,KAFK,CAEIG,GAAF,IAAWC,kBAAkB,CAAED,GAAF,EAAOZ,mBAAP,CAF/B,CAAP;AAGA,CAPM;AASP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASa,kBAAT,CAA6Bd,QAA7B,EAAuCC,mBAAmB,GAAG,IAA7D,EAAoE;AAC1E,MAAK,CAAEA,mBAAP,EAA6B;AAC5B,UAAMD,QAAN;AACA;;AAED,SAAOM,0BAA0B,CAAEN,QAAF,CAA1B,CAAuCe,IAAvC,CAA+CC,KAAF,IAAa;AAChE,UAAMC,YAAY,GAAG;AACpBT,MAAAA,IAAI,EAAE,eADc;AAEpBC,MAAAA,OAAO,EAAE,cAAI,4BAAJ;AAFW,KAArB;AAKA,UAAMO,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\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} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}
{"version":3,"sources":["@wordpress/api-fetch/src/utils/response.js"],"names":["parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"mappings":";;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,UAAEC,QAAF,EAA4C;AAAA,MAAhCC,mBAAgC,uEAAV,IAAU;;AACjE,MAAKA,mBAAL,EAA2B;AAC1B,QAAKD,QAAQ,CAACE,MAAT,KAAoB,GAAzB,EAA+B;AA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KA,UAAMO,KAAK,IAAIC,YAAf;AACA,GAPM,CAAP;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any> | null | Response} Parsed response.\n */\nconst parseResponse = ( response, shouldParseResponse = true ) => {\n\tif ( shouldParseResponse ) {\n\t\tif ( response.status === 204 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn response.json ? response.json() : Promise.reject( response );\n\t}\n\n\treturn response;\n};\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} response\n * @return {Promise<any>} Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response ) => {\n\tconst invalidJsonError = {\n\t\tcode: 'invalid_json',\n\t\tmessage: __( 'The response is not a valid JSON response.' ),\n\t};\n\n\tif ( ! response || ! response.json ) {\n\t\tthrow invalidJsonError;\n\t}\n\n\treturn response.json().catch( () => {\n\t\tthrow invalidJsonError;\n\t} );\n};\n\n/**\n * Parses the apiFetch response properly and normalize response errors.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n *\n * @return {Promise<any>} Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse,\n\tshouldParseResponse = true\n) => {\n\treturn Promise.resolve(\n\t\tparseResponse( response, shouldParseResponse )\n\t).catch( ( res ) => parseAndThrowError( res, shouldParseResponse ) );\n};\n\n/**\n * Parses a response, throwing an error if parsing the response fails.\n *\n * @param {Response} response\n * @param {boolean} shouldParseResponse\n * @return {Promise<any>} Parsed response.\n */\nexport function parseAndThrowError( response, shouldParseResponse = true ) {\n\tif ( ! shouldParseResponse ) {\n\t\tthrow response;\n\t}\n\n\treturn parseJsonAndNormalizeError( response ).then( ( error ) => {\n\t\tconst unknownError = {\n\t\t\tcode: 'unknown_error',\n\t\t\tmessage: __( 'An unknown error occurred.' ),\n\t\t};\n\n\t\tthrow error || unknownError;\n\t} );\n}\n"]}
{
"name": "@wordpress/api-fetch",
"version": "5.2.5",
"version": "5.2.6",
"description": "Utility to make WordPress REST API requests.",

@@ -30,5 +30,5 @@ "author": "The WordPress Contributors",

"dependencies": {
"@babel/runtime": "^7.13.10",
"@wordpress/i18n": "^4.2.3",
"@wordpress/url": "^3.3.0"
"@babel/runtime": "^7.16.0",
"@wordpress/i18n": "^4.2.4",
"@wordpress/url": "^3.3.1"
},

@@ -38,3 +38,3 @@ "publishConfig": {

},
"gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
"gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
}