@wordpress/api-fetch 7.28.1-next.0f6f9d12c.0 → 7.29.1-next.e256d081a.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 (95) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/index.js +25 -34
  3. package/build/index.js.map +1 -1
  4. package/build/middlewares/fetch-all-middleware.js +14 -14
  5. package/build/middlewares/fetch-all-middleware.js.map +1 -1
  6. package/build/middlewares/http-v1.js +6 -5
  7. package/build/middlewares/http-v1.js.map +1 -1
  8. package/build/middlewares/media-upload.js +6 -6
  9. package/build/middlewares/media-upload.js.map +1 -1
  10. package/build/middlewares/namespace-endpoint.js +2 -1
  11. package/build/middlewares/namespace-endpoint.js.map +1 -1
  12. package/build/middlewares/nonce.js +7 -5
  13. package/build/middlewares/nonce.js.map +1 -1
  14. package/build/middlewares/preloading.js +10 -7
  15. package/build/middlewares/preloading.js.map +1 -1
  16. package/build/middlewares/root-url.js +2 -2
  17. package/build/middlewares/root-url.js.map +1 -1
  18. package/build/middlewares/theme-preview.js +6 -2
  19. package/build/middlewares/theme-preview.js.map +1 -1
  20. package/build/middlewares/user-locale.js +2 -1
  21. package/build/middlewares/user-locale.js.map +1 -1
  22. package/build/types.js.map +1 -1
  23. package/build/utils/response.js +11 -11
  24. package/build/utils/response.js.map +1 -1
  25. package/build-module/index.js +13 -35
  26. package/build-module/index.js.map +1 -1
  27. package/build-module/middlewares/fetch-all-middleware.js +14 -15
  28. package/build-module/middlewares/fetch-all-middleware.js.map +1 -1
  29. package/build-module/middlewares/http-v1.js +6 -5
  30. package/build-module/middlewares/http-v1.js.map +1 -1
  31. package/build-module/middlewares/media-upload.js +6 -7
  32. package/build-module/middlewares/media-upload.js.map +1 -1
  33. package/build-module/middlewares/namespace-endpoint.js +2 -1
  34. package/build-module/middlewares/namespace-endpoint.js.map +1 -1
  35. package/build-module/middlewares/nonce.js +7 -5
  36. package/build-module/middlewares/nonce.js.map +1 -1
  37. package/build-module/middlewares/preloading.js +10 -7
  38. package/build-module/middlewares/preloading.js.map +1 -1
  39. package/build-module/middlewares/root-url.js +3 -2
  40. package/build-module/middlewares/root-url.js.map +1 -1
  41. package/build-module/middlewares/theme-preview.js +5 -2
  42. package/build-module/middlewares/theme-preview.js.map +1 -1
  43. package/build-module/middlewares/user-locale.js +2 -1
  44. package/build-module/middlewares/user-locale.js.map +1 -1
  45. package/build-module/types.js.map +1 -1
  46. package/build-module/utils/response.js +11 -11
  47. package/build-module/utils/response.js.map +1 -1
  48. package/build-types/index.d.ts +25 -32
  49. package/build-types/index.d.ts.map +1 -1
  50. package/build-types/middlewares/fetch-all-middleware.d.ts +5 -4
  51. package/build-types/middlewares/fetch-all-middleware.d.ts.map +1 -1
  52. package/build-types/middlewares/http-v1.d.ts +8 -3
  53. package/build-types/middlewares/http-v1.d.ts.map +1 -1
  54. package/build-types/middlewares/media-upload.d.ts +5 -4
  55. package/build-types/middlewares/media-upload.d.ts.map +1 -1
  56. package/build-types/middlewares/namespace-endpoint.d.ts +4 -3
  57. package/build-types/middlewares/namespace-endpoint.d.ts.map +1 -1
  58. package/build-types/middlewares/nonce.d.ts +9 -4
  59. package/build-types/middlewares/nonce.d.ts.map +1 -1
  60. package/build-types/middlewares/preloading.d.ts +8 -4
  61. package/build-types/middlewares/preloading.d.ts.map +1 -1
  62. package/build-types/middlewares/root-url.d.ts +8 -4
  63. package/build-types/middlewares/root-url.d.ts.map +1 -1
  64. package/build-types/middlewares/theme-preview.d.ts +8 -4
  65. package/build-types/middlewares/theme-preview.d.ts.map +1 -1
  66. package/build-types/middlewares/user-locale.d.ts +4 -3
  67. package/build-types/middlewares/user-locale.d.ts.map +1 -1
  68. package/build-types/types.d.ts +4 -3
  69. package/build-types/types.d.ts.map +1 -1
  70. package/build-types/utils/response.d.ts +13 -5
  71. package/build-types/utils/response.d.ts.map +1 -1
  72. package/package.json +4 -4
  73. package/src/{index.js → index.ts} +49 -46
  74. package/src/middlewares/{fetch-all-middleware.js → fetch-all-middleware.ts} +24 -20
  75. package/src/middlewares/{http-v1.js → http-v1.ts} +8 -6
  76. package/src/middlewares/{media-upload.js → media-upload.ts} +10 -9
  77. package/src/middlewares/{namespace-endpoint.js → namespace-endpoint.ts} +7 -2
  78. package/src/middlewares/{nonce.js → nonce.ts} +15 -7
  79. package/src/middlewares/{preloading.js → preloading.ts} +21 -11
  80. package/src/middlewares/root-url.ts +47 -0
  81. package/src/middlewares/test/{fetch-all-middleware.js → fetch-all-middleware.ts} +1 -1
  82. package/src/middlewares/test/{http-v1.js → http-v1.ts} +7 -4
  83. package/src/middlewares/test/{media-upload.js → media-upload.ts} +2 -1
  84. package/src/middlewares/test/{namespace-endpoint.js → namespace-endpoint.ts} +2 -1
  85. package/src/middlewares/test/{nonce.js → nonce.ts} +5 -4
  86. package/src/middlewares/test/{preloading.js → preloading.ts} +31 -11
  87. package/src/middlewares/test/{root-url.js → root-url.ts} +2 -1
  88. package/src/middlewares/test/{user-locale.js → user-locale.ts} +9 -8
  89. package/src/middlewares/theme-preview.ts +60 -0
  90. package/src/middlewares/{user-locale.js → user-locale.ts} +4 -2
  91. package/src/types.ts +10 -5
  92. package/src/utils/{response.js → response.ts} +18 -15
  93. package/tsconfig.tsbuildinfo +1 -1
  94. package/src/middlewares/root-url.js +0 -44
  95. package/src/middlewares/theme-preview.js +0 -42
@@ -4,8 +4,12 @@
4
4
  import { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';
5
5
 
6
6
  /**
7
- * @param {Record<string, any>} preloadedData
8
- * @return {import('../types').APIFetchMiddleware} Preloading middleware.
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 {Record<string, any>} responseData
53
- * @param {boolean} parse
54
- * @return {Promise<any>} Promise with the response.
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(/<([^>]+)>/, (/** @type {any} */_, /** @type {string} */url) => `<${encodeURI(url)}>`);
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.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';\n\n/**\n * @param {Record<string, any>} preloadedData\n * @return {import('../types').APIFetchMiddleware} Preloading middleware.\n */\nfunction createPreloadingMiddleware( preloadedData ) {\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\t/** @type {string | void} */\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 {Record<string, any>} responseData\n * @param {boolean} parse\n * @return {Promise<any>} Promise with the response.\n */\nfunction prepareResponse( responseData, parse ) {\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( responseData.headers ).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( /** @type {any} */ _, /** @type {string} */ url ) =>\n\t\t\t\t\t\t`<${ 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
+ {"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 {string} rootURL
8
- * @return {import('../types').APIFetchMiddleware} Root URL middleware.
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.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport namespaceAndEndpointMiddleware from './namespace-endpoint';\n\n/**\n * @param {string} rootURL\n * @return {import('../types').APIFetchMiddleware} Root URL middleware.\n */\nconst createRootURLMiddleware = ( rootURL ) => ( options, next ) => {\n\treturn namespaceAndEndpointMiddleware( options, ( optionsWithPath ) => {\n\t\tlet url = optionsWithPath.url;\n\t\tlet path = optionsWithPath.path;\n\t\tlet apiRoot;\n\n\t\tif ( typeof path === 'string' ) {\n\t\t\tapiRoot = rootURL;\n\n\t\t\tif ( -1 !== rootURL.indexOf( '?' ) ) {\n\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t}\n\n\t\t\tpath = path.replace( /^\\//, '' );\n\n\t\t\t// API root may already include query parameter prefix if site is\n\t\t\t// configured to use plain permalinks.\n\t\t\tif (\n\t\t\t\t'string' === typeof apiRoot &&\n\t\t\t\t-1 !== apiRoot.indexOf( '?' )\n\t\t\t) {\n\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t}\n\n\t\t\turl = apiRoot + path;\n\t\t}\n\n\t\treturn next( {\n\t\t\t...optionsWithPath,\n\t\t\turl,\n\t\t} );\n\t} );\n};\n\nexport default createRootURLMiddleware;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,8BAA8B,MAAM,sBAAsB;;AAEjE;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAKC,OAAO,IAAM,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACnE,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;AAED,eAAeL,uBAAuB","ignoreList":[]}
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 {Record<string, any>} themePath
14
- * @return {import('../types').APIFetchMiddleware} Preloading middleware.
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.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url';\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 {Record<string, any>} themePath\n * @return {import('../types').APIFetchMiddleware} Preloading middleware.\n */\nconst createThemePreviewMiddleware = ( themePath ) => ( options, next ) => {\n\tif ( typeof options.url === 'string' ) {\n\t\tconst wpThemePreview = getQueryArg( options.url, 'wp_theme_preview' );\n\t\tif ( wpThemePreview === undefined ) {\n\t\t\toptions.url = addQueryArgs( options.url, {\n\t\t\t\twp_theme_preview: themePath,\n\t\t\t} );\n\t\t} else if ( wpThemePreview === '' ) {\n\t\t\toptions.url = removeQueryArgs( options.url, 'wp_theme_preview' );\n\t\t}\n\t}\n\n\tif ( typeof options.path === 'string' ) {\n\t\tconst wpThemePreview = getQueryArg( options.path, 'wp_theme_preview' );\n\t\tif ( wpThemePreview === undefined ) {\n\t\t\toptions.path = addQueryArgs( options.path, {\n\t\t\t\twp_theme_preview: themePath,\n\t\t\t} );\n\t\t} else if ( wpThemePreview === '' ) {\n\t\t\toptions.path = removeQueryArgs( options.path, 'wp_theme_preview' );\n\t\t}\n\t}\n\n\treturn next( options );\n};\n\nexport default createThemePreviewMiddleware;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,WAAW,EAAEC,eAAe,QAAQ,gBAAgB;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,4BAA4B,GAAKC,SAAS,IAAM,CAAEC,OAAO,EAAEC,IAAI,KAAM;EAC1E,IAAK,OAAOD,OAAO,CAACE,GAAG,KAAK,QAAQ,EAAG;IACtC,MAAMC,cAAc,GAAGP,WAAW,CAAEI,OAAO,CAACE,GAAG,EAAE,kBAAmB,CAAC;IACrE,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,CAAEG,OAAO,CAACE,GAAG,EAAE,kBAAmB,CAAC;IACjE;EACD;EAEA,IAAK,OAAOF,OAAO,CAACM,IAAI,KAAK,QAAQ,EAAG;IACvC,MAAMH,cAAc,GAAGP,WAAW,CAAEI,OAAO,CAACM,IAAI,EAAE,kBAAmB,CAAC;IACtE,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,CAAEG,OAAO,CAACM,IAAI,EAAE,kBAAmB,CAAC;IACnE;EACD;EAEA,OAAOL,IAAI,CAAED,OAAQ,CAAC;AACvB,CAAC;AAED,eAAeF,4BAA4B","ignoreList":[]}
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
- * @type {import('../types').APIFetchMiddleware}
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.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, hasQueryArg } from '@wordpress/url';\n\n/**\n * @type {import('../types').APIFetchMiddleware}\n */\nconst userLocaleMiddleware = ( 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;AACA,MAAMC,oBAAoB,GAAGA,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACjD,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
+ {"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?: boolean;\n\tdata?: any;\n\tnamespace?: string;\n\tendpoint?: string;\n}\n\nexport type APIFetchMiddleware = (\n\toptions: APIFetchOptions,\n\tnext: ( nextOptions: APIFetchOptions ) => Promise< any >\n) => Promise< any >;\n"],"mappings":"","ignoreList":[]}
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":[]}
@@ -6,10 +6,10 @@ import { __ } from '@wordpress/i18n';
6
6
  /**
7
7
  * Parses the apiFetch response.
8
8
  *
9
- * @param {Response} response
10
- * @param {boolean} shouldParseResponse
9
+ * @param response
10
+ * @param shouldParseResponse
11
11
  *
12
- * @return {Promise<any> | null | Response} Parsed response.
12
+ * @return Parsed response.
13
13
  */
14
14
  const parseResponse = (response, shouldParseResponse = true) => {
15
15
  if (shouldParseResponse) {
@@ -25,8 +25,8 @@ const parseResponse = (response, shouldParseResponse = true) => {
25
25
  * Calls the `json` function on the Response, throwing an error if the response
26
26
  * doesn't have a json function or if parsing the json itself fails.
27
27
  *
28
- * @param {Response} response
29
- * @return {Promise<any>} Parsed response.
28
+ * @param response
29
+ * @return Parsed response.
30
30
  */
31
31
  const parseJsonAndNormalizeError = response => {
32
32
  const invalidJsonError = {
@@ -44,10 +44,10 @@ const parseJsonAndNormalizeError = response => {
44
44
  /**
45
45
  * Parses the apiFetch response properly and normalize response errors.
46
46
  *
47
- * @param {Response} response
48
- * @param {boolean} shouldParseResponse
47
+ * @param response
48
+ * @param shouldParseResponse
49
49
  *
50
- * @return {Promise<any>} Parsed response.
50
+ * @return Parsed response.
51
51
  */
52
52
  export const parseResponseAndNormalizeError = (response, shouldParseResponse = true) => {
53
53
  return Promise.resolve(parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
@@ -56,9 +56,9 @@ export const parseResponseAndNormalizeError = (response, shouldParseResponse = t
56
56
  /**
57
57
  * Parses a response, throwing an error if parsing the response fails.
58
58
  *
59
- * @param {Response} response
60
- * @param {boolean} shouldParseResponse
61
- * @return {Promise<any>} Parsed response.
59
+ * @param response
60
+ * @param shouldParseResponse
61
+ * @return Parsed response.
62
62
  */
63
63
  export function parseAndThrowError(response, shouldParseResponse = true) {
64
64
  if (!shouldParseResponse) {
@@ -1 +1 @@
1
- {"version":3,"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"sources":["@wordpress/api-fetch/src/utils/response.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAGA,CAAEC,QAAQ,EAAEC,mBAAmB,GAAG,IAAI,KAAM;EACjE,IAAKA,mBAAmB,EAAG;IAC1B,IAAKD,QAAQ,CAACE,MAAM,KAAK,GAAG,EAAG;MAC9B,OAAO,IAAI;IACZ;IAEA,OAAOF,QAAQ,CAACG,IAAI,GAAGH,QAAQ,CAACG,IAAI,CAAC,CAAC,GAAGC,OAAO,CAACC,MAAM,CAAEL,QAAS,CAAC;EACpE;EAEA,OAAOA,QAAQ;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,0BAA0B,GAAKN,QAAQ,IAAM;EAClD,MAAMO,gBAAgB,GAAG;IACxBC,IAAI,EAAE,cAAc;IACpBC,OAAO,EAAEX,EAAE,CAAE,4CAA6C;EAC3D,CAAC;EAED,IAAK,CAAEE,QAAQ,IAAI,CAAEA,QAAQ,CAACG,IAAI,EAAG;IACpC,MAAMI,gBAAgB;EACvB;EAEA,OAAOP,QAAQ,CAACG,IAAI,CAAC,CAAC,CAACO,KAAK,CAAE,MAAM;IACnC,MAAMH,gBAAgB;EACvB,CAAE,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,8BAA8B,GAAGA,CAC7CX,QAAQ,EACRC,mBAAmB,GAAG,IAAI,KACtB;EACJ,OAAOG,OAAO,CAACQ,OAAO,CACrBb,aAAa,CAAEC,QAAQ,EAAEC,mBAAoB,CAC9C,CAAC,CAACS,KAAK,CAAIG,GAAG,IAAMC,kBAAkB,CAAED,GAAG,EAAEZ,mBAAoB,CAAE,CAAC;AACrE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,kBAAkBA,CAAEd,QAAQ,EAAEC,mBAAmB,GAAG,IAAI,EAAG;EAC1E,IAAK,CAAEA,mBAAmB,EAAG;IAC5B,MAAMD,QAAQ;EACf;EAEA,OAAOM,0BAA0B,CAAEN,QAAS,CAAC,CAACe,IAAI,CAAIC,KAAK,IAAM;IAChE,MAAMC,YAAY,GAAG;MACpBT,IAAI,EAAE,eAAe;MACrBC,OAAO,EAAEX,EAAE,CAAE,4BAA6B;IAC3C,CAAC;IAED,MAAMkB,KAAK,IAAIC,YAAY;EAC5B,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["__","parseResponse","response","shouldParseResponse","status","json","Promise","reject","parseJsonAndNormalizeError","invalidJsonError","code","message","catch","parseResponseAndNormalizeError","resolve","res","parseAndThrowError","then","error","unknownError"],"sources":["@wordpress/api-fetch/src/utils/response.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Parses the apiFetch response.\n *\n * @param response\n * @param shouldParseResponse\n *\n * @return Parsed response.\n */\nconst parseResponse = ( response: 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\n * @return Parsed response.\n */\nconst parseJsonAndNormalizeError = ( response: 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\n * @param shouldParseResponse\n *\n * @return Parsed response.\n */\nexport const parseResponseAndNormalizeError = (\n\tresponse: Response,\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\n * @param shouldParseResponse\n * @return Parsed response.\n */\nexport function parseAndThrowError(\n\tresponse: Response,\n\tshouldParseResponse = true\n) {\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAGA,CAAEC,QAAkB,EAAEC,mBAAmB,GAAG,IAAI,KAAM;EAC3E,IAAKA,mBAAmB,EAAG;IAC1B,IAAKD,QAAQ,CAACE,MAAM,KAAK,GAAG,EAAG;MAC9B,OAAO,IAAI;IACZ;IAEA,OAAOF,QAAQ,CAACG,IAAI,GAAGH,QAAQ,CAACG,IAAI,CAAC,CAAC,GAAGC,OAAO,CAACC,MAAM,CAAEL,QAAS,CAAC;EACpE;EAEA,OAAOA,QAAQ;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,0BAA0B,GAAKN,QAAkB,IAAM;EAC5D,MAAMO,gBAAgB,GAAG;IACxBC,IAAI,EAAE,cAAc;IACpBC,OAAO,EAAEX,EAAE,CAAE,4CAA6C;EAC3D,CAAC;EAED,IAAK,CAAEE,QAAQ,IAAI,CAAEA,QAAQ,CAACG,IAAI,EAAG;IACpC,MAAMI,gBAAgB;EACvB;EAEA,OAAOP,QAAQ,CAACG,IAAI,CAAC,CAAC,CAACO,KAAK,CAAE,MAAM;IACnC,MAAMH,gBAAgB;EACvB,CAAE,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,8BAA8B,GAAGA,CAC7CX,QAAkB,EAClBC,mBAAmB,GAAG,IAAI,KACtB;EACJ,OAAOG,OAAO,CAACQ,OAAO,CACrBb,aAAa,CAAEC,QAAQ,EAAEC,mBAAoB,CAC9C,CAAC,CAACS,KAAK,CAAIG,GAAG,IAAMC,kBAAkB,CAAED,GAAG,EAAEZ,mBAAoB,CAAE,CAAC;AACrE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,kBAAkBA,CACjCd,QAAkB,EAClBC,mBAAmB,GAAG,IAAI,EACzB;EACD,IAAK,CAAEA,mBAAmB,EAAG;IAC5B,MAAMD,QAAQ;EACf;EAEA,OAAOM,0BAA0B,CAAEN,QAAS,CAAC,CAACe,IAAI,CAAIC,KAAK,IAAM;IAChE,MAAMC,YAAY,GAAG;MACpBT,IAAI,EAAE,eAAe;MACrBC,OAAO,EAAEX,EAAE,CAAE,4BAA6B;IAC3C,CAAC;IAED,MAAMkB,KAAK,IAAIC,YAAY;EAC5B,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -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
- * Register a middleware
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.js"],"names":[],"mappings":";iCA8Cc,OAAO,SAAS,EAAE,kBAAkB;8BACpC,OAAO,SAAS,EAAE,eAAe;2BAoCjC,CAAC,OAAO,EAAE,OAAO,SAAS,EAAE,eAAe,KAAK,OAAO,CAAC,GAAG,CAAC;AAkE1E;;;;GAIG;AACH,0BAJa,CAAC,WACH,OAAO,SAAS,EAAE,eAAe,GAChC,OAAO,CAAC,CAAC,CAAC,CAkCrB;;;;;;;;;;;AA/HD;;;;GAIG;AACH,gDAFW,OAAO,SAAS,EAAE,kBAAkB,QAI9C;AAyED;;;;;GAKG;AACH,kDAFW,YAAY,QAItB;kCA3IiC,qBAAqB;uCAEhB,0BAA0B;oCAD7B,wBAAwB;+BAE7B,oCAAoC;kCAIjC,4BAA4B;yCACrB,6BAA6B"}
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;AAiHjB,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,QA4Bf,CAAC;AAYF,eAAe,QAAQ,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -1,10 +1,11 @@
1
- export default fetchAllMiddleware;
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
- * @type {import('../types').APIFetchMiddleware}
6
+ * @param options
7
+ * @param next
8
8
  */
9
- declare const fetchAllMiddleware: import("../types").APIFetchMiddleware;
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.js"],"names":[],"mappings":";AAqEA;;;;;;GAMG;AACH,kCAFU,OAAO,UAAU,EAAE,kBAAkB,CAmD7C"}
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
- export default httpV1Middleware;
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
- * @type {import('../types').APIFetchMiddleware}
9
+ * @param options
10
+ * @param next
7
11
  */
8
- declare const httpV1Middleware: import("../types").APIFetchMiddleware;
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.js"],"names":[],"mappings":";AAmBA;;;;;GAKG;AACH,gCAFU,OAAO,UAAU,EAAE,kBAAkB,CAiB7C"}
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"}
@@ -1,8 +1,9 @@
1
- export default mediaUploadMiddleware;
1
+ import type { APIFetchMiddleware } from '../types';
2
2
  /**
3
3
  * Middleware handling media upload failures and retries.
4
- *
5
- * @type {import('../types').APIFetchMiddleware}
4
+ * @param options
5
+ * @param next
6
6
  */
7
- declare const mediaUploadMiddleware: import("../types").APIFetchMiddleware;
7
+ declare const mediaUploadMiddleware: APIFetchMiddleware;
8
+ export default mediaUploadMiddleware;
8
9
  //# sourceMappingURL=media-upload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"media-upload.d.ts","sourceRoot":"","sources":["../../src/middlewares/media-upload.js"],"names":[],"mappings":";AA0BA;;;;GAIG;AACH,qCAFU,OAAO,UAAU,EAAE,kBAAkB,CAmE7C"}
1
+ {"version":3,"file":"media-upload.d.ts","sourceRoot":"","sources":["../../src/middlewares/media-upload.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAmB,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAepE;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,EAAE,kBAiE5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -1,6 +1,7 @@
1
- export default namespaceAndEndpointMiddleware;
2
1
  /**
3
- * @type {import('../types').APIFetchMiddleware}
2
+ * Internal dependencies
4
3
  */
5
- declare const namespaceAndEndpointMiddleware: import("../types").APIFetchMiddleware;
4
+ import type { APIFetchMiddleware } from '../types';
5
+ declare const namespaceAndEndpointMiddleware: APIFetchMiddleware;
6
+ export default namespaceAndEndpointMiddleware;
6
7
  //# sourceMappingURL=namespace-endpoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"namespace-endpoint.d.ts","sourceRoot":"","sources":["../../src/middlewares/namespace-endpoint.js"],"names":[],"mappings":";AAAA;;GAEG;AACH,8CAFU,OAAO,UAAU,EAAE,kBAAkB,CA0B7C"}
1
+ {"version":3,"file":"namespace-endpoint.d.ts","sourceRoot":"","sources":["../../src/middlewares/namespace-endpoint.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,QAAA,MAAM,8BAA8B,EAAE,kBA2BrC,CAAC;AAEF,eAAe,8BAA8B,CAAC"}
@@ -1,9 +1,14 @@
1
- export default createNonceMiddleware;
2
1
  /**
3
- * @param {string} nonce
4
- * @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
2
+ * Internal dependencies
3
+ */
4
+ import type { APIFetchMiddleware } from '../types';
5
+ /**
6
+ * @param nonce
7
+ *
8
+ * @return A middleware to enhance a request with a nonce.
5
9
  */
6
- declare function createNonceMiddleware(nonce: string): import("../types").APIFetchMiddleware & {
10
+ declare function createNonceMiddleware(nonce: string): APIFetchMiddleware & {
7
11
  nonce: string;
8
12
  };
13
+ export default createNonceMiddleware;
9
14
  //# sourceMappingURL=nonce.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nonce.d.ts","sourceRoot":"","sources":["../../src/middlewares/nonce.js"],"names":[],"mappings":";AAAA;;;GAGG;AACH,8CAHW,MAAM,GACL,OAAO,UAAU,EAAE,kBAAkB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAgCpE"}
1
+ {"version":3,"file":"nonce.d.ts","sourceRoot":"","sources":["../../src/middlewares/nonce.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;GAIG;AACH,iBAAS,qBAAqB,CAC7B,KAAK,EAAE,MAAM,GACX,kBAAkB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CA8BxC;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,7 +1,11 @@
1
- export default createPreloadingMiddleware;
2
1
  /**
3
- * @param {Record<string, any>} preloadedData
4
- * @return {import('../types').APIFetchMiddleware} Preloading middleware.
2
+ * Internal dependencies
3
+ */
4
+ import type { APIFetchMiddleware } from '../types';
5
+ /**
6
+ * @param preloadedData
7
+ * @return Preloading middleware.
5
8
  */
6
- declare function createPreloadingMiddleware(preloadedData: Record<string, any>): import("../types").APIFetchMiddleware;
9
+ declare function createPreloadingMiddleware(preloadedData: Record<string, any>): APIFetchMiddleware;
10
+ export default createPreloadingMiddleware;
7
11
  //# sourceMappingURL=preloading.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preloading.d.ts","sourceRoot":"","sources":["../../src/middlewares/preloading.js"],"names":[],"mappings":";AAKA;;;GAGG;AACH,2DAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClB,OAAO,UAAU,EAAE,kBAAkB,CAqDhD"}
1
+ {"version":3,"file":"preloading.d.ts","sourceRoot":"","sources":["../../src/middlewares/preloading.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;GAGG;AACH,iBAAS,0BAA0B,CAClC,aAAa,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,GAClC,kBAAkB,CAkDpB;AAkDD,eAAe,0BAA0B,CAAC"}
@@ -1,7 +1,11 @@
1
- export default createRootURLMiddleware;
2
1
  /**
3
- * @param {string} rootURL
4
- * @return {import('../types').APIFetchMiddleware} Root URL middleware.
2
+ * Internal dependencies
3
+ */
4
+ import type { APIFetchMiddleware } from '../types';
5
+ /**
6
+ * @param rootURL
7
+ * @return Root URL middleware.
5
8
  */
6
- declare function createRootURLMiddleware(rootURL: string): import("../types").APIFetchMiddleware;
9
+ declare const createRootURLMiddleware: (rootURL: string) => APIFetchMiddleware;
10
+ export default createRootURLMiddleware;
7
11
  //# sourceMappingURL=root-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"root-url.d.ts","sourceRoot":"","sources":["../../src/middlewares/root-url.js"],"names":[],"mappings":";AAKA;;;GAGG;AACH,kDAHW,MAAM,GACL,OAAO,UAAU,EAAE,kBAAkB,CAkChD"}
1
+ {"version":3,"file":"root-url.d.ts","sourceRoot":"","sources":["../../src/middlewares/root-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;GAGG;AACH,QAAA,MAAM,uBAAuB,YACjB,MAAM,KAAI,kBAiCpB,CAAC;AAEH,eAAe,uBAAuB,CAAC"}
@@ -1,4 +1,7 @@
1
- export default createThemePreviewMiddleware;
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { APIFetchMiddleware } from '../types';
2
5
  /**
3
6
  * This appends a `wp_theme_preview` parameter to the REST API request URL if
4
7
  * the admin URL contains a `theme` GET parameter.
@@ -6,8 +9,9 @@ export default createThemePreviewMiddleware;
6
9
  * If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
7
10
  * then bypass this middleware.
8
11
  *
9
- * @param {Record<string, any>} themePath
10
- * @return {import('../types').APIFetchMiddleware} Preloading middleware.
12
+ * @param themePath
13
+ * @return Preloading middleware.
11
14
  */
12
- declare function createThemePreviewMiddleware(themePath: Record<string, any>): import("../types").APIFetchMiddleware;
15
+ declare const createThemePreviewMiddleware: (themePath: Record<string, any>) => APIFetchMiddleware;
16
+ export default createThemePreviewMiddleware;
13
17
  //# sourceMappingURL=theme-preview.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme-preview.d.ts","sourceRoot":"","sources":["../../src/middlewares/theme-preview.js"],"names":[],"mappings":";AAKA;;;;;;;;;GASG;AACH,yDAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClB,OAAO,UAAU,EAAE,kBAAkB,CA0BhD"}
1
+ {"version":3,"file":"theme-preview.d.ts","sourceRoot":"","sources":["../../src/middlewares/theme-preview.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;GASG;AACH,QAAA,MAAM,4BAA4B,cACpB,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,KAAI,kBAqCrC,CAAC;AAEH,eAAe,4BAA4B,CAAC"}
@@ -1,6 +1,7 @@
1
- export default userLocaleMiddleware;
2
1
  /**
3
- * @type {import('../types').APIFetchMiddleware}
2
+ * Internal dependencies
4
3
  */
5
- declare const userLocaleMiddleware: import("../types").APIFetchMiddleware;
4
+ import type { APIFetchMiddleware } from '../types';
5
+ declare const userLocaleMiddleware: APIFetchMiddleware;
6
+ export default userLocaleMiddleware;
6
7
  //# sourceMappingURL=user-locale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-locale.d.ts","sourceRoot":"","sources":["../../src/middlewares/user-locale.js"],"names":[],"mappings":";AAKA;;GAEG;AACH,oCAFU,OAAO,UAAU,EAAE,kBAAkB,CAkB7C"}
1
+ {"version":3,"file":"user-locale.d.ts","sourceRoot":"","sources":["../../src/middlewares/user-locale.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,QAAA,MAAM,oBAAoB,EAAE,kBAgB3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -1,14 +1,15 @@
1
- export interface APIFetchOptions extends RequestInit {
1
+ export interface APIFetchOptions<Parse extends boolean = boolean> extends RequestInit {
2
2
  headers?: Record<string, string>;
3
3
  path?: string;
4
4
  url?: string;
5
5
  /**
6
6
  * @default true
7
7
  */
8
- parse?: boolean;
8
+ parse?: Parse;
9
9
  data?: any;
10
10
  namespace?: string;
11
11
  endpoint?: string;
12
12
  }
13
- export type APIFetchMiddleware = (options: APIFetchOptions, next: (nextOptions: APIFetchOptions) => Promise<any>) => Promise<any>;
13
+ export type FetchHandler<Parse extends boolean = boolean> = (nextOptions: APIFetchOptions<Parse>) => Promise<any>;
14
+ export type APIFetchMiddleware<Parse extends boolean = boolean> = (options: APIFetchOptions<Parse>, next: FetchHandler<Parse>) => Promise<any>;
14
15
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAEnD,OAAO,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,CAAE,WAAW,EAAE,eAAe,KAAM,OAAO,CAAE,GAAG,CAAE,KACpD,OAAO,CAAE,GAAG,CAAE,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe,CAAE,KAAK,SAAS,OAAO,GAAG,OAAO,CAChE,SAAQ,WAAW;IAEnB,OAAO,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,YAAY,CAAE,KAAK,SAAS,OAAO,GAAG,OAAO,IAAK,CAC7D,WAAW,EAAE,eAAe,CAAE,KAAK,CAAE,KACjC,OAAO,CAAE,GAAG,CAAE,CAAC;AAEpB,MAAM,MAAM,kBAAkB,CAAE,KAAK,SAAS,OAAO,GAAG,OAAO,IAAK,CACnE,OAAO,EAAE,eAAe,CAAE,KAAK,CAAE,EACjC,IAAI,EAAE,YAAY,CAAE,KAAK,CAAE,KACvB,OAAO,CAAE,GAAG,CAAE,CAAC"}
@@ -1,10 +1,18 @@
1
+ /**
2
+ * Parses the apiFetch response properly and normalize response errors.
3
+ *
4
+ * @param response
5
+ * @param shouldParseResponse
6
+ *
7
+ * @return Parsed response.
8
+ */
9
+ export declare const parseResponseAndNormalizeError: (response: Response, shouldParseResponse?: boolean) => Promise<any>;
1
10
  /**
2
11
  * Parses a response, throwing an error if parsing the response fails.
3
12
  *
4
- * @param {Response} response
5
- * @param {boolean} shouldParseResponse
6
- * @return {Promise<any>} Parsed response.
13
+ * @param response
14
+ * @param shouldParseResponse
15
+ * @return Parsed response.
7
16
  */
8
- export function parseAndThrowError(response: Response, shouldParseResponse?: boolean): Promise<any>;
9
- export function parseResponseAndNormalizeError(response: Response, shouldParseResponse?: boolean): Promise<any>;
17
+ export declare function parseAndThrowError(response: Response, shouldParseResponse?: boolean): Promise<never>;
10
18
  //# sourceMappingURL=response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/utils/response.js"],"names":[],"mappings":"AAgEA;;;;;;GAMG;AACH,6CAJW,QAAQ,wBACR,OAAO,GACN,OAAO,CAAC,GAAG,CAAC,CAevB;AA7BM,yDALI,QAAQ,wBACR,OAAO,GAEN,OAAO,CAAC,GAAG,CAAC,CASvB"}
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AA+CA;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,aAChC,QAAQ,gDAMlB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,UAAO,kBAc1B"}