@wordpress/e2e-test-utils-playwright 1.32.0 → 1.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 (113) hide show
  1. package/build/admin/create-new-post.js +46 -28
  2. package/build/admin/create-new-post.js.map +7 -1
  3. package/build/admin/edit-post.js +35 -17
  4. package/build/admin/edit-post.js.map +7 -1
  5. package/build/admin/get-page-error.js +30 -22
  6. package/build/admin/get-page-error.js.map +7 -1
  7. package/build/admin/index.js +54 -34
  8. package/build/admin/index.js.map +7 -1
  9. package/build/admin/visit-admin-page.js +42 -29
  10. package/build/admin/visit-admin-page.js.map +7 -1
  11. package/build/admin/visit-site-editor.js +71 -64
  12. package/build/admin/visit-site-editor.js.map +7 -1
  13. package/build/config.js +40 -10
  14. package/build/config.js.map +7 -1
  15. package/build/editor/click-block-options-menu-item.js +29 -14
  16. package/build/editor/click-block-options-menu-item.js.map +7 -1
  17. package/build/editor/click-block-toolbar-button.js +33 -13
  18. package/build/editor/click-block-toolbar-button.js.map +7 -1
  19. package/build/editor/get-blocks.js +59 -43
  20. package/build/editor/get-blocks.js.map +7 -1
  21. package/build/editor/get-edited-post-content.js +31 -12
  22. package/build/editor/get-edited-post-content.js.map +7 -1
  23. package/build/editor/index.js +92 -72
  24. package/build/editor/index.js.map +7 -1
  25. package/build/editor/insert-block.js +50 -21
  26. package/build/editor/insert-block.js.map +7 -1
  27. package/build/editor/open-document-settings-sidebar.js +37 -24
  28. package/build/editor/open-document-settings-sidebar.js.map +7 -1
  29. package/build/editor/preview.js +37 -18
  30. package/build/editor/preview.js.map +7 -1
  31. package/build/editor/publish-post.js +42 -42
  32. package/build/editor/publish-post.js.map +7 -1
  33. package/build/editor/save-draft.js +29 -15
  34. package/build/editor/save-draft.js.map +7 -1
  35. package/build/editor/select-blocks.js +46 -25
  36. package/build/editor/select-blocks.js.map +7 -1
  37. package/build/editor/set-content.js +34 -14
  38. package/build/editor/set-content.js.map +7 -1
  39. package/build/editor/set-is-fixed-toolbar.js +31 -15
  40. package/build/editor/set-is-fixed-toolbar.js.map +7 -1
  41. package/build/editor/set-preferences.js +38 -18
  42. package/build/editor/set-preferences.js.map +7 -1
  43. package/build/editor/show-block-toolbar.js +30 -16
  44. package/build/editor/show-block-toolbar.js.map +7 -1
  45. package/build/editor/site-editor.js +46 -41
  46. package/build/editor/site-editor.js.map +7 -1
  47. package/build/editor/switch-editor-tool.js +42 -30
  48. package/build/editor/switch-editor-tool.js.map +7 -1
  49. package/build/editor/switch-to-legacy-canvas.js +33 -14
  50. package/build/editor/switch-to-legacy-canvas.js.map +7 -1
  51. package/build/editor/transform-block-to.js +41 -21
  52. package/build/editor/transform-block-to.js.map +7 -1
  53. package/build/index.js +50 -32
  54. package/build/index.js.map +7 -1
  55. package/build/lighthouse/index.js +89 -53
  56. package/build/lighthouse/index.js.map +7 -1
  57. package/build/metrics/index.js +298 -249
  58. package/build/metrics/index.js.map +7 -1
  59. package/build/page-utils/drag-files.js +134 -112
  60. package/build/page-utils/drag-files.js.map +7 -1
  61. package/build/page-utils/emulate-network-conditions.js +92 -66
  62. package/build/page-utils/emulate-network-conditions.js.map +7 -1
  63. package/build/page-utils/index.js +54 -34
  64. package/build/page-utils/index.js.map +7 -1
  65. package/build/page-utils/is-current-url.js +31 -18
  66. package/build/page-utils/is-current-url.js.map +7 -1
  67. package/build/page-utils/keycodes.js +51 -39
  68. package/build/page-utils/keycodes.js.map +7 -1
  69. package/build/page-utils/press-keys.js +148 -127
  70. package/build/page-utils/press-keys.js.map +7 -1
  71. package/build/page-utils/set-browser-viewport.js +32 -41
  72. package/build/page-utils/set-browser-viewport.js.map +7 -1
  73. package/build/request-utils/blocks.js +49 -40
  74. package/build/request-utils/blocks.js.map +7 -1
  75. package/build/request-utils/comments.js +57 -45
  76. package/build/request-utils/comments.js.map +7 -1
  77. package/build/request-utils/gutenberg-experiments.js +48 -26
  78. package/build/request-utils/gutenberg-experiments.js.map +7 -1
  79. package/build/request-utils/index.js +187 -153
  80. package/build/request-utils/index.js.map +7 -1
  81. package/build/request-utils/login.js +43 -18
  82. package/build/request-utils/login.js.map +7 -1
  83. package/build/request-utils/media.js +72 -64
  84. package/build/request-utils/media.js.map +7 -1
  85. package/build/request-utils/menus.js +119 -109
  86. package/build/request-utils/menus.js.map +7 -1
  87. package/build/request-utils/pages.js +60 -49
  88. package/build/request-utils/pages.js.map +7 -1
  89. package/build/request-utils/patterns.js +39 -24
  90. package/build/request-utils/patterns.js.map +7 -1
  91. package/build/request-utils/plugins.js +68 -74
  92. package/build/request-utils/plugins.js.map +7 -1
  93. package/build/request-utils/posts.js +52 -39
  94. package/build/request-utils/posts.js.map +7 -1
  95. package/build/request-utils/preferences.js +36 -17
  96. package/build/request-utils/preferences.js.map +7 -1
  97. package/build/request-utils/rest.js +153 -129
  98. package/build/request-utils/rest.js.map +7 -1
  99. package/build/request-utils/site-settings.js +38 -28
  100. package/build/request-utils/site-settings.js.map +7 -1
  101. package/build/request-utils/templates.js +57 -45
  102. package/build/request-utils/templates.js.map +7 -1
  103. package/build/request-utils/themes.js +78 -53
  104. package/build/request-utils/themes.js.map +7 -1
  105. package/build/request-utils/users.js +72 -72
  106. package/build/request-utils/users.js.map +7 -1
  107. package/build/request-utils/widgets.js +71 -55
  108. package/build/request-utils/widgets.js.map +7 -1
  109. package/build/test.js +128 -146
  110. package/build/test.js.map +7 -1
  111. package/build/types.js +16 -2
  112. package/build/types.js.map +7 -1
  113. package/package.json +6 -2
@@ -1 +1,7 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/request-utils/plugins.ts"],"names":[],"mappings":";;AAsGS,sCAAa;AAAE,wCAAc;AAAE,4CAAgB;AAtGxD;;GAEG;AACH,6CAAqD;AAOrD;;;;;;GAMG;AACH,KAAK,UAAU,aAAa,CAAsB,YAAY,GAAG,KAAK;IACrE,IAAK,CAAE,YAAY,IAAI,IAAI,CAAC,UAAU,EAAG,CAAC;QACzC,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GAAG,gBAAgB,CAAE,IAAI,EAAE,UAAU,CAAE,CAAC;IAEpD,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,kBAAmB,MAAO,EAAE;QAClC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;KAC1B,CAAE,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,gBAAgB,CAAsB,IAAY;IAChE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAG,gBAAgB,CAAE,IAAI,EAAE,UAAU,CAAE,CAAC;IAEpD,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,kBAAmB,MAAO,EAAE;QAClC,IAAI,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;KAC5B,CAAE,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/plugins.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\n/**\n * Fetch the plugins from API and cache them in memory,\n * since they are unlikely to change during testing.\n *\n * @param this\n * @param forceRefetch Force refetch the installed plugins to update the cache.\n */\nasync function getPluginsMap( this: RequestUtils, forceRefetch = false ) {\n\tif ( ! forceRefetch && this.pluginsMap ) {\n\t\treturn this.pluginsMap;\n\t}\n\n\tconst plugins = await this.rest( {\n\t\tpath: '/wp/v2/plugins',\n\t} );\n\tthis.pluginsMap = {};\n\tfor ( const plugin of plugins ) {\n\t\t// Ideally, we should be using sanitize_title() in PHP rather than kebabCase(),\n\t\t// but we don't have the exact port of it in JS.\n\t\t// This is a good approximation though.\n\t\tconst slug = kebabCase( plugin.name.toLowerCase() );\n\t\tthis.pluginsMap[ slug ] = plugin.plugin;\n\t}\n\treturn this.pluginsMap;\n}\n\n/**\n * Finds a plugin in the plugin map.\n *\n * Attempts to provide a helpful error message if not found.\n *\n * @param slug Plugin slug.\n * @param pluginsMap Plugins map.\n */\nfunction getPluginFromMap(\n\tslug: string,\n\tpluginsMap: Record< string, string >\n) {\n\tconst plugin = pluginsMap[ slug ];\n\n\tif ( ! plugin ) {\n\t\tfor ( const key of Object.keys( pluginsMap ) ) {\n\t\t\tif (\n\t\t\t\tkey.toLowerCase().replace( /-/g, '' ) ===\n\t\t\t\tslug.toLowerCase().replace( /-/g, '' )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The plugin \"${ slug }\" isn't installed. Did you perhaps mean \"${ key }\"?`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error( `The plugin \"${ slug }\" isn't installed` );\n\t}\n\n\treturn plugin;\n}\n\n/**\n * Activates an installed plugin.\n *\n * @param this RequestUtils.\n * @param slug Plugin slug.\n */\nasync function activatePlugin( this: RequestUtils, slug: string ) {\n\tconst pluginsMap = await this.getPluginsMap();\n\tconst plugin = getPluginFromMap( slug, pluginsMap );\n\n\tawait this.rest( {\n\t\tmethod: 'PUT',\n\t\tpath: `/wp/v2/plugins/${ plugin }`,\n\t\tdata: { status: 'active' },\n\t} );\n}\n\n/**\n * Deactivates an active plugin.\n *\n * @param this RequestUtils.\n * @param slug Plugin slug.\n */\nasync function deactivatePlugin( this: RequestUtils, slug: string ) {\n\tconst pluginsMap = await this.getPluginsMap();\n\tconst plugin = getPluginFromMap( slug, pluginsMap );\n\n\tawait this.rest( {\n\t\tmethod: 'PUT',\n\t\tpath: `/wp/v2/plugins/${ plugin }`,\n\t\tdata: { status: 'inactive' },\n\t} );\n}\n\nexport { getPluginsMap, activatePlugin, deactivatePlugin };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAcvC,eAAe,cAAmC,eAAe,OAAQ;AACxE,MA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.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteAllPosts = deleteAllPosts;
4
- exports.createPost = createPost;
5
- /**
6
- * Delete all posts using REST API.
7
- *
8
- * @param this
9
- */
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 posts_exports = {};
20
+ __export(posts_exports, {
21
+ createPost: () => createPost,
22
+ deleteAllPosts: () => deleteAllPosts
23
+ });
24
+ module.exports = __toCommonJS(posts_exports);
10
25
  async function deleteAllPosts() {
11
- // List all posts.
12
- // https://developer.wordpress.org/rest-api/reference/posts/#list-posts
13
- const posts = await this.rest({
14
- path: '/wp/v2/posts',
15
- params: {
16
- per_page: 100,
17
- // All possible statuses.
18
- status: 'publish,future,draft,pending,private,trash',
19
- },
20
- });
21
- // Delete all posts one by one.
22
- // https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post
23
- // "/wp/v2/posts" not yet supports batch requests.
24
- await Promise.all(posts.map((post) => this.rest({
25
- method: 'DELETE',
26
+ const posts = await this.rest({
27
+ path: "/wp/v2/posts",
28
+ params: {
29
+ per_page: 100,
30
+ // All possible statuses.
31
+ status: "publish,future,draft,pending,private,trash"
32
+ }
33
+ });
34
+ await Promise.all(
35
+ posts.map(
36
+ (post) => this.rest({
37
+ method: "DELETE",
26
38
  path: `/wp/v2/posts/${post.id}`,
27
39
  params: {
28
- force: true,
29
- },
30
- })));
40
+ force: true
41
+ }
42
+ })
43
+ )
44
+ );
31
45
  }
32
- /**
33
- * Creates a new post using the REST API.
34
- *
35
- * @param this
36
- * @param payload Post attributes.
37
- */
38
46
  async function createPost(payload) {
39
- const post = await this.rest({
40
- method: 'POST',
41
- path: `/wp/v2/posts`,
42
- data: { ...payload },
43
- });
44
- return post;
47
+ const post = await this.rest({
48
+ method: "POST",
49
+ path: `/wp/v2/posts`,
50
+ data: { ...payload }
51
+ });
52
+ return post;
45
53
  }
46
- //# sourceMappingURL=posts.js.map
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ createPost,
57
+ deleteAllPosts
58
+ });
59
+ //# sourceMappingURL=posts.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"posts.js","sourceRoot":"","sources":["../../src/request-utils/posts.ts"],"names":[],"mappings":";;AAyBA,wCA0BC;AAQD,gCAWC;AAlDD;;;;GAIG;AACI,KAAK,UAAU,cAAc;IACnC,kBAAkB;IAClB,uEAAuE;IACvE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAY;QACxC,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;YACb,yBAAyB;YACzB,MAAM,EAAE,4CAA4C;SACpD;KACD,CAAE,CAAC;IAEJ,+BAA+B;IAC/B,0EAA0E;IAC1E,kDAAkD;IAClD,MAAM,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAE,CAAE,IAAI,EAAG,EAAE,CACrB,IAAI,CAAC,IAAI,CAAE;QACV,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,gBAAiB,IAAI,CAAC,EAAG,EAAE;QACjC,MAAM,EAAE;YACP,KAAK,EAAE,IAAI;SACX;KACD,CAAE,CACH,CACD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,UAAU,CAE/B,OAA0B;IAE1B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAU;QACrC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE;KACpB,CAAE,CAAC;IAEJ,OAAO,IAAI,CAAC;AACb,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/posts.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\nexport interface Post {\n\tid: number;\n\tcontent: string;\n\tstatus: 'publish' | 'future' | 'draft' | 'pending' | 'private';\n\tlink: string;\n}\n\nexport interface CreatePostPayload {\n\ttitle?: string;\n\tcontent?: string;\n\tstatus: 'publish' | 'future' | 'draft' | 'pending' | 'private';\n\tdate?: string;\n\tdate_gmt: string;\n}\n\n/**\n * Delete all posts using REST API.\n *\n * @param this\n */\nexport async function deleteAllPosts( this: RequestUtils ) {\n\t// List all posts.\n\t// https://developer.wordpress.org/rest-api/reference/posts/#list-posts\n\tconst posts = await this.rest< Post[] >( {\n\t\tpath: '/wp/v2/posts',\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t\t// All possible statuses.\n\t\t\tstatus: 'publish,future,draft,pending,private,trash',\n\t\t},\n\t} );\n\n\t// Delete all posts one by one.\n\t// https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post\n\t// \"/wp/v2/posts\" not yet supports batch requests.\n\tawait Promise.all(\n\t\tposts.map( ( post ) =>\n\t\t\tthis.rest( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\tpath: `/wp/v2/posts/${ post.id }`,\n\t\t\t\tparams: {\n\t\t\t\t\tforce: true,\n\t\t\t\t},\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Creates a new post using the REST API.\n *\n * @param this\n * @param payload Post attributes.\n */\nexport async function createPost(\n\tthis: RequestUtils,\n\tpayload: CreatePostPayload\n) {\n\tconst post = await this.rest< Post >( {\n\t\tmethod: 'POST',\n\t\tpath: `/wp/v2/posts`,\n\t\tdata: { ...payload },\n\t} );\n\n\treturn post;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,eAAsB,iBAAqC;AAG1D,QAAM,QAAQ,MAAM,KAAK,KAAgB;AAAA,IACxC,MAAM;AAAA,IACN,QAAQ;AAAA,MACP,UAAU;AAAA;AAAA,MAEV,QAAQ;AAAA,IACT;AAAA,EACD,CAAE;AAKF,QAAM,QAAQ;AAAA,IACb,MAAM;AAAA,MAAK,CAAE,SACZ,KAAK,KAAM;AAAA,QACV,QAAQ;AAAA,QACR,MAAM,gBAAiB,KAAK,EAAG;AAAA,QAC/B,QAAQ;AAAA,UACP,OAAO;AAAA,QACR;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AACD;AAQA,eAAsB,WAErB,SACC;AACD,QAAM,OAAO,MAAM,KAAK,KAAc;AAAA,IACrC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM,EAAE,GAAG,QAAQ;AAAA,EACpB,CAAE;AAEF,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1,20 +1,39 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetPreferences = resetPreferences;
4
- /**
5
- * Reset user preferences
6
- *
7
- * @param this Request utils.
8
- */
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 preferences_exports = {};
20
+ __export(preferences_exports, {
21
+ resetPreferences: () => resetPreferences
22
+ });
23
+ module.exports = __toCommonJS(preferences_exports);
9
24
  async function resetPreferences() {
10
- await this.rest({
11
- path: '/wp/v2/users/me',
12
- method: 'PUT',
13
- data: {
14
- meta: {
15
- persisted_preferences: {},
16
- },
17
- },
18
- });
25
+ await this.rest({
26
+ path: "/wp/v2/users/me",
27
+ method: "PUT",
28
+ data: {
29
+ meta: {
30
+ persisted_preferences: {}
31
+ }
32
+ }
33
+ });
19
34
  }
20
- //# sourceMappingURL=preferences.js.map
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ resetPreferences
38
+ });
39
+ //# sourceMappingURL=preferences.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../src/request-utils/preferences.ts"],"names":[],"mappings":";;AAUA,4CAUC;AAfD;;;;GAIG;AACI,KAAK,UAAU,gBAAgB;IACrC,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE;YACL,IAAI,EAAE;gBACL,qBAAqB,EAAE,EAAE;aACzB;SACD;KACD,CAAE,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/preferences.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\n/**\n * Reset user preferences\n *\n * @param this Request utils.\n */\nexport async function resetPreferences( this: RequestUtils ) {\n\tawait this.rest( {\n\t\tpath: '/wp/v2/users/me',\n\t\tmethod: 'PUT',\n\t\tdata: {\n\t\t\tmeta: {\n\t\t\t\tpersisted_preferences: {},\n\t\t\t},\n\t\t},\n\t} );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,eAAsB,mBAAuC;AAC5D,QAAM,KAAK,KAAM;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM;AAAA,MACL,MAAM;AAAA,QACL,uBAAuB,CAAC;AAAA,MACzB;AAAA,IACD;AAAA,EACD,CAAE;AACH;",
6
+ "names": []
7
+ }
@@ -1,148 +1,172 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupRest = setupRest;
4
- exports.rest = rest;
5
- exports.getMaxBatchSize = getMaxBatchSize;
6
- exports.batchRest = batchRest;
7
- /**
8
- * External dependencies
9
- */
10
- const fs = require("fs/promises");
11
- const path_1 = require("path");
12
- const test_1 = require("@playwright/test");
13
- /**
14
- * Internal dependencies
15
- */
16
- const config_1 = require("../config");
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 rest_exports = {};
30
+ __export(rest_exports, {
31
+ batchRest: () => batchRest,
32
+ getMaxBatchSize: () => getMaxBatchSize,
33
+ rest: () => rest,
34
+ setupRest: () => setupRest
35
+ });
36
+ module.exports = __toCommonJS(rest_exports);
37
+ var fs = __toESM(require("fs/promises"));
38
+ var import_path = require("path");
39
+ var import_test = require("@playwright/test");
40
+ var import_config = require("../config");
17
41
  function splitRequestsToChunks(requests, chunkSize) {
18
- const arr = [...requests];
19
- const cache = [];
20
- while (arr.length) {
21
- cache.push(arr.splice(0, chunkSize));
22
- }
23
- return cache;
42
+ const arr = [...requests];
43
+ const cache = [];
44
+ while (arr.length) {
45
+ cache.push(arr.splice(0, chunkSize));
46
+ }
47
+ return cache;
24
48
  }
25
49
  async function getAPIRootURL(request) {
26
- // Discover the API root url using link header.
27
- // See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header
28
- const response = await request.head(config_1.WP_BASE_URL);
29
- const links = response.headers().link;
30
- const restLink = links?.match(/<([^>]+)>; rel="https:\/\/api\.w\.org\/"/);
31
- if (!restLink) {
32
- throw new Error(`Failed to discover REST API endpoint.
50
+ const response = await request.head(import_config.WP_BASE_URL);
51
+ const links = response.headers().link;
52
+ const restLink = links?.match(/<([^>]+)>; rel="https:\/\/api\.w\.org\/"/);
53
+ if (!restLink) {
54
+ throw new Error(`Failed to discover REST API endpoint.
33
55
  Link header: ${links}`);
34
- }
35
- const [, rootURL] = restLink;
36
- return rootURL;
56
+ }
57
+ const [, rootURL] = restLink;
58
+ return rootURL;
37
59
  }
38
60
  async function setupRest() {
39
- let nonce = '';
40
- let rootURL = '';
41
- // Poll until the REST API is discovered.
42
- // See https://github.com/WordPress/gutenberg/issues/61627
43
- await test_1.expect
44
- .poll(async () => {
45
- try {
46
- [nonce, rootURL] = await Promise.all([
47
- this.login(),
48
- getAPIRootURL(this.request),
49
- ]);
50
- }
51
- catch (error) {
52
- // Prints the error if the timeout is reached.
53
- return error;
54
- }
55
- return !!(nonce && rootURL);
56
- }, {
57
- message: 'Failed to setup REST API.',
58
- timeout: 60_000, // 1 minute.
59
- })
60
- .toBe(true);
61
- const { cookies } = await this.request.storageState();
62
- const storageState = {
63
- cookies,
64
- nonce,
65
- rootURL,
66
- };
67
- if (this.storageStatePath) {
68
- await fs.mkdir((0, path_1.dirname)(this.storageStatePath), { recursive: true });
69
- await fs.writeFile(this.storageStatePath, JSON.stringify(storageState), 'utf-8');
61
+ let nonce = "";
62
+ let rootURL = "";
63
+ await import_test.expect.poll(
64
+ async () => {
65
+ try {
66
+ [nonce, rootURL] = await Promise.all([
67
+ this.login(),
68
+ getAPIRootURL(this.request)
69
+ ]);
70
+ } catch (error) {
71
+ return error;
72
+ }
73
+ return !!(nonce && rootURL);
74
+ },
75
+ {
76
+ message: "Failed to setup REST API.",
77
+ timeout: 6e4
78
+ // 1 minute.
70
79
  }
71
- this.storageState = storageState;
72
- return storageState;
80
+ ).toBe(true);
81
+ const { cookies } = await this.request.storageState();
82
+ const storageState = {
83
+ cookies,
84
+ nonce,
85
+ rootURL
86
+ };
87
+ if (this.storageStatePath) {
88
+ await fs.mkdir((0, import_path.dirname)(this.storageStatePath), { recursive: true });
89
+ await fs.writeFile(
90
+ this.storageStatePath,
91
+ JSON.stringify(storageState),
92
+ "utf-8"
93
+ );
94
+ }
95
+ this.storageState = storageState;
96
+ return storageState;
73
97
  }
74
98
  async function rest(options) {
75
- const { path, ...fetchOptions } = options;
76
- if (!path) {
77
- throw new Error('"path" is required to make a REST call');
78
- }
79
- if (!this.storageState?.nonce || !this.storageState?.rootURL) {
80
- await this.setupRest();
81
- }
82
- const relativePath = path.startsWith('/') ? path.slice(1) : path;
83
- const url = this.storageState.rootURL + relativePath;
84
- try {
85
- const response = await this.request.fetch(url, {
86
- ...fetchOptions,
87
- failOnStatusCode: false,
88
- headers: {
89
- 'X-WP-Nonce': this.storageState.nonce,
90
- ...(fetchOptions.headers || {}),
91
- },
92
- });
93
- const json = await response.json();
94
- if (!response.ok()) {
95
- throw json;
96
- }
97
- return json;
99
+ const { path, ...fetchOptions } = options;
100
+ if (!path) {
101
+ throw new Error('"path" is required to make a REST call');
102
+ }
103
+ if (!this.storageState?.nonce || !this.storageState?.rootURL) {
104
+ await this.setupRest();
105
+ }
106
+ const relativePath = path.startsWith("/") ? path.slice(1) : path;
107
+ const url = this.storageState.rootURL + relativePath;
108
+ try {
109
+ const response = await this.request.fetch(url, {
110
+ ...fetchOptions,
111
+ failOnStatusCode: false,
112
+ headers: {
113
+ "X-WP-Nonce": this.storageState.nonce,
114
+ ...fetchOptions.headers || {}
115
+ }
116
+ });
117
+ const json = await response.json();
118
+ if (!response.ok()) {
119
+ throw json;
98
120
  }
99
- catch (error) {
100
- // Nonce in invalid, retry again with a renewed nonce.
101
- if (typeof error === 'object' &&
102
- error !== null &&
103
- Object.prototype.hasOwnProperty.call(error, 'code') &&
104
- error.code === 'rest_cookie_invalid_nonce') {
105
- await this.setupRest();
106
- return this.rest(options);
107
- }
108
- throw error;
121
+ return json;
122
+ } catch (error) {
123
+ if (typeof error === "object" && error !== null && Object.prototype.hasOwnProperty.call(error, "code") && error.code === "rest_cookie_invalid_nonce") {
124
+ await this.setupRest();
125
+ return this.rest(options);
109
126
  }
127
+ throw error;
128
+ }
110
129
  }
111
- /**
112
- * Get the maximum batch size for the REST API.
113
- *
114
- * @param this
115
- * @param forceRefetch Force revalidate the cached max batch size.
116
- */
117
130
  async function getMaxBatchSize(forceRefetch = false) {
118
- if (!forceRefetch && this.maxBatchSize) {
119
- return this.maxBatchSize;
120
- }
121
- const response = await this.rest({
122
- method: 'OPTIONS',
123
- path: '/batch/v1',
124
- });
125
- this.maxBatchSize = response.endpoints[0].args.requests.maxItems;
131
+ if (!forceRefetch && this.maxBatchSize) {
126
132
  return this.maxBatchSize;
133
+ }
134
+ const response = await this.rest({
135
+ method: "OPTIONS",
136
+ path: "/batch/v1"
137
+ });
138
+ this.maxBatchSize = response.endpoints[0].args.requests.maxItems;
139
+ return this.maxBatchSize;
127
140
  }
128
141
  async function batchRest(requests) {
129
- const maxBatchSize = await this.getMaxBatchSize();
130
- if (requests.length > maxBatchSize) {
131
- const chunks = splitRequestsToChunks(requests, maxBatchSize);
132
- const chunkResponses = await Promise.all(chunks.map((chunkRequests) => this.batchRest(chunkRequests)));
133
- return chunkResponses.flat();
134
- }
135
- const batchResponses = await this.rest({
136
- method: 'POST',
137
- path: '/batch/v1',
138
- data: {
139
- requests,
140
- validation: 'require-all-validate',
141
- },
142
- });
143
- if (batchResponses.failed) {
144
- throw batchResponses;
142
+ const maxBatchSize = await this.getMaxBatchSize();
143
+ if (requests.length > maxBatchSize) {
144
+ const chunks = splitRequestsToChunks(requests, maxBatchSize);
145
+ const chunkResponses = await Promise.all(
146
+ chunks.map(
147
+ (chunkRequests) => this.batchRest(chunkRequests)
148
+ )
149
+ );
150
+ return chunkResponses.flat();
151
+ }
152
+ const batchResponses = await this.rest({
153
+ method: "POST",
154
+ path: "/batch/v1",
155
+ data: {
156
+ requests,
157
+ validation: "require-all-validate"
145
158
  }
146
- return batchResponses.responses;
159
+ });
160
+ if (batchResponses.failed) {
161
+ throw batchResponses;
162
+ }
163
+ return batchResponses.responses;
147
164
  }
148
- //# sourceMappingURL=rest.js.map
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ batchRest,
168
+ getMaxBatchSize,
169
+ rest,
170
+ setupRest
171
+ });
172
+ //# sourceMappingURL=rest.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/request-utils/rest.ts"],"names":[],"mappings":";;AA6NS,8BAAS;AAAE,oBAAI;AAAE,0CAAe;AAAE,8BAAS;AA7NpD;;GAEG;AACH,kCAAk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AI,CAAC,IAAI,CAQ3B;QACJ,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,WAAW;KACjB,CAAE,CAAC;IACJ,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAE,CAAC,CAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IACnE,OAAO,IAAI,CAAC,YAAY,CAAC;AAC1B,CAAC;AASD,KAAK,UAAU,SAAS,CAEvB,QAAwB;IAExB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;IAElD,IAAK,QAAQ,CAAC,MAAM,GAAG,YAAY,EAAG,CAAC;QACtC,MAAM,MAAM,GAAG,qBAAqB,CAAE,QAAQ,EAAE,YAAY,CAAE,CAAC;QAE/D,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CACvC,MAAM,CAAC,GAAG,CAAE,CAAE,aAAa,EAAG,EAAE,CAC/B,IAAI,CAAC,SAAS,CAAmB,aAAa,CAAE,CAChD,CACD,CAAC;QAEF,OAAO,cAAc,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,IAAI,CAGjC;QACJ,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE;YACL,QAAQ;YACR,UAAU,EAAE,sBAAsB;SAClC;KACD,CAAE,CAAC;IAEJ,IAAK,cAAc,CAAC,MAAM,EAAG,CAAC;QAC7B,MAAM,cAAc,CAAC;IACtB,CAAC;IAED,OAAO,cAAc,CAAC,SAAS,CAAC;AACjC,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/rest.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport * as fs from 'fs/promises';\nimport { dirname } from 'path';\nimport { expect } from '@playwright/test';\nimport type { APIRequestContext } from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport { WP_BASE_URL } from '../config';\nimport type { RequestUtils, StorageState } from './index';\n\nfunction splitRequestsToChunks( requests: BatchRequest[], chunkSize: number ) {\n\tconst arr = [ ...requests ];\n\tconst cache = [];\n\twhile ( arr.length ) {\n\t\tcache.push( arr.splice( 0, chunkSize ) );\n\t}\n\n\treturn cache;\n}\n\nasync function getAPIRootURL( request: APIRequestContext ) {\n\t// Discover the API root url using link header.\n\t// See https://developer.wordpress.org/rest-api/using-the-rest-api/discovery/#link-header\n\tconst response = await request.head( WP_BASE_URL );\n\tconst links = response.headers().link;\n\tconst restLink = links?.match( /<([^>]+)>; rel=\"https:\\/\\/api\\.w\\.org\\/\"/ );\n\n\tif ( ! restLink ) {\n\t\tthrow new Error( `Failed to discover REST API endpoint.\n Link header: ${ links }` );\n\t}\n\n\tconst [ , rootURL ] = restLink;\n\n\treturn rootURL;\n}\n\nasync function setupRest( this: RequestUtils ): Promise< StorageState > {\n\tlet nonce = '';\n\tlet rootURL = '';\n\n\t// Poll until the REST API is discovered.\n\t// See https://github.com/WordPress/gutenberg/issues/61627\n\tawait expect\n\t\t.poll(\n\t\t\tasync () => {\n\t\t\t\ttry {\n\t\t\t\t\t[ nonce, rootURL ] = await Promise.all( [\n\t\t\t\t\t\tthis.login(),\n\t\t\t\t\t\tgetAPIRootURL( this.request ),\n\t\t\t\t\t] );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Prints the error if the timeout is reached.\n\t\t\t\t\treturn error;\n\t\t\t\t}\n\n\t\t\t\treturn !! ( nonce && rootURL );\n\t\t\t},\n\t\t\t{\n\t\t\t\tmessage: 'Failed to setup REST API.',\n\t\t\t\ttimeout: 60_000, // 1 minute.\n\t\t\t}\n\t\t)\n\t\t.toBe( true );\n\n\tconst { cookies } = await this.request.storageState();\n\n\tconst storageState: StorageState = {\n\t\tcookies,\n\t\tnonce,\n\t\trootURL,\n\t};\n\n\tif ( this.storageStatePath ) {\n\t\tawait fs.mkdir( dirname( this.storageStatePath ), { recursive: true } );\n\t\tawait fs.writeFile(\n\t\t\tthis.storageStatePath,\n\t\t\tJSON.stringify( storageState ),\n\t\t\t'utf-8'\n\t\t);\n\t}\n\n\tthis.storageState = storageState;\n\n\treturn storageState;\n}\n\ntype RequestFetchOptions = Exclude<\n\tParameters< APIRequestContext[ 'fetch' ] >[ 1 ],\n\tundefined\n>;\nexport interface RestOptions extends RequestFetchOptions {\n\tpath: string;\n}\n\nasync function rest< RestResponse = any >(\n\tthis: RequestUtils,\n\toptions: RestOptions\n): Promise< RestResponse > {\n\tconst { path, ...fetchOptions } = options;\n\n\tif ( ! path ) {\n\t\tthrow new Error( '\"path\" is required to make a REST call' );\n\t}\n\n\tif ( ! this.storageState?.nonce || ! this.storageState?.rootURL ) {\n\t\tawait this.setupRest();\n\t}\n\n\tconst relativePath = path.startsWith( '/' ) ? path.slice( 1 ) : path;\n\n\tconst url = this.storageState!.rootURL + relativePath;\n\n\ttry {\n\t\tconst response = await this.request.fetch( url, {\n\t\t\t...fetchOptions,\n\t\t\tfailOnStatusCode: false,\n\t\t\theaders: {\n\t\t\t\t'X-WP-Nonce': this.storageState!.nonce,\n\t\t\t\t...( fetchOptions.headers || {} ),\n\t\t\t},\n\t\t} );\n\t\tconst json: RestResponse = await response.json();\n\n\t\tif ( ! response.ok() ) {\n\t\t\tthrow json;\n\t\t}\n\n\t\treturn json;\n\t} catch ( error ) {\n\t\t// Nonce in invalid, retry again with a renewed nonce.\n\t\tif (\n\t\t\ttypeof error === 'object' &&\n\t\t\terror !== null &&\n\t\t\tObject.prototype.hasOwnProperty.call( error, 'code' ) &&\n\t\t\t( error as { code: string } ).code === 'rest_cookie_invalid_nonce'\n\t\t) {\n\t\t\tawait this.setupRest();\n\n\t\t\treturn this.rest( options );\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\n/**\n * Get the maximum batch size for the REST API.\n *\n * @param this\n * @param forceRefetch Force revalidate the cached max batch size.\n */\nasync function getMaxBatchSize( this: RequestUtils, forceRefetch = false ) {\n\tif ( ! forceRefetch && this.maxBatchSize ) {\n\t\treturn this.maxBatchSize;\n\t}\n\n\tconst response = await this.rest< {\n\t\tendpoints: {\n\t\t\targs: {\n\t\t\t\trequests: {\n\t\t\t\t\tmaxItems: number;\n\t\t\t\t};\n\t\t\t};\n\t\t}[];\n\t} >( {\n\t\tmethod: 'OPTIONS',\n\t\tpath: '/batch/v1',\n\t} );\n\tthis.maxBatchSize = response.endpoints[ 0 ].args.requests.maxItems;\n\treturn this.maxBatchSize;\n}\n\nexport interface BatchRequest {\n\tmethod?: string;\n\tpath: string;\n\theaders?: Record< string, string | string[] >;\n\tbody?: any;\n}\n\nasync function batchRest< BatchResponse >(\n\tthis: RequestUtils,\n\trequests: BatchRequest[]\n): Promise< BatchResponse[] > {\n\tconst maxBatchSize = await this.getMaxBatchSize();\n\n\tif ( requests.length > maxBatchSize ) {\n\t\tconst chunks = splitRequestsToChunks( requests, maxBatchSize );\n\n\t\tconst chunkResponses = await Promise.all(\n\t\t\tchunks.map( ( chunkRequests ) =>\n\t\t\t\tthis.batchRest< BatchResponse >( chunkRequests )\n\t\t\t)\n\t\t);\n\n\t\treturn chunkResponses.flat();\n\t}\n\n\tconst batchResponses = await this.rest< {\n\t\tfailed?: string;\n\t\tresponses: BatchResponse[];\n\t} >( {\n\t\tmethod: 'POST',\n\t\tpath: '/batch/v1',\n\t\tdata: {\n\t\t\trequests,\n\t\t\tvalidation: 'require-all-validate',\n\t\t},\n\t} );\n\n\tif ( batchResponses.failed ) {\n\t\tthrow batchResponses;\n\t}\n\n\treturn batchResponses.responses;\n}\n\nexport { setupRest, rest, getMaxBatchSize, batchRest };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,SAAoB;AACpB,kBAAwB;AACxB,kBAAuB;AAMvB,oBAA4B;AAG5B,SAAS,sBAAuB,UAA0B,WAAoB;AAC7E,QAAM,MAAM,CAAE,GAAG,QAAS;AAC1B,QAAM,QAAQ,CA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,MAAM,QAAQ;AAAA,MACpC,OAAO;AAAA,QAAK,CAAE,kBACb,KAAK,UAA4B,aAAc;AAAA,MAChD;AAAA,IACD;AAEA,WAAO,eAAe,KAAK;AAAA,EAC5B;AAEA,QAAM,iBAAiB,MAAM,KAAK,KAG7B;AAAA,IACJ,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,MACL;AAAA,MACA,YAAY;AAAA,IACb;AAAA,EACD,CAAE;AAEF,MAAK,eAAe,QAAS;AAC5B,UAAM;AAAA,EACP;AAEA,SAAO,eAAe;AACvB;",
6
+ "names": []
7
+ }
@@ -1,33 +1,43 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSiteSettings = getSiteSettings;
4
- exports.updateSiteSettings = updateSiteSettings;
5
- /**
6
- * Get the site settings.
7
- *
8
- * @see https://developer.wordpress.org/rest-api/reference/settings/#retrieve-a-site-setting
9
- *
10
- * @param this RequestUtils.
11
- */
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 site_settings_exports = {};
20
+ __export(site_settings_exports, {
21
+ getSiteSettings: () => getSiteSettings,
22
+ updateSiteSettings: () => updateSiteSettings
23
+ });
24
+ module.exports = __toCommonJS(site_settings_exports);
12
25
  async function getSiteSettings() {
13
- return await this.rest({
14
- path: '/wp/v2/settings',
15
- method: 'GET',
16
- });
26
+ return await this.rest({
27
+ path: "/wp/v2/settings",
28
+ method: "GET"
29
+ });
17
30
  }
18
- /**
19
- * Update the site settings.
20
- *
21
- * @see https://developer.wordpress.org/rest-api/reference/settings/#update-a-site-setting
22
- *
23
- * @param this RequestUtils.
24
- * @param siteSettings The partial settings payload to update.
25
- */
26
31
  async function updateSiteSettings(siteSettings) {
27
- return await this.rest({
28
- path: '/wp/v2/settings',
29
- method: 'POST',
30
- data: siteSettings,
31
- });
32
+ return await this.rest({
33
+ path: "/wp/v2/settings",
34
+ method: "POST",
35
+ data: siteSettings
36
+ });
32
37
  }
33
- //# sourceMappingURL=site-settings.js.map
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ getSiteSettings,
41
+ updateSiteSettings
42
+ });
43
+ //# sourceMappingURL=site-settings.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"site-settings.js","sourceRoot":"","sources":["../../src/request-utils/site-settings.ts"],"names":[],"mappings":";;AAiCA,0CAKC;AAUD,gDASC;AA/BD;;;;;;GAMG;AACI,KAAK,UAAU,eAAe;IACpC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAkB;QACvC,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,KAAK;KACb,CAAE,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAEvC,YAAqC;IAErC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAkB;QACvC,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,YAAY;KAClB,CAAE,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/site-settings.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\ntype SiteSettings = {\n\ttitle: string;\n\tdescription: string;\n\turl: string;\n\temail: string;\n\ttimezone: string;\n\tdate_format: string;\n\ttime_format: string;\n\tstart_of_week: number;\n\tlanguage: string;\n\tuse_smilies: boolean;\n\tdefault_category: number;\n\tdefault_post_format: string;\n\tposts_per_page: number;\n\tdefault_ping_status: 'open' | 'closed';\n\tdefault_comment_status: 'open' | 'closed';\n\tshow_on_front: 'posts' | 'page';\n\tpage_on_front: number;\n\tpage_for_posts: number;\n};\n\n/**\n * Get the site settings.\n *\n * @see https://developer.wordpress.org/rest-api/reference/settings/#retrieve-a-site-setting\n *\n * @param this RequestUtils.\n */\nexport async function getSiteSettings( this: RequestUtils ) {\n\treturn await this.rest< SiteSettings >( {\n\t\tpath: '/wp/v2/settings',\n\t\tmethod: 'GET',\n\t} );\n}\n\n/**\n * Update the site settings.\n *\n * @see https://developer.wordpress.org/rest-api/reference/settings/#update-a-site-setting\n *\n * @param this RequestUtils.\n * @param siteSettings The partial settings payload to update.\n */\nexport async function updateSiteSettings(\n\tthis: RequestUtils,\n\tsiteSettings: Partial< SiteSettings >\n) {\n\treturn await this.rest< SiteSettings >( {\n\t\tpath: '/wp/v2/settings',\n\t\tmethod: 'POST',\n\t\tdata: siteSettings,\n\t} );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA,eAAsB,kBAAsC;AAC3D,SAAO,MAAM,KAAK,KAAsB;AAAA,IACvC,MAAM;AAAA,IACN,QAAQ;AAAA,EACT,CAAE;AACH;AAUA,eAAsB,mBAErB,cACC;AACD,SAAO,MAAM,KAAK,KAAsB;AAAA,IACvC,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CAAE;AACH;",
6
+ "names": []
7
+ }