@wordpress/api-fetch 7.32.0 → 7.32.1-next.b8c8708f3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/build/index.js +112 -145
  2. package/build/index.js.map +7 -1
  3. package/build/middlewares/fetch-all-middleware.js +48 -81
  4. package/build/middlewares/fetch-all-middleware.js.map +7 -1
  5. package/build/middlewares/http-v1.js +29 -38
  6. package/build/middlewares/http-v1.js.map +7 -1
  7. package/build/middlewares/media-upload.js +43 -49
  8. package/build/middlewares/media-upload.js.map +7 -1
  9. package/build/middlewares/namespace-endpoint.js +27 -14
  10. package/build/middlewares/namespace-endpoint.js.map +7 -1
  11. package/build/middlewares/nonce.js +26 -23
  12. package/build/middlewares/nonce.js.map +7 -1
  13. package/build/middlewares/preloading.js +63 -60
  14. package/build/middlewares/preloading.js.map +7 -1
  15. package/build/middlewares/root-url.js +42 -27
  16. package/build/middlewares/root-url.js.map +7 -1
  17. package/build/middlewares/theme-preview.js +49 -38
  18. package/build/middlewares/theme-preview.js.map +7 -1
  19. package/build/middlewares/user-locale.js +28 -23
  20. package/build/middlewares/user-locale.js.map +7 -1
  21. package/build/types.js +16 -5
  22. package/build/types.js.map +7 -1
  23. package/build/utils/response.js +31 -39
  24. package/build/utils/response.js.map +7 -1
  25. package/build-module/index.js +76 -121
  26. package/build-module/index.js.map +7 -1
  27. package/build-module/middlewares/fetch-all-middleware.js +16 -71
  28. package/build-module/middlewares/fetch-all-middleware.js.map +7 -1
  29. package/build-module/middlewares/http-v1.js +11 -34
  30. package/build-module/middlewares/http-v1.js.map +7 -1
  31. package/build-module/middlewares/media-upload.js +27 -43
  32. package/build-module/middlewares/media-upload.js.map +7 -1
  33. package/build-module/middlewares/namespace-endpoint.js +9 -10
  34. package/build-module/middlewares/namespace-endpoint.js.map +7 -1
  35. package/build-module/middlewares/nonce.js +8 -19
  36. package/build-module/middlewares/nonce.js.map +7 -1
  37. package/build-module/middlewares/preloading.js +43 -54
  38. package/build-module/middlewares/preloading.js.map +7 -1
  39. package/build-module/middlewares/root-url.js +14 -23
  40. package/build-module/middlewares/root-url.js.map +7 -1
  41. package/build-module/middlewares/theme-preview.js +29 -31
  42. package/build-module/middlewares/theme-preview.js.map +7 -1
  43. package/build-module/middlewares/user-locale.js +10 -19
  44. package/build-module/middlewares/user-locale.js.map +7 -1
  45. package/build-module/types.js +1 -2
  46. package/build-module/types.js.map +7 -1
  47. package/build-module/utils/response.js +10 -36
  48. package/build-module/utils/response.js.map +7 -1
  49. package/package.json +13 -5
@@ -1,42 +1,12 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { addQueryArgs } from '@wordpress/url';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import apiFetch from '..';
10
- /**
11
- * Apply query arguments to both URL and Path, whichever is present.
12
- *
13
- * @param {APIFetchOptions} props The request options
14
- * @param {Record< string, string | number >} queryArgs
15
- * @return The request with the modified query args
16
- */
17
- const modifyQuery = ({
18
- path,
19
- url,
20
- ...options
21
- }, queryArgs) => ({
1
+ import { addQueryArgs } from "@wordpress/url";
2
+ import apiFetch from "..";
3
+ const modifyQuery = ({ path, url, ...options }, queryArgs) => ({
22
4
  ...options,
23
5
  url: url && addQueryArgs(url, queryArgs),
24
6
  path: path && addQueryArgs(path, queryArgs)
25
7
  });
26
-
27
- /**
28
- * Duplicates parsing functionality from apiFetch.
29
- *
30
- * @param response
31
- * @return Parsed response json.
32
- */
33
- const parseResponse = response => response.json ? response.json() : Promise.reject(response);
34
-
35
- /**
36
- * @param linkHeader
37
- * @return The parsed link header.
38
- */
39
- const parseLinkHeader = linkHeader => {
8
+ const parseResponse = (response) => response.json ? response.json() : Promise.reject(response);
9
+ const parseLinkHeader = (linkHeader) => {
40
10
  if (!linkHeader) {
41
11
  return {};
42
12
  }
@@ -45,46 +15,22 @@ const parseLinkHeader = linkHeader => {
45
15
  next: match[1]
46
16
  } : {};
47
17
  };
48
-
49
- /**
50
- * @param response
51
- * @return The next page URL.
52
- */
53
- const getNextPageUrl = response => {
54
- const {
55
- next
56
- } = parseLinkHeader(response.headers.get('link'));
18
+ const getNextPageUrl = (response) => {
19
+ const { next } = parseLinkHeader(response.headers.get("link"));
57
20
  return next;
58
21
  };
59
-
60
- /**
61
- * @param options
62
- * @return True if the request contains an unbounded query.
63
- */
64
- const requestContainsUnboundedQuery = options => {
65
- const pathIsUnbounded = !!options.path && options.path.indexOf('per_page=-1') !== -1;
66
- const urlIsUnbounded = !!options.url && options.url.indexOf('per_page=-1') !== -1;
22
+ const requestContainsUnboundedQuery = (options) => {
23
+ const pathIsUnbounded = !!options.path && options.path.indexOf("per_page=-1") !== -1;
24
+ const urlIsUnbounded = !!options.url && options.url.indexOf("per_page=-1") !== -1;
67
25
  return pathIsUnbounded || urlIsUnbounded;
68
26
  };
69
-
70
- /**
71
- * The REST API enforces an upper limit on the per_page option. To handle large
72
- * collections, apiFetch consumers can pass `per_page=-1`; this middleware will
73
- * then recursively assemble a full response array from all available pages.
74
- * @param options
75
- * @param next
76
- */
77
27
  const fetchAllMiddleware = async (options, next) => {
78
28
  if (options.parse === false) {
79
- // If a consumer has opted out of parsing, do not apply middleware.
80
29
  return next(options);
81
30
  }
82
31
  if (!requestContainsUnboundedQuery(options)) {
83
- // If neither url nor path is requesting all items, do not apply middleware.
84
32
  return next(options);
85
33
  }
86
-
87
- // Retrieve requested page of results.
88
34
  const response = await apiFetch({
89
35
  ...modifyQuery(options, {
90
36
  per_page: 100
@@ -94,22 +40,18 @@ const fetchAllMiddleware = async (options, next) => {
94
40
  });
95
41
  const results = await parseResponse(response);
96
42
  if (!Array.isArray(results)) {
97
- // We have no reliable way of merging non-array results.
98
43
  return results;
99
44
  }
100
45
  let nextPage = getNextPageUrl(response);
101
46
  if (!nextPage) {
102
- // There are no further pages to request.
103
47
  return results;
104
48
  }
105
-
106
- // Iteratively fetch all remaining pages until no "next" header is found.
107
49
  let mergedResults = [].concat(results);
108
50
  while (nextPage) {
109
51
  const nextResponse = await apiFetch({
110
52
  ...options,
111
53
  // Ensure the URL for the next page is used instead of any provided path.
112
- path: undefined,
54
+ path: void 0,
113
55
  url: nextPage,
114
56
  // Ensure we still get headers so we can identify the next page.
115
57
  parse: false
@@ -120,5 +62,8 @@ const fetchAllMiddleware = async (options, next) => {
120
62
  }
121
63
  return mergedResults;
122
64
  };
123
- export default fetchAllMiddleware;
124
- //# sourceMappingURL=fetch-all-middleware.js.map
65
+ var fetch_all_middleware_default = fetchAllMiddleware;
66
+ export {
67
+ fetch_all_middleware_default as default
68
+ };
69
+ //# sourceMappingURL=fetch-all-middleware.js.map
@@ -1 +1,7 @@
1
- {"version":3,"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"],"sources":["@wordpress/api-fetch/src/middlewares/fetch-all-middleware.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\nimport type { APIFetchMiddleware, APIFetchOptions } from '../types';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {APIFetchOptions} props The request options\n * @param {Record< string, string | number >} queryArgs\n * @return The request with the modified query args\n */\nconst modifyQuery = (\n\t{ path, url, ...options }: APIFetchOptions,\n\tqueryArgs: Record< string, string | number >\n): APIFetchOptions => ( {\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\n * @return Parsed response json.\n */\nconst parseResponse = ( response: Response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param linkHeader\n * @return The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader: string | null ) => {\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\n * @return The next page URL.\n */\nconst getNextPageUrl = ( response: Response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param options\n * @return True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options: APIFetchOptions ) => {\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 * @param options\n * @param next\n */\nconst fetchAllMiddleware: APIFetchMiddleware = 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 = ( [] as Array< 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"],"mappings":"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","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/middlewares/fetch-all-middleware.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport apiFetch from '..';\nimport type { APIFetchMiddleware, APIFetchOptions } from '../types';\n\n/**\n * Apply query arguments to both URL and Path, whichever is present.\n *\n * @param {APIFetchOptions} props The request options\n * @param {Record< string, string | number >} queryArgs\n * @return The request with the modified query args\n */\nconst modifyQuery = (\n\t{ path, url, ...options }: APIFetchOptions,\n\tqueryArgs: Record< string, string | number >\n): APIFetchOptions => ( {\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\n * @return Parsed response json.\n */\nconst parseResponse = ( response: Response ) =>\n\tresponse.json ? response.json() : Promise.reject( response );\n\n/**\n * @param linkHeader\n * @return The parsed link header.\n */\nconst parseLinkHeader = ( linkHeader: string | null ) => {\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\n * @return The next page URL.\n */\nconst getNextPageUrl = ( response: Response ) => {\n\tconst { next } = parseLinkHeader( response.headers.get( 'link' ) );\n\treturn next;\n};\n\n/**\n * @param options\n * @return True if the request contains an unbounded query.\n */\nconst requestContainsUnboundedQuery = ( options: APIFetchOptions ) => {\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 * @param options\n * @param next\n */\nconst fetchAllMiddleware: APIFetchMiddleware = 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 = ( [] as Array< 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"],
5
+ "mappings": "AAGA,SAAS,oBAAoB;AAK7B,OAAO,cAAc;AAUrB,MAAM,cAAc,CACnB,EAAE,MAAM,KAAK,GAAG,QAAQ,GACxB,eACuB;AAAA,EACvB,GAAG;AAAA,EACH,KAAK,OAAO,aAAc,KAAK,SAAU;AAAA,EACzC,MAAM,QAAQ,aAAc,MAAM,SAAU;AAC7C;AAQA,MAAM,gBAAgB,CAAE,aACvB,SAAS,OAAO,SAAS,KAAK,IAAI,QAAQ,OAAQ,QAAS;AAM5D,MAAM,kBAAkB,CAAE,eAA+B;AACxD,MAAK,CAAE,YAAa;AACnB,WAAO,CAAC;AAAA,EACT;AACA,QAAM,QAAQ,WAAW,MAAO,uBAAwB;AACxD,SAAO,QACJ;AAAA,IACA,MAAM,MAAO,CAAE;AAAA,EACf,IACA,CAAC;AACL;AAMA,MAAM,iBAAiB,CAAE,aAAwB;AAChD,QAAM,EAAE,KAAK,IAAI,gBAAiB,SAAS,QAAQ,IAAK,MAAO,CAAE;AACjE,SAAO;AACR;AAMA,MAAM,gCAAgC,CAAE,YAA8B;AACrE,QAAM,kBACL,CAAC,CAAE,QAAQ,QAAQ,QAAQ,KAAK,QAAS,aAAc,MAAM;AAC9D,QAAM,iBACL,CAAC,CAAE,QAAQ,OAAO,QAAQ,IAAI,QAAS,aAAc,MAAM;AAC5D,SAAO,mBAAmB;AAC3B;AASA,MAAM,qBAAyC,OAAQ,SAAS,SAAU;AACzE,MAAK,QAAQ,UAAU,OAAQ;AAE9B,WAAO,KAAM,OAAQ;AAAA,EACtB;AACA,MAAK,CAAE,8BAA+B,OAAQ,GAAI;AAEjD,WAAO,KAAM,OAAQ;AAAA,EACtB;AAGA,QAAM,WAAW,MAAM,SAAU;AAAA,IAChC,GAAG,YAAa,SAAS;AAAA,MACxB,UAAU;AAAA,IACX,CAAE;AAAA;AAAA,IAEF,OAAO;AAAA,EACR,CAAE;AAEF,QAAM,UAAU,MAAM,cAAe,QAAS;AAE9C,MAAK,CAAE,MAAM,QAAS,OAAQ,GAAI;AAEjC,WAAO;AAAA,EACR;AAEA,MAAI,WAAW,eAAgB,QAAS;AAExC,MAAK,CAAE,UAAW;AAEjB,WAAO;AAAA,EACR;AAGA,MAAI,gBAAkB,CAAC,EAAoB,OAAQ,OAAQ;AAC3D,SAAQ,UAAW;AAClB,UAAM,eAAe,MAAM,SAAU;AAAA,MACpC,GAAG;AAAA;AAAA,MAEH,MAAM;AAAA,MACN,KAAK;AAAA;AAAA,MAEL,OAAO;AAAA,IACR,CAAE;AACF,UAAM,cAAc,MAAM,cAAe,YAAa;AACtD,oBAAgB,cAAc,OAAQ,WAAY;AAClD,eAAW,eAAgB,YAAa;AAAA,EACzC;AACA,SAAO;AACR;AAEA,IAAO,+BAAQ;",
6
+ "names": []
7
+ }
@@ -1,45 +1,22 @@
1
- /**
2
- * Internal dependencies
3
- */
4
-
5
- /**
6
- * Set of HTTP methods which are eligible to be overridden.
7
- */
8
- const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
9
-
10
- /**
11
- * Default request method.
12
- *
13
- * "A request has an associated method (a method). Unless stated otherwise it
14
- * is `GET`."
15
- *
16
- * @see https://fetch.spec.whatwg.org/#requests
17
- */
18
- const DEFAULT_METHOD = 'GET';
19
-
20
- /**
21
- * API Fetch middleware which overrides the request method for HTTP v1
22
- * compatibility leveraging the REST API X-HTTP-Method-Override header.
23
- *
24
- * @param options
25
- * @param next
26
- */
1
+ const OVERRIDE_METHODS = /* @__PURE__ */ new Set(["PATCH", "PUT", "DELETE"]);
2
+ const DEFAULT_METHOD = "GET";
27
3
  const httpV1Middleware = (options, next) => {
28
- const {
29
- method = DEFAULT_METHOD
30
- } = options;
4
+ const { method = DEFAULT_METHOD } = options;
31
5
  if (OVERRIDE_METHODS.has(method.toUpperCase())) {
32
6
  options = {
33
7
  ...options,
34
8
  headers: {
35
9
  ...options.headers,
36
- 'X-HTTP-Method-Override': method,
37
- 'Content-Type': 'application/json'
10
+ "X-HTTP-Method-Override": method,
11
+ "Content-Type": "application/json"
38
12
  },
39
- method: 'POST'
13
+ method: "POST"
40
14
  };
41
15
  }
42
16
  return next(options);
43
17
  };
44
- export default httpV1Middleware;
45
- //# sourceMappingURL=http-v1.js.map
18
+ var http_v1_default = httpV1Middleware;
19
+ export {
20
+ http_v1_default as default
21
+ };
22
+ //# sourceMappingURL=http-v1.js.map
@@ -1 +1,7 @@
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":[]}
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": "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,46 +1,25 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { parseAndThrowError, parseResponseAndNormalizeError } from '../utils/response';
10
- /**
11
- * @param options
12
- * @return True if the request is for media upload.
13
- */
1
+ import { __ } from "@wordpress/i18n";
2
+ import {
3
+ parseAndThrowError,
4
+ parseResponseAndNormalizeError
5
+ } from "../utils/response";
14
6
  function isMediaUploadRequest(options) {
15
- const isCreateMethod = !!options.method && options.method === 'POST';
16
- const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
7
+ const isCreateMethod = !!options.method && options.method === "POST";
8
+ const isMediaEndpoint = !!options.path && options.path.indexOf("/wp/v2/media") !== -1 || !!options.url && options.url.indexOf("/wp/v2/media") !== -1;
17
9
  return isMediaEndpoint && isCreateMethod;
18
10
  }
19
-
20
- /**
21
- * Middleware handling media upload failures and retries.
22
- * @param options
23
- * @param next
24
- */
25
11
  const mediaUploadMiddleware = (options, next) => {
26
12
  if (!isMediaUploadRequest(options)) {
27
13
  return next(options);
28
14
  }
29
15
  let retries = 0;
30
16
  const maxRetries = 5;
31
-
32
- /**
33
- * @param attachmentId
34
- * @return Processed post response.
35
- */
36
- const postProcess = attachmentId => {
17
+ const postProcess = (attachmentId) => {
37
18
  retries++;
38
19
  return next({
39
20
  path: `/wp/v2/media/${attachmentId}/post-process`,
40
- method: 'POST',
41
- data: {
42
- action: 'create-image-subsizes'
43
- },
21
+ method: "POST",
22
+ data: { action: "create-image-subsizes" },
44
23
  parse: false
45
24
  }).catch(() => {
46
25
  if (retries < maxRetries) {
@@ -48,33 +27,38 @@ const mediaUploadMiddleware = (options, next) => {
48
27
  }
49
28
  next({
50
29
  path: `/wp/v2/media/${attachmentId}?force=true`,
51
- method: 'DELETE'
30
+ method: "DELETE"
52
31
  });
53
32
  return Promise.reject();
54
33
  });
55
34
  };
56
- return next({
57
- ...options,
58
- parse: false
59
- }).catch(response => {
60
- // `response` could actually be an error thrown by `defaultFetchHandler`.
35
+ return next({ ...options, parse: false }).catch((response) => {
61
36
  if (!(response instanceof globalThis.Response)) {
62
37
  return Promise.reject(response);
63
38
  }
64
- const attachmentId = response.headers.get('x-wp-upload-attachment-id');
39
+ const attachmentId = response.headers.get(
40
+ "x-wp-upload-attachment-id"
41
+ );
65
42
  if (response.status >= 500 && response.status < 600 && attachmentId) {
66
43
  return postProcess(attachmentId).catch(() => {
67
44
  if (options.parse !== false) {
68
45
  return Promise.reject({
69
- code: 'post_process',
70
- message: __('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
46
+ code: "post_process",
47
+ message: __(
48
+ "Media upload failed. If this is a photo or a large image, please scale it down and try again."
49
+ )
71
50
  });
72
51
  }
73
52
  return Promise.reject(response);
74
53
  });
75
54
  }
76
55
  return parseAndThrowError(response, options.parse);
77
- }).then(response => parseResponseAndNormalizeError(response, options.parse));
56
+ }).then(
57
+ (response) => parseResponseAndNormalizeError(response, options.parse)
58
+ );
78
59
  };
79
- export default mediaUploadMiddleware;
80
- //# sourceMappingURL=media-upload.js.map
60
+ var media_upload_default = mediaUploadMiddleware;
61
+ export {
62
+ media_upload_default as default
63
+ };
64
+ //# sourceMappingURL=media-upload.js.map
@@ -1 +1,7 @@
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
+ {
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": "AAGA,SAAS,UAAU;AAKnB;AAAA,EACC;AAAA,EACA;AAAA,OACM;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,SAAS;AAAA,cACR;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAEA,eAAO,QAAQ,OAAQ,QAAS;AAAA,MACjC,CAAE;AAAA,IACH;AACA,WAAO,mBAAoB,UAAU,QAAQ,KAAM;AAAA,EACpD,CAAE,EACD;AAAA,IAAM,CAAE,aACR,+BAAgC,UAAU,QAAQ,KAAM;AAAA,EACzD;AACF;AAEA,IAAO,uBAAQ;",
6
+ "names": []
7
+ }
@@ -1,15 +1,11 @@
1
- /**
2
- * Internal dependencies
3
- */
4
-
5
1
  const namespaceAndEndpointMiddleware = (options, next) => {
6
2
  let path = options.path;
7
3
  let namespaceTrimmed, endpointTrimmed;
8
- if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
9
- namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
10
- endpointTrimmed = options.endpoint.replace(/^\//, '');
4
+ if (typeof options.namespace === "string" && typeof options.endpoint === "string") {
5
+ namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, "");
6
+ endpointTrimmed = options.endpoint.replace(/^\//, "");
11
7
  if (endpointTrimmed) {
12
- path = namespaceTrimmed + '/' + endpointTrimmed;
8
+ path = namespaceTrimmed + "/" + endpointTrimmed;
13
9
  } else {
14
10
  path = namespaceTrimmed;
15
11
  }
@@ -21,5 +17,8 @@ const namespaceAndEndpointMiddleware = (options, next) => {
21
17
  path
22
18
  });
23
19
  };
24
- export default namespaceAndEndpointMiddleware;
25
- //# sourceMappingURL=namespace-endpoint.js.map
20
+ var namespace_endpoint_default = namespaceAndEndpointMiddleware;
21
+ export {
22
+ namespace_endpoint_default as default
23
+ };
24
+ //# sourceMappingURL=namespace-endpoint.js.map
@@ -1 +1,7 @@
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
+ {
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": "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,22 +1,8 @@
1
- /**
2
- * Internal dependencies
3
- */
4
-
5
- /**
6
- * @param nonce
7
- *
8
- * @return A middleware to enhance a request with a nonce.
9
- */
10
1
  function createNonceMiddleware(nonce) {
11
2
  const middleware = (options, next) => {
12
- const {
13
- headers = {}
14
- } = options;
15
-
16
- // If an 'X-WP-Nonce' header (or any case-insensitive variation
17
- // thereof) was specified, no need to add a nonce header.
3
+ const { headers = {} } = options;
18
4
  for (const headerName in headers) {
19
- if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
5
+ if (headerName.toLowerCase() === "x-wp-nonce" && headers[headerName] === middleware.nonce) {
20
6
  return next(options);
21
7
  }
22
8
  }
@@ -24,12 +10,15 @@ function createNonceMiddleware(nonce) {
24
10
  ...options,
25
11
  headers: {
26
12
  ...headers,
27
- 'X-WP-Nonce': middleware.nonce
13
+ "X-WP-Nonce": middleware.nonce
28
14
  }
29
15
  });
30
16
  };
31
17
  middleware.nonce = nonce;
32
18
  return middleware;
33
19
  }
34
- export default createNonceMiddleware;
35
- //# sourceMappingURL=nonce.js.map
20
+ var nonce_default = createNonceMiddleware;
21
+ export {
22
+ nonce_default as default
23
+ };
24
+ //# sourceMappingURL=nonce.js.map
@@ -1 +1,7 @@
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":[]}
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": "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,84 +1,73 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
-
10
- /**
11
- * @param preloadedData
12
- * @return Preloading middleware.
13
- */
1
+ import { addQueryArgs, getQueryArgs, normalizePath } from "@wordpress/url";
14
2
  function createPreloadingMiddleware(preloadedData) {
15
- const cache = Object.fromEntries(Object.entries(preloadedData).map(([path, data]) => [normalizePath(path), data]));
3
+ const cache = Object.fromEntries(
4
+ Object.entries(preloadedData).map(([path, data]) => [
5
+ normalizePath(path),
6
+ data
7
+ ])
8
+ );
16
9
  return (options, next) => {
17
- const {
18
- parse = true
19
- } = options;
10
+ const { parse = true } = options;
20
11
  let rawPath = options.path;
21
12
  if (!rawPath && options.url) {
22
- const {
23
- rest_route: pathFromQuery,
24
- ...queryArgs
25
- } = getQueryArgs(options.url);
26
- if (typeof pathFromQuery === 'string') {
13
+ const { rest_route: pathFromQuery, ...queryArgs } = getQueryArgs(
14
+ options.url
15
+ );
16
+ if (typeof pathFromQuery === "string") {
27
17
  rawPath = addQueryArgs(pathFromQuery, queryArgs);
28
18
  }
29
19
  }
30
- if (typeof rawPath !== 'string') {
20
+ if (typeof rawPath !== "string") {
31
21
  return next(options);
32
22
  }
33
- const method = options.method || 'GET';
23
+ const method = options.method || "GET";
34
24
  const path = normalizePath(rawPath);
35
- if ('GET' === method && cache[path]) {
25
+ if ("GET" === method && cache[path]) {
36
26
  const cacheData = cache[path];
37
-
38
- // Unsetting the cache key ensures that the data is only used a single time.
39
27
  delete cache[path];
40
28
  return prepareResponse(cacheData, !!parse);
41
- } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
29
+ } else if ("OPTIONS" === method && cache[method] && cache[method][path]) {
42
30
  const cacheData = cache[method][path];
43
-
44
- // Unsetting the cache key ensures that the data is only used a single time.
45
31
  delete cache[method][path];
46
32
  return prepareResponse(cacheData, !!parse);
47
33
  }
48
34
  return next(options);
49
35
  };
50
36
  }
51
-
52
- /**
53
- * This is a helper function that sends a success response.
54
- *
55
- * @param responseData
56
- * @param parse
57
- * @return Promise with the response.
58
- */
59
37
  function prepareResponse(responseData, parse) {
60
38
  if (parse) {
61
39
  return Promise.resolve(responseData.body);
62
40
  }
63
41
  try {
64
- return Promise.resolve(new window.Response(JSON.stringify(responseData.body), {
65
- status: 200,
66
- statusText: 'OK',
67
- headers: responseData.headers
68
- }));
42
+ return Promise.resolve(
43
+ new window.Response(JSON.stringify(responseData.body), {
44
+ status: 200,
45
+ statusText: "OK",
46
+ headers: responseData.headers
47
+ })
48
+ );
69
49
  } catch {
70
- // See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926.
71
- Object.entries(responseData.headers).forEach(([key, value]) => {
72
- if (key.toLowerCase() === 'link') {
73
- responseData.headers[key] = value.replace(/<([^>]+)>/, (_, url) => `<${encodeURI(url)}>`);
50
+ Object.entries(
51
+ responseData.headers
52
+ ).forEach(([key, value]) => {
53
+ if (key.toLowerCase() === "link") {
54
+ responseData.headers[key] = value.replace(
55
+ /<([^>]+)>/,
56
+ (_, url) => `<${encodeURI(url)}>`
57
+ );
74
58
  }
75
59
  });
76
- return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
77
- status: 200,
78
- statusText: 'OK',
79
- headers: responseData.headers
80
- }));
60
+ return Promise.resolve(
61
+ parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
62
+ status: 200,
63
+ statusText: "OK",
64
+ headers: responseData.headers
65
+ })
66
+ );
81
67
  }
82
68
  }
83
- export default createPreloadingMiddleware;
84
- //# sourceMappingURL=preloading.js.map
69
+ var preloading_default = createPreloadingMiddleware;
70
+ export {
71
+ preloading_default as default
72
+ };
73
+ //# sourceMappingURL=preloading.js.map