@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 +1,7 @@
1
- {"version":3,"names":["OVERRIDE_METHODS","Set","DEFAULT_METHOD","httpV1Middleware","options","next","method","has","toUpperCase","headers","_default","exports","default"],"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;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaT,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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,mBAAmB,oBAAI,IAAK,CAAE,SAAS,OAAO,QAAS,CAAE;AAU/D,MAAM,iBAAiB;AASvB,MAAM,mBAAuC,CAAE,SAAS,SAAU;AACjE,QAAM,EAAE,SAAS,eAAe,IAAI;AACpC,MAAK,iBAAiB,IAAK,OAAO,YAAY,CAAE,GAAI;AACnD,cAAU;AAAA,MACT,GAAG;AAAA,MACH,SAAS;AAAA,QACR,GAAG,QAAQ;AAAA,QACX,0BAA0B;AAAA,QAC1B,gBAAgB;AAAA,MACjB;AAAA,MACA,QAAQ;AAAA,IACT;AAAA,EACD;AAEA,SAAO,KAAM,OAAQ;AACtB;AAEA,IAAO,kBAAQ;",
6
+ "names": []
7
+ }
@@ -1,53 +1,45 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var media_upload_exports = {};
20
+ __export(media_upload_exports, {
21
+ default: () => media_upload_default
5
22
  });
6
- exports.default = void 0;
7
- var _i18n = require("@wordpress/i18n");
8
- var _response = require("../utils/response");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
-
17
- /**
18
- * @param options
19
- * @return True if the request is for media upload.
20
- */
23
+ module.exports = __toCommonJS(media_upload_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_response = require("../utils/response");
21
26
  function isMediaUploadRequest(options) {
22
- const isCreateMethod = !!options.method && options.method === 'POST';
23
- const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
27
+ const isCreateMethod = !!options.method && options.method === "POST";
28
+ const isMediaEndpoint = !!options.path && options.path.indexOf("/wp/v2/media") !== -1 || !!options.url && options.url.indexOf("/wp/v2/media") !== -1;
24
29
  return isMediaEndpoint && isCreateMethod;
25
30
  }
26
-
27
- /**
28
- * Middleware handling media upload failures and retries.
29
- * @param options
30
- * @param next
31
- */
32
31
  const mediaUploadMiddleware = (options, next) => {
33
32
  if (!isMediaUploadRequest(options)) {
34
33
  return next(options);
35
34
  }
36
35
  let retries = 0;
37
36
  const maxRetries = 5;
38
-
39
- /**
40
- * @param attachmentId
41
- * @return Processed post response.
42
- */
43
- const postProcess = attachmentId => {
37
+ const postProcess = (attachmentId) => {
44
38
  retries++;
45
39
  return next({
46
40
  path: `/wp/v2/media/${attachmentId}/post-process`,
47
- method: 'POST',
48
- data: {
49
- action: 'create-image-subsizes'
50
- },
41
+ method: "POST",
42
+ data: { action: "create-image-subsizes" },
51
43
  parse: false
52
44
  }).catch(() => {
53
45
  if (retries < maxRetries) {
@@ -55,33 +47,35 @@ const mediaUploadMiddleware = (options, next) => {
55
47
  }
56
48
  next({
57
49
  path: `/wp/v2/media/${attachmentId}?force=true`,
58
- method: 'DELETE'
50
+ method: "DELETE"
59
51
  });
60
52
  return Promise.reject();
61
53
  });
62
54
  };
63
- return next({
64
- ...options,
65
- parse: false
66
- }).catch(response => {
67
- // `response` could actually be an error thrown by `defaultFetchHandler`.
55
+ return next({ ...options, parse: false }).catch((response) => {
68
56
  if (!(response instanceof globalThis.Response)) {
69
57
  return Promise.reject(response);
70
58
  }
71
- const attachmentId = response.headers.get('x-wp-upload-attachment-id');
59
+ const attachmentId = response.headers.get(
60
+ "x-wp-upload-attachment-id"
61
+ );
72
62
  if (response.status >= 500 && response.status < 600 && attachmentId) {
73
63
  return postProcess(attachmentId).catch(() => {
74
64
  if (options.parse !== false) {
75
65
  return Promise.reject({
76
- code: 'post_process',
77
- message: (0, _i18n.__)('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
66
+ code: "post_process",
67
+ message: (0, import_i18n.__)(
68
+ "Media upload failed. If this is a photo or a large image, please scale it down and try again."
69
+ )
78
70
  });
79
71
  }
80
72
  return Promise.reject(response);
81
73
  });
82
74
  }
83
- return (0, _response.parseAndThrowError)(response, options.parse);
84
- }).then(response => (0, _response.parseResponseAndNormalizeError)(response, options.parse));
75
+ return (0, import_response.parseAndThrowError)(response, options.parse);
76
+ }).then(
77
+ (response) => (0, import_response.parseResponseAndNormalizeError)(response, options.parse)
78
+ );
85
79
  };
86
- var _default = exports.default = mediaUploadMiddleware;
87
- //# sourceMappingURL=media-upload.js.map
80
+ var media_upload_default = mediaUploadMiddleware;
81
+ //# sourceMappingURL=media-upload.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_response","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","__","parseAndThrowError","then","parseResponseAndNormalizeError","_default","exports","default"],"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":"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","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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAKnB,sBAGO;AAOP,SAAS,qBAAsB,SAA2B;AACzD,QAAM,iBAAiB,CAAC,CAAE,QAAQ,UAAU,QAAQ,WAAW;AAC/D,QAAM,kBACH,CAAC,CAAE,QAAQ,QAAQ,QAAQ,KAAK,QAAS,cAAe,MAAM,MAC9D,CAAC,CAAE,QAAQ,OAAO,QAAQ,IAAI,QAAS,cAAe,MAAM;AAE/D,SAAO,mBAAmB;AAC3B;AAOA,MAAM,wBAA4C,CAAE,SAAS,SAAU;AACtE,MAAK,CAAE,qBAAsB,OAAQ,GAAI;AACxC,WAAO,KAAM,OAAQ;AAAA,EACtB;AAEA,MAAI,UAAU;AACd,QAAM,aAAa;AAMnB,QAAM,cAAc,CAAE,iBAA0C;AAC/D;AACA,WAAO,KAAM;AAAA,MACZ,MAAM,gBAAiB,YAAa;AAAA,MACpC,QAAQ;AAAA,MACR,MAAM,EAAE,QAAQ,wBAAwB;AAAA,MACxC,OAAO;AAAA,IACR,CAAE,EAAE,MAAO,MAAM;AAChB,UAAK,UAAU,YAAa;AAC3B,eAAO,YAAa,YAAa;AAAA,MAClC;AACA,WAAM;AAAA,QACL,MAAM,gBAAiB,YAAa;AAAA,QACpC,QAAQ;AAAA,MACT,CAAE;AAEF,aAAO,QAAQ,OAAO;AAAA,IACvB,CAAE;AAAA,EACH;AAEA,SAAO,KAAM,EAAE,GAAG,SAAS,OAAO,MAAM,CAAE,EACxC,MAAO,CAAE,aAAwB;AAEjC,QAAK,EAAI,oBAAoB,WAAW,WAAa;AACpD,aAAO,QAAQ,OAAQ,QAAS;AAAA,IACjC;AAEA,UAAM,eAAe,SAAS,QAAQ;AAAA,MACrC;AAAA,IACD;AACA,QACC,SAAS,UAAU,OACnB,SAAS,SAAS,OAClB,cACC;AACD,aAAO,YAAa,YAAa,EAAE,MAAO,MAAM;AAC/C,YAAK,QAAQ,UAAU,OAAQ;AAC9B,iBAAO,QAAQ,OAAQ;AAAA,YACtB,MAAM;AAAA,YACN,aAAS;AAAA,cACR;AAAA,YACD;AAAA,UACD,CAAE;AAAA,QACH;AAEA,eAAO,QAAQ,OAAQ,QAAS;AAAA,MACjC,CAAE;AAAA,IACH;AACA,eAAO,oCAAoB,UAAU,QAAQ,KAAM;AAAA,EACpD,CAAE,EACD;AAAA,IAAM,CAAE,iBACR,gDAAgC,UAAU,QAAQ,KAAM;AAAA,EACzD;AACF;AAEA,IAAO,uBAAQ;",
6
+ "names": []
7
+ }
@@ -1,21 +1,34 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var namespace_endpoint_exports = {};
20
+ __export(namespace_endpoint_exports, {
21
+ default: () => namespace_endpoint_default
5
22
  });
6
- exports.default = void 0;
7
- /**
8
- * Internal dependencies
9
- */
10
-
23
+ module.exports = __toCommonJS(namespace_endpoint_exports);
11
24
  const namespaceAndEndpointMiddleware = (options, next) => {
12
25
  let path = options.path;
13
26
  let namespaceTrimmed, endpointTrimmed;
14
- if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
15
- namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
16
- endpointTrimmed = options.endpoint.replace(/^\//, '');
27
+ if (typeof options.namespace === "string" && typeof options.endpoint === "string") {
28
+ namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, "");
29
+ endpointTrimmed = options.endpoint.replace(/^\//, "");
17
30
  if (endpointTrimmed) {
18
- path = namespaceTrimmed + '/' + endpointTrimmed;
31
+ path = namespaceTrimmed + "/" + endpointTrimmed;
19
32
  } else {
20
33
  path = namespaceTrimmed;
21
34
  }
@@ -27,5 +40,5 @@ const namespaceAndEndpointMiddleware = (options, next) => {
27
40
  path
28
41
  });
29
42
  };
30
- var _default = exports.default = namespaceAndEndpointMiddleware;
31
- //# sourceMappingURL=namespace-endpoint.js.map
43
+ var namespace_endpoint_default = namespaceAndEndpointMiddleware;
44
+ //# sourceMappingURL=namespace-endpoint.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["namespaceAndEndpointMiddleware","options","next","path","namespaceTrimmed","endpointTrimmed","namespace","endpoint","replace","_default","exports","default"],"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;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaX,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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,iCAAqD,CAC1D,SACA,SACI;AACJ,MAAI,OAAO,QAAQ;AACnB,MAAI,kBAAkB;AAEtB,MACC,OAAO,QAAQ,cAAc,YAC7B,OAAO,QAAQ,aAAa,UAC3B;AACD,uBAAmB,QAAQ,UAAU,QAAS,YAAY,EAAG;AAC7D,sBAAkB,QAAQ,SAAS,QAAS,OAAO,EAAG;AACtD,QAAK,iBAAkB;AACtB,aAAO,mBAAmB,MAAM;AAAA,IACjC,OAAO;AACN,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO,QAAQ;AACf,SAAO,QAAQ;AAEf,SAAO,KAAM;AAAA,IACZ,GAAG;AAAA,IACH;AAAA,EACD,CAAE;AACH;AAEA,IAAO,6BAAQ;",
6
+ "names": []
7
+ }
@@ -1,28 +1,31 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var nonce_exports = {};
20
+ __export(nonce_exports, {
21
+ default: () => nonce_default
5
22
  });
6
- exports.default = void 0;
7
- /**
8
- * Internal dependencies
9
- */
10
-
11
- /**
12
- * @param nonce
13
- *
14
- * @return A middleware to enhance a request with a nonce.
15
- */
23
+ module.exports = __toCommonJS(nonce_exports);
16
24
  function createNonceMiddleware(nonce) {
17
25
  const middleware = (options, next) => {
18
- const {
19
- headers = {}
20
- } = options;
21
-
22
- // If an 'X-WP-Nonce' header (or any case-insensitive variation
23
- // thereof) was specified, no need to add a nonce header.
26
+ const { headers = {} } = options;
24
27
  for (const headerName in headers) {
25
- if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
28
+ if (headerName.toLowerCase() === "x-wp-nonce" && headers[headerName] === middleware.nonce) {
26
29
  return next(options);
27
30
  }
28
31
  }
@@ -30,12 +33,12 @@ function createNonceMiddleware(nonce) {
30
33
  ...options,
31
34
  headers: {
32
35
  ...headers,
33
- 'X-WP-Nonce': middleware.nonce
36
+ "X-WP-Nonce": middleware.nonce
34
37
  }
35
38
  });
36
39
  };
37
40
  middleware.nonce = nonce;
38
41
  return middleware;
39
42
  }
40
- var _default = exports.default = createNonceMiddleware;
41
- //# sourceMappingURL=nonce.js.map
43
+ var nonce_default = createNonceMiddleware;
44
+ //# sourceMappingURL=nonce.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createNonceMiddleware","nonce","middleware","options","next","headers","headerName","toLowerCase","_default","exports","default"],"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;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcV,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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,SAAS,sBACR,OACyC;AACzC,QAAM,aAAqD,CAC1D,SACA,SACI;AACJ,UAAM,EAAE,UAAU,CAAC,EAAE,IAAI;AAIzB,eAAY,cAAc,SAAU;AACnC,UACC,WAAW,YAAY,MAAM,gBAC7B,QAAS,UAAW,MAAM,WAAW,OACpC;AACD,eAAO,KAAM,OAAQ;AAAA,MACtB;AAAA,IACD;AAEA,WAAO,KAAM;AAAA,MACZ,GAAG;AAAA,MACH,SAAS;AAAA,QACR,GAAG;AAAA,QACH,cAAc,WAAW;AAAA,MAC1B;AAAA,IACD,CAAE;AAAA,EACH;AAEA,aAAW,QAAQ;AAEnB,SAAO;AACR;AAEA,IAAO,gBAAQ;",
6
+ "names": []
7
+ }
@@ -1,90 +1,93 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var preloading_exports = {};
20
+ __export(preloading_exports, {
21
+ default: () => preloading_default
5
22
  });
6
- exports.default = void 0;
7
- var _url = require("@wordpress/url");
8
- /**
9
- * WordPress dependencies
10
- */
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
-
16
- /**
17
- * @param preloadedData
18
- * @return Preloading middleware.
19
- */
23
+ module.exports = __toCommonJS(preloading_exports);
24
+ var import_url = require("@wordpress/url");
20
25
  function createPreloadingMiddleware(preloadedData) {
21
- const cache = Object.fromEntries(Object.entries(preloadedData).map(([path, data]) => [(0, _url.normalizePath)(path), data]));
26
+ const cache = Object.fromEntries(
27
+ Object.entries(preloadedData).map(([path, data]) => [
28
+ (0, import_url.normalizePath)(path),
29
+ data
30
+ ])
31
+ );
22
32
  return (options, next) => {
23
- const {
24
- parse = true
25
- } = options;
33
+ const { parse = true } = options;
26
34
  let rawPath = options.path;
27
35
  if (!rawPath && options.url) {
28
- const {
29
- rest_route: pathFromQuery,
30
- ...queryArgs
31
- } = (0, _url.getQueryArgs)(options.url);
32
- if (typeof pathFromQuery === 'string') {
33
- rawPath = (0, _url.addQueryArgs)(pathFromQuery, queryArgs);
36
+ const { rest_route: pathFromQuery, ...queryArgs } = (0, import_url.getQueryArgs)(
37
+ options.url
38
+ );
39
+ if (typeof pathFromQuery === "string") {
40
+ rawPath = (0, import_url.addQueryArgs)(pathFromQuery, queryArgs);
34
41
  }
35
42
  }
36
- if (typeof rawPath !== 'string') {
43
+ if (typeof rawPath !== "string") {
37
44
  return next(options);
38
45
  }
39
- const method = options.method || 'GET';
40
- const path = (0, _url.normalizePath)(rawPath);
41
- if ('GET' === method && cache[path]) {
46
+ const method = options.method || "GET";
47
+ const path = (0, import_url.normalizePath)(rawPath);
48
+ if ("GET" === method && cache[path]) {
42
49
  const cacheData = cache[path];
43
-
44
- // Unsetting the cache key ensures that the data is only used a single time.
45
50
  delete cache[path];
46
51
  return prepareResponse(cacheData, !!parse);
47
- } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
52
+ } else if ("OPTIONS" === method && cache[method] && cache[method][path]) {
48
53
  const cacheData = cache[method][path];
49
-
50
- // Unsetting the cache key ensures that the data is only used a single time.
51
54
  delete cache[method][path];
52
55
  return prepareResponse(cacheData, !!parse);
53
56
  }
54
57
  return next(options);
55
58
  };
56
59
  }
57
-
58
- /**
59
- * This is a helper function that sends a success response.
60
- *
61
- * @param responseData
62
- * @param parse
63
- * @return Promise with the response.
64
- */
65
60
  function prepareResponse(responseData, parse) {
66
61
  if (parse) {
67
62
  return Promise.resolve(responseData.body);
68
63
  }
69
64
  try {
70
- return Promise.resolve(new window.Response(JSON.stringify(responseData.body), {
71
- status: 200,
72
- statusText: 'OK',
73
- headers: responseData.headers
74
- }));
65
+ return Promise.resolve(
66
+ new window.Response(JSON.stringify(responseData.body), {
67
+ status: 200,
68
+ statusText: "OK",
69
+ headers: responseData.headers
70
+ })
71
+ );
75
72
  } catch {
76
- // See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926.
77
- Object.entries(responseData.headers).forEach(([key, value]) => {
78
- if (key.toLowerCase() === 'link') {
79
- responseData.headers[key] = value.replace(/<([^>]+)>/, (_, url) => `<${encodeURI(url)}>`);
73
+ Object.entries(
74
+ responseData.headers
75
+ ).forEach(([key, value]) => {
76
+ if (key.toLowerCase() === "link") {
77
+ responseData.headers[key] = value.replace(
78
+ /<([^>]+)>/,
79
+ (_, url) => `<${encodeURI(url)}>`
80
+ );
80
81
  }
81
82
  });
82
- return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
83
- status: 200,
84
- statusText: 'OK',
85
- headers: responseData.headers
86
- }));
83
+ return Promise.resolve(
84
+ parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
85
+ status: 200,
86
+ statusText: "OK",
87
+ headers: responseData.headers
88
+ })
89
+ );
87
90
  }
88
91
  }
89
- var _default = exports.default = createPreloadingMiddleware;
90
- //# sourceMappingURL=preloading.js.map
92
+ var preloading_default = createPreloadingMiddleware;
93
+ //# sourceMappingURL=preloading.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_url","require","createPreloadingMiddleware","preloadedData","cache","Object","fromEntries","entries","map","path","data","normalizePath","options","next","parse","rawPath","url","rest_route","pathFromQuery","queryArgs","getQueryArgs","addQueryArgs","method","cacheData","prepareResponse","responseData","Promise","resolve","body","window","Response","JSON","stringify","status","statusText","headers","forEach","key","value","toLowerCase","replace","_","encodeURI","_default","exports","default"],"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
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/middlewares/preloading.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs, getQueryArgs, normalizePath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\n\n/**\n * @param preloadedData\n * @return Preloading middleware.\n */\nfunction createPreloadingMiddleware(\n\tpreloadedData: Record< string, any >\n): APIFetchMiddleware {\n\tconst cache = Object.fromEntries(\n\t\tObject.entries( preloadedData ).map( ( [ path, data ] ) => [\n\t\t\tnormalizePath( path ),\n\t\t\tdata,\n\t\t] )\n\t);\n\n\treturn ( options, next ) => {\n\t\tconst { parse = true } = options;\n\t\tlet rawPath = options.path;\n\t\tif ( ! rawPath && options.url ) {\n\t\t\tconst { rest_route: pathFromQuery, ...queryArgs } = getQueryArgs(\n\t\t\t\toptions.url\n\t\t\t);\n\n\t\t\tif ( typeof pathFromQuery === 'string' ) {\n\t\t\t\trawPath = addQueryArgs( pathFromQuery, queryArgs );\n\t\t\t}\n\t\t}\n\n\t\tif ( typeof rawPath !== 'string' ) {\n\t\t\treturn next( options );\n\t\t}\n\n\t\tconst method = options.method || 'GET';\n\t\tconst path = normalizePath( rawPath );\n\n\t\tif ( 'GET' === method && cache[ path ] ) {\n\t\t\tconst cacheData = cache[ path ];\n\n\t\t\t// Unsetting the cache key ensures that the data is only used a single time.\n\t\t\tdelete cache[ path ];\n\n\t\t\treturn prepareResponse( cacheData, !! parse );\n\t\t} else if (\n\t\t\t'OPTIONS' === method &&\n\t\t\tcache[ method ] &&\n\t\t\tcache[ method ][ path ]\n\t\t) {\n\t\t\tconst cacheData = cache[ method ][ path ];\n\n\t\t\t// Unsetting the cache key ensures that the data is only used a single time.\n\t\t\tdelete cache[ method ][ path ];\n\n\t\t\treturn prepareResponse( cacheData, !! parse );\n\t\t}\n\n\t\treturn next( options );\n\t};\n}\n\n/**\n * This is a helper function that sends a success response.\n *\n * @param responseData\n * @param parse\n * @return Promise with the response.\n */\nfunction prepareResponse(\n\tresponseData: Record< string, any >,\n\tparse: boolean\n) {\n\tif ( parse ) {\n\t\treturn Promise.resolve( responseData.body );\n\t}\n\n\ttry {\n\t\treturn Promise.resolve(\n\t\t\tnew window.Response( JSON.stringify( responseData.body ), {\n\t\t\t\tstatus: 200,\n\t\t\t\tstatusText: 'OK',\n\t\t\t\theaders: responseData.headers,\n\t\t\t} )\n\t\t);\n\t} catch {\n\t\t// See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926.\n\t\tObject.entries(\n\t\t\tresponseData.headers as Record< string, string >\n\t\t).forEach( ( [ key, value ] ) => {\n\t\t\tif ( key.toLowerCase() === 'link' ) {\n\t\t\t\tresponseData.headers[ key ] = value.replace(\n\t\t\t\t\t/<([^>]+)>/,\n\t\t\t\t\t( _, url ) => `<${ encodeURI( url ) }>`\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t\treturn Promise.resolve(\n\t\t\tparse\n\t\t\t\t? responseData.body\n\t\t\t\t: new window.Response( JSON.stringify( responseData.body ), {\n\t\t\t\t\t\tstatus: 200,\n\t\t\t\t\t\tstatusText: 'OK',\n\t\t\t\t\t\theaders: responseData.headers,\n\t\t\t\t } )\n\t\t);\n\t}\n}\n\nexport default createPreloadingMiddleware;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0D;AAW1D,SAAS,2BACR,eACqB;AACrB,QAAM,QAAQ,OAAO;AAAA,IACpB,OAAO,QAAS,aAAc,EAAE,IAAK,CAAE,CAAE,MAAM,IAAK,MAAO;AAAA,UAC1D,0BAAe,IAAK;AAAA,MACpB;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO,CAAE,SAAS,SAAU;AAC3B,UAAM,EAAE,QAAQ,KAAK,IAAI;AACzB,QAAI,UAAU,QAAQ;AACtB,QAAK,CAAE,WAAW,QAAQ,KAAM;AAC/B,YAAM,EAAE,YAAY,eAAe,GAAG,UAAU,QAAI;AAAA,QACnD,QAAQ;AAAA,MACT;AAEA,UAAK,OAAO,kBAAkB,UAAW;AACxC,sBAAU,yBAAc,eAAe,SAAU;AAAA,MAClD;AAAA,IACD;AAEA,QAAK,OAAO,YAAY,UAAW;AAClC,aAAO,KAAM,OAAQ;AAAA,IACtB;AAEA,UAAM,SAAS,QAAQ,UAAU;AACjC,UAAM,WAAO,0BAAe,OAAQ;AAEpC,QAAK,UAAU,UAAU,MAAO,IAAK,GAAI;AACxC,YAAM,YAAY,MAAO,IAAK;AAG9B,aAAO,MAAO,IAAK;AAEnB,aAAO,gBAAiB,WAAW,CAAC,CAAE,KAAM;AAAA,IAC7C,WACC,cAAc,UACd,MAAO,MAAO,KACd,MAAO,MAAO,EAAG,IAAK,GACrB;AACD,YAAM,YAAY,MAAO,MAAO,EAAG,IAAK;AAGxC,aAAO,MAAO,MAAO,EAAG,IAAK;AAE7B,aAAO,gBAAiB,WAAW,CAAC,CAAE,KAAM;AAAA,IAC7C;AAEA,WAAO,KAAM,OAAQ;AAAA,EACtB;AACD;AASA,SAAS,gBACR,cACA,OACC;AACD,MAAK,OAAQ;AACZ,WAAO,QAAQ,QAAS,aAAa,IAAK;AAAA,EAC3C;AAEA,MAAI;AACH,WAAO,QAAQ;AAAA,MACd,IAAI,OAAO,SAAU,KAAK,UAAW,aAAa,IAAK,GAAG;AAAA,QACzD,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,SAAS,aAAa;AAAA,MACvB,CAAE;AAAA,IACH;AAAA,EACD,QAAQ;AAEP,WAAO;AAAA,MACN,aAAa;AAAA,IACd,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AAChC,UAAK,IAAI,YAAY,MAAM,QAAS;AACnC,qBAAa,QAAS,GAAI,IAAI,MAAM;AAAA,UACnC;AAAA,UACA,CAAE,GAAG,QAAS,IAAK,UAAW,GAAI,CAAE;AAAA,QACrC;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,QAAQ;AAAA,MACd,QACG,aAAa,OACb,IAAI,OAAO,SAAU,KAAK,UAAW,aAAa,IAAK,GAAG;AAAA,QAC1D,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,SAAS,aAAa;AAAA,MACtB,CAAE;AAAA,IACN;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
6
+ "names": []
7
+ }
@@ -1,35 +1,50 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var root_url_exports = {};
30
+ __export(root_url_exports, {
31
+ default: () => root_url_default
6
32
  });
7
- exports.default = void 0;
8
- var _namespaceEndpoint = _interopRequireDefault(require("./namespace-endpoint"));
9
- /**
10
- * Internal dependencies
11
- */
12
-
13
- /**
14
- * @param rootURL
15
- * @return Root URL middleware.
16
- */
17
- const createRootURLMiddleware = rootURL => (options, next) => {
18
- return (0, _namespaceEndpoint.default)(options, optionsWithPath => {
33
+ module.exports = __toCommonJS(root_url_exports);
34
+ var import_namespace_endpoint = __toESM(require("./namespace-endpoint"));
35
+ const createRootURLMiddleware = (rootURL) => (options, next) => {
36
+ return (0, import_namespace_endpoint.default)(options, (optionsWithPath) => {
19
37
  let url = optionsWithPath.url;
20
38
  let path = optionsWithPath.path;
21
39
  let apiRoot;
22
- if (typeof path === 'string') {
40
+ if (typeof path === "string") {
23
41
  apiRoot = rootURL;
24
- if (-1 !== rootURL.indexOf('?')) {
25
- path = path.replace('?', '&');
42
+ if (-1 !== rootURL.indexOf("?")) {
43
+ path = path.replace("?", "&");
26
44
  }
27
- path = path.replace(/^\//, '');
28
-
29
- // API root may already include query parameter prefix if site is
30
- // configured to use plain permalinks.
31
- if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
32
- path = path.replace('?', '&');
45
+ path = path.replace(/^\//, "");
46
+ if ("string" === typeof apiRoot && -1 !== apiRoot.indexOf("?")) {
47
+ path = path.replace("?", "&");
33
48
  }
34
49
  url = apiRoot + path;
35
50
  }
@@ -39,5 +54,5 @@ const createRootURLMiddleware = rootURL => (options, next) => {
39
54
  });
40
55
  });
41
56
  };
42
- var _default = exports.default = createRootURLMiddleware;
43
- //# sourceMappingURL=root-url.js.map
57
+ var root_url_default = createRootURLMiddleware;
58
+ //# sourceMappingURL=root-url.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_namespaceEndpoint","_interopRequireDefault","require","createRootURLMiddleware","rootURL","options","next","namespaceAndEndpointMiddleware","optionsWithPath","url","path","apiRoot","indexOf","replace","_default","exports","default"],"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":";;;;;;;AAIA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAC1BC,OAAe,IACjB,CAAEC,OAAO,EAAEC,IAAI,KAAM;EACpB,OAAO,IAAAC,0BAA8B,EAAEF,OAAO,EAAIG,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,GAAGP,OAAO;MAEjB,IAAK,CAAC,CAAC,KAAKA,OAAO,CAACQ,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,OAAOJ,IAAI,CAAE;MACZ,GAAGE,eAAe;MAClBC;IACD,CAAE,CAAC;EACJ,CAAE,CAAC;AACJ,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEYb,uBAAuB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/middlewares/root-url.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { APIFetchMiddleware } from '../types';\nimport namespaceAndEndpointMiddleware from './namespace-endpoint';\n\n/**\n * @param rootURL\n * @return Root URL middleware.\n */\nconst createRootURLMiddleware =\n\t( rootURL: string ): APIFetchMiddleware =>\n\t( options, next ) => {\n\t\treturn namespaceAndEndpointMiddleware( options, ( optionsWithPath ) => {\n\t\t\tlet url = optionsWithPath.url;\n\t\t\tlet path = optionsWithPath.path;\n\t\t\tlet apiRoot;\n\n\t\t\tif ( typeof path === 'string' ) {\n\t\t\t\tapiRoot = rootURL;\n\n\t\t\t\tif ( -1 !== rootURL.indexOf( '?' ) ) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\tpath = path.replace( /^\\//, '' );\n\n\t\t\t\t// API root may already include query parameter prefix if site is\n\t\t\t\t// configured to use plain permalinks.\n\t\t\t\tif (\n\t\t\t\t\t'string' === typeof apiRoot &&\n\t\t\t\t\t-1 !== apiRoot.indexOf( '?' )\n\t\t\t\t) {\n\t\t\t\t\tpath = path.replace( '?', '&' );\n\t\t\t\t}\n\n\t\t\t\turl = apiRoot + path;\n\t\t\t}\n\n\t\t\treturn next( {\n\t\t\t\t...optionsWithPath,\n\t\t\t\turl,\n\t\t\t} );\n\t\t} );\n\t};\n\nexport default createRootURLMiddleware;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAA2C;AAM3C,MAAM,0BACL,CAAE,YACF,CAAE,SAAS,SAAU;AACpB,aAAO,0BAAAA,SAAgC,SAAS,CAAE,oBAAqB;AACtE,QAAI,MAAM,gBAAgB;AAC1B,QAAI,OAAO,gBAAgB;AAC3B,QAAI;AAEJ,QAAK,OAAO,SAAS,UAAW;AAC/B,gBAAU;AAEV,UAAK,OAAO,QAAQ,QAAS,GAAI,GAAI;AACpC,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,aAAO,KAAK,QAAS,OAAO,EAAG;AAI/B,UACC,aAAa,OAAO,WACpB,OAAO,QAAQ,QAAS,GAAI,GAC3B;AACD,eAAO,KAAK,QAAS,KAAK,GAAI;AAAA,MAC/B;AAEA,YAAM,UAAU;AAAA,IACjB;AAEA,WAAO,KAAM;AAAA,MACZ,GAAG;AAAA,MACH;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACH;AAED,IAAO,mBAAQ;",
6
+ "names": ["namespaceAndEndpointMiddleware"]
7
+ }