@wordpress/e2e-test-utils-playwright 1.32.0 → 1.32.1-next.47f435fc9.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.
- package/build/admin/create-new-post.js +46 -28
- package/build/admin/create-new-post.js.map +7 -1
- package/build/admin/edit-post.js +35 -17
- package/build/admin/edit-post.js.map +7 -1
- package/build/admin/get-page-error.js +30 -22
- package/build/admin/get-page-error.js.map +7 -1
- package/build/admin/index.js +54 -34
- package/build/admin/index.js.map +7 -1
- package/build/admin/visit-admin-page.js +42 -29
- package/build/admin/visit-admin-page.js.map +7 -1
- package/build/admin/visit-site-editor.js +71 -64
- package/build/admin/visit-site-editor.js.map +7 -1
- package/build/config.js +40 -10
- package/build/config.js.map +7 -1
- package/build/editor/click-block-options-menu-item.js +29 -14
- package/build/editor/click-block-options-menu-item.js.map +7 -1
- package/build/editor/click-block-toolbar-button.js +33 -13
- package/build/editor/click-block-toolbar-button.js.map +7 -1
- package/build/editor/get-blocks.js +59 -43
- package/build/editor/get-blocks.js.map +7 -1
- package/build/editor/get-edited-post-content.js +31 -12
- package/build/editor/get-edited-post-content.js.map +7 -1
- package/build/editor/index.js +92 -72
- package/build/editor/index.js.map +7 -1
- package/build/editor/insert-block.js +50 -21
- package/build/editor/insert-block.js.map +7 -1
- package/build/editor/open-document-settings-sidebar.js +37 -24
- package/build/editor/open-document-settings-sidebar.js.map +7 -1
- package/build/editor/preview.js +37 -18
- package/build/editor/preview.js.map +7 -1
- package/build/editor/publish-post.js +42 -42
- package/build/editor/publish-post.js.map +7 -1
- package/build/editor/save-draft.js +29 -15
- package/build/editor/save-draft.js.map +7 -1
- package/build/editor/select-blocks.js +46 -25
- package/build/editor/select-blocks.js.map +7 -1
- package/build/editor/set-content.js +34 -14
- package/build/editor/set-content.js.map +7 -1
- package/build/editor/set-is-fixed-toolbar.js +31 -15
- package/build/editor/set-is-fixed-toolbar.js.map +7 -1
- package/build/editor/set-preferences.js +38 -18
- package/build/editor/set-preferences.js.map +7 -1
- package/build/editor/show-block-toolbar.js +30 -16
- package/build/editor/show-block-toolbar.js.map +7 -1
- package/build/editor/site-editor.js +46 -41
- package/build/editor/site-editor.js.map +7 -1
- package/build/editor/switch-editor-tool.js +42 -30
- package/build/editor/switch-editor-tool.js.map +7 -1
- package/build/editor/switch-to-legacy-canvas.js +33 -14
- package/build/editor/switch-to-legacy-canvas.js.map +7 -1
- package/build/editor/transform-block-to.js +41 -21
- package/build/editor/transform-block-to.js.map +7 -1
- package/build/index.js +50 -32
- package/build/index.js.map +7 -1
- package/build/lighthouse/index.js +89 -53
- package/build/lighthouse/index.js.map +7 -1
- package/build/metrics/index.js +298 -249
- package/build/metrics/index.js.map +7 -1
- package/build/page-utils/drag-files.js +134 -112
- package/build/page-utils/drag-files.js.map +7 -1
- package/build/page-utils/emulate-network-conditions.js +92 -66
- package/build/page-utils/emulate-network-conditions.js.map +7 -1
- package/build/page-utils/index.js +54 -34
- package/build/page-utils/index.js.map +7 -1
- package/build/page-utils/is-current-url.js +31 -18
- package/build/page-utils/is-current-url.js.map +7 -1
- package/build/page-utils/keycodes.js +51 -39
- package/build/page-utils/keycodes.js.map +7 -1
- package/build/page-utils/press-keys.js +148 -127
- package/build/page-utils/press-keys.js.map +7 -1
- package/build/page-utils/set-browser-viewport.js +32 -41
- package/build/page-utils/set-browser-viewport.js.map +7 -1
- package/build/request-utils/blocks.js +49 -40
- package/build/request-utils/blocks.js.map +7 -1
- package/build/request-utils/comments.js +57 -45
- package/build/request-utils/comments.js.map +7 -1
- package/build/request-utils/gutenberg-experiments.js +48 -26
- package/build/request-utils/gutenberg-experiments.js.map +7 -1
- package/build/request-utils/index.js +187 -153
- package/build/request-utils/index.js.map +7 -1
- package/build/request-utils/login.js +43 -18
- package/build/request-utils/login.js.map +7 -1
- package/build/request-utils/media.js +72 -64
- package/build/request-utils/media.js.map +7 -1
- package/build/request-utils/menus.js +119 -109
- package/build/request-utils/menus.js.map +7 -1
- package/build/request-utils/pages.js +60 -49
- package/build/request-utils/pages.js.map +7 -1
- package/build/request-utils/patterns.js +39 -24
- package/build/request-utils/patterns.js.map +7 -1
- package/build/request-utils/plugins.js +68 -74
- package/build/request-utils/plugins.js.map +7 -1
- package/build/request-utils/posts.js +52 -39
- package/build/request-utils/posts.js.map +7 -1
- package/build/request-utils/preferences.js +36 -17
- package/build/request-utils/preferences.js.map +7 -1
- package/build/request-utils/rest.js +153 -129
- package/build/request-utils/rest.js.map +7 -1
- package/build/request-utils/site-settings.js +38 -28
- package/build/request-utils/site-settings.js.map +7 -1
- package/build/request-utils/templates.js +57 -45
- package/build/request-utils/templates.js.map +7 -1
- package/build/request-utils/themes.js +78 -53
- package/build/request-utils/themes.js.map +7 -1
- package/build/request-utils/users.js +72 -72
- package/build/request-utils/users.js.map +7 -1
- package/build/request-utils/widgets.js +71 -55
- package/build/request-utils/widgets.js.map +7 -1
- package/build/test.js +128 -146
- package/build/test.js.map +7 -1
- package/build/types.js +16 -2
- package/build/types.js.map +7 -1
- package/package.json +6 -2
|
@@ -1,54 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
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 templates_exports = {};
|
|
20
|
+
__export(templates_exports, {
|
|
21
|
+
createTemplate: () => createTemplate,
|
|
22
|
+
deleteAllTemplates: () => deleteAllTemplates
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(templates_exports);
|
|
5
25
|
const PATH_MAPPING = {
|
|
6
|
-
|
|
7
|
-
|
|
26
|
+
wp_template: "/wp/v2/templates",
|
|
27
|
+
wp_template_part: "/wp/v2/template-parts"
|
|
8
28
|
};
|
|
9
|
-
/**
|
|
10
|
-
* Delete all the templates of given type.
|
|
11
|
-
*
|
|
12
|
-
* @param this
|
|
13
|
-
* @param type - Template type to delete.
|
|
14
|
-
*/
|
|
15
29
|
async function deleteAllTemplates(type) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
30
|
+
const path = PATH_MAPPING[type];
|
|
31
|
+
if (!path) {
|
|
32
|
+
throw new Error(`Unsupported template type: ${type}.`);
|
|
33
|
+
}
|
|
34
|
+
const templates = await this.rest({ path });
|
|
35
|
+
for (const template of templates) {
|
|
36
|
+
if (!template?.id || !template?.wp_id) {
|
|
37
|
+
continue;
|
|
19
38
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (responseError) {
|
|
33
|
-
// Disable reason - the error provides valuable feedback about issues with tests.
|
|
34
|
-
// eslint-disable-next-line no-console
|
|
35
|
-
console.warn(`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`, responseError);
|
|
36
|
-
}
|
|
39
|
+
try {
|
|
40
|
+
await this.rest({
|
|
41
|
+
method: "DELETE",
|
|
42
|
+
path: `${path}/${template.id}`,
|
|
43
|
+
params: { force: true }
|
|
44
|
+
});
|
|
45
|
+
} catch (responseError) {
|
|
46
|
+
console.warn(
|
|
47
|
+
`deleteAllTemplates failed to delete template (id: ${template.wp_id}) with the following error`,
|
|
48
|
+
responseError
|
|
49
|
+
);
|
|
37
50
|
}
|
|
51
|
+
}
|
|
38
52
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Creates a new template using the REST API.
|
|
41
|
-
*
|
|
42
|
-
* @param this
|
|
43
|
-
* @param type Template type to delete.
|
|
44
|
-
* @param payload Template attributes.
|
|
45
|
-
*/
|
|
46
53
|
async function createTemplate(type, payload) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
const template = await this.rest({
|
|
55
|
+
method: "POST",
|
|
56
|
+
path: PATH_MAPPING[type],
|
|
57
|
+
params: { ...payload, type, status: "publish", is_wp_suggestion: true }
|
|
58
|
+
});
|
|
59
|
+
return template;
|
|
53
60
|
}
|
|
54
|
-
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
createTemplate,
|
|
64
|
+
deleteAllTemplates
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/request-utils/templates.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\ntype TemplateType = 'wp_template' | 'wp_template_part';\n\ninterface Template {\n\twp_id: number;\n\tid: string;\n}\n\ninterface CreateTemplatePayload {\n\tslug: string;\n\ttitle?: string;\n\tcontent?: string;\n\tdescription?: string;\n}\n\nconst PATH_MAPPING = {\n\twp_template: '/wp/v2/templates',\n\twp_template_part: '/wp/v2/template-parts',\n};\n\n/**\n * Delete all the templates of given type.\n *\n * @param this\n * @param type - Template type to delete.\n */\nasync function deleteAllTemplates( this: RequestUtils, type: TemplateType ) {\n\tconst path = PATH_MAPPING[ type ];\n\n\tif ( ! path ) {\n\t\tthrow new Error( `Unsupported template type: ${ type }.` );\n\t}\n\n\tconst templates = await this.rest< Template[] >( { path } );\n\n\tfor ( const template of templates ) {\n\t\tif ( ! template?.id || ! template?.wp_id ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.rest( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\tpath: `${ path }/${ template.id }`,\n\t\t\t\tparams: { force: true },\n\t\t\t} );\n\t\t} catch ( responseError ) {\n\t\t\t// Disable reason - the error provides valuable feedback about issues with tests.\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following error`,\n\t\t\t\tresponseError\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Creates a new template using the REST API.\n *\n * @param this\n * @param type Template type to delete.\n * @param payload Template attributes.\n */\nasync function createTemplate(\n\tthis: RequestUtils,\n\ttype: TemplateType,\n\tpayload: CreateTemplatePayload\n) {\n\tconst template = await this.rest< Template >( {\n\t\tmethod: 'POST',\n\t\tpath: PATH_MAPPING[ type ],\n\t\tparams: { ...payload, type, status: 'publish', is_wp_suggestion: true },\n\t} );\n\n\treturn template;\n}\n\nexport { deleteAllTemplates, createTemplate };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBA,MAAM,eAAe;AAAA,EACpB,aAAa;AAAA,EACb,kBAAkB;AACnB;AAQA,eAAe,mBAAwC,MAAqB;AAC3E,QAAM,OAAO,aAAc,IAAK;AAEhC,MAAK,CAAE,MAAO;AACb,UAAM,IAAI,MAAO,8BAA+B,IAAK,GAAI;AAAA,EAC1D;AAEA,QAAM,YAAY,MAAM,KAAK,KAAoB,EAAE,KAAK,CAAE;AAE1D,aAAY,YAAY,WAAY;AACnC,QAAK,CAAE,UAAU,MAAM,CAAE,UAAU,OAAQ;AAC1C;AAAA,IACD;AAEA,QAAI;AACH,YAAM,KAAK,KAAM;AAAA,QAChB,QAAQ;AAAA,QACR,MAAM,GAAI,IAAK,IAAK,SAAS,EAAG;AAAA,QAChC,QAAQ,EAAE,OAAO,KAAK;AAAA,MACvB,CAAE;AAAA,IACH,SAAU,eAAgB;AAGzB,cAAQ;AAAA,QACP,qDAAsD,SAAS,KAAM;AAAA,QACrE;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AASA,eAAe,eAEd,MACA,SACC;AACD,QAAM,WAAW,MAAM,KAAK,KAAkB;AAAA,IAC7C,QAAQ;AAAA,IACR,MAAM,aAAc,IAAK;AAAA,IACzB,QAAQ,EAAE,GAAG,SAAS,MAAM,QAAQ,WAAW,kBAAkB,KAAK;AAAA,EACvE,CAAE;AAEF,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,62 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 themes_exports = {};
|
|
20
|
+
__export(themes_exports, {
|
|
21
|
+
activateTheme: () => activateTheme,
|
|
22
|
+
getCurrentThemeGlobalStylesPostId: () => getCurrentThemeGlobalStylesPostId,
|
|
23
|
+
getThemeGlobalStylesRevisions: () => getThemeGlobalStylesRevisions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(themes_exports);
|
|
26
|
+
var import_config = require("../config");
|
|
27
|
+
const THEMES_URL = new URL("wp-admin/themes.php", import_config.WP_BASE_URL).href;
|
|
8
28
|
async function activateTheme(themeSlug) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
let response = await this.request.get(THEMES_URL);
|
|
30
|
+
const html = await response.text();
|
|
31
|
+
const optionalFolder = "([a-z0-9-]+%2F)?";
|
|
32
|
+
let matchGroup = html.match(
|
|
33
|
+
`action=activate&stylesheet=${encodeURIComponent(
|
|
34
|
+
themeSlug
|
|
35
|
+
)}&_wpnonce=[a-z0-9]+`
|
|
36
|
+
);
|
|
37
|
+
if (!matchGroup) {
|
|
38
|
+
matchGroup = html.match(
|
|
39
|
+
`action=activate&stylesheet=${optionalFolder}${encodeURIComponent(
|
|
40
|
+
themeSlug
|
|
41
|
+
)}&_wpnonce=[a-z0-9]+`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (!matchGroup) {
|
|
45
|
+
if (html.includes(`data-slug="${themeSlug}"`)) {
|
|
46
|
+
return;
|
|
19
47
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
const [activateQuery] = matchGroup;
|
|
28
|
-
const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, '&');
|
|
29
|
-
response = await this.request.get(activateLink);
|
|
30
|
-
await response.dispose();
|
|
48
|
+
throw new Error(`The theme "${themeSlug}" is not installed`);
|
|
49
|
+
}
|
|
50
|
+
const [activateQuery] = matchGroup;
|
|
51
|
+
const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, "&");
|
|
52
|
+
response = await this.request.get(activateLink);
|
|
53
|
+
await response.dispose();
|
|
31
54
|
}
|
|
32
|
-
// https://developer.wordpress.org/rest-api/reference/themes/#definition
|
|
33
55
|
async function getCurrentThemeGlobalStylesPostId() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
const themes = await this.rest({
|
|
57
|
+
path: "/wp/v2/themes"
|
|
58
|
+
});
|
|
59
|
+
let themeGlobalStylesId = "";
|
|
60
|
+
if (themes && themes.length) {
|
|
61
|
+
const currentTheme = themes.find(
|
|
62
|
+
({ status }) => status === "active"
|
|
63
|
+
);
|
|
64
|
+
const globalStylesURL = currentTheme?._links?.["wp:user-global-styles"]?.[0]?.href;
|
|
65
|
+
if (globalStylesURL) {
|
|
66
|
+
themeGlobalStylesId = globalStylesURL?.split(
|
|
67
|
+
"rest_route=/wp/v2/global-styles/"
|
|
68
|
+
)[1];
|
|
44
69
|
}
|
|
45
|
-
|
|
70
|
+
}
|
|
71
|
+
return themeGlobalStylesId;
|
|
46
72
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Deletes all post revisions using the REST API.
|
|
49
|
-
*
|
|
50
|
-
* @param {} this RequestUtils.
|
|
51
|
-
* @param {string|number} parentId Post attributes.
|
|
52
|
-
*/
|
|
53
73
|
async function getThemeGlobalStylesRevisions(parentId) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
74
|
+
return await this.rest({
|
|
75
|
+
path: `/wp/v2/global-styles/${parentId}/revisions`,
|
|
76
|
+
params: {
|
|
77
|
+
per_page: 100
|
|
78
|
+
}
|
|
79
|
+
});
|
|
61
80
|
}
|
|
62
|
-
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
activateTheme,
|
|
84
|
+
getCurrentThemeGlobalStylesPostId,
|
|
85
|
+
getThemeGlobalStylesRevisions
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=themes.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/request-utils/themes.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\nimport { WP_BASE_URL } from '../config';\n\nconst THEMES_URL = new URL( 'wp-admin/themes.php', WP_BASE_URL ).href;\n\nasync function activateTheme(\n\tthis: RequestUtils,\n\tthemeSlug: string\n): Promise< void > {\n\tlet response = await this.request.get( THEMES_URL );\n\tconst html = await response.text();\n\tconst optionalFolder = '([a-z0-9-]+%2F)?';\n\n\t// The `optionalFolder` regex part matches paths with a folder,\n\t// so it will return the first match, which might contain a folder.\n\t// First try to honor the included theme slug, that is, without a folder.\n\tlet matchGroup = html.match(\n\t\t`action=activate&stylesheet=${ encodeURIComponent(\n\t\t\tthemeSlug\n\t\t) }&_wpnonce=[a-z0-9]+`\n\t);\n\n\t// If the theme is not found, try to match the theme slug with a folder.\n\tif ( ! matchGroup ) {\n\t\tmatchGroup = html.match(\n\t\t\t`action=activate&stylesheet=${ optionalFolder }${ encodeURIComponent(\n\t\t\t\tthemeSlug\n\t\t\t) }&_wpnonce=[a-z0-9]+`\n\t\t);\n\t}\n\n\tif ( ! matchGroup ) {\n\t\tif ( html.includes( `data-slug=\"${ themeSlug }\"` ) ) {\n\t\t\t// The theme is already activated.\n\t\t\treturn;\n\t\t}\n\n\t\tthrow new Error( `The theme \"${ themeSlug }\" is not installed` );\n\t}\n\n\tconst [ activateQuery ] = matchGroup;\n\tconst activateLink =\n\t\tTHEMES_URL + `?${ activateQuery }`.replace( /&/g, '&' );\n\n\tresponse = await this.request.get( activateLink );\n\n\tawait response.dispose();\n}\n\n// https://developer.wordpress.org/rest-api/reference/themes/#definition\nasync function getCurrentThemeGlobalStylesPostId( this: RequestUtils ) {\n\ttype ThemeItem = {\n\t\tstylesheet: string;\n\t\tstatus: string;\n\t\t_links: { 'wp:user-global-styles': { href: string }[] };\n\t};\n\tconst themes = await this.rest< ThemeItem[] >( {\n\t\tpath: '/wp/v2/themes',\n\t} );\n\tlet themeGlobalStylesId: string = '';\n\tif ( themes && themes.length ) {\n\t\tconst currentTheme: ThemeItem | undefined = themes.find(\n\t\t\t( { status } ) => status === 'active'\n\t\t);\n\n\t\tconst globalStylesURL =\n\t\t\tcurrentTheme?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]?.href;\n\t\tif ( globalStylesURL ) {\n\t\t\tthemeGlobalStylesId = globalStylesURL?.split(\n\t\t\t\t'rest_route=/wp/v2/global-styles/'\n\t\t\t)[ 1 ];\n\t\t}\n\t}\n\treturn themeGlobalStylesId;\n}\n\n/**\n * Deletes all post revisions using the REST API.\n *\n * @param {} this RequestUtils.\n * @param {string|number} parentId Post attributes.\n */\nasync function getThemeGlobalStylesRevisions(\n\tthis: RequestUtils,\n\tparentId: number | string\n) {\n\t// Lists all global styles revisions.\n\treturn await this.rest< Record< string, Object >[] >( {\n\t\tpath: `/wp/v2/global-styles/${ parentId }/revisions`,\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n}\n\nexport {\n\tactivateTheme,\n\tgetCurrentThemeGlobalStylesPostId,\n\tgetThemeGlobalStylesRevisions,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;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ACrD,MAAM,wBAAyB,QAAS;AAAA,IACxC,QAAQ;AAAA,MACP,UAAU;AAAA,IACX;AAAA,EACD,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,81 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 users_exports = {};
|
|
20
|
+
__export(users_exports, {
|
|
21
|
+
createUser: () => createUser,
|
|
22
|
+
deleteAllUsers: () => deleteAllUsers
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(users_exports);
|
|
11
25
|
async function listUsers() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
const response = await this.rest({
|
|
27
|
+
method: "GET",
|
|
28
|
+
path: "/wp/v2/users",
|
|
29
|
+
params: {
|
|
30
|
+
per_page: 100
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return response;
|
|
20
34
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Add a test user.
|
|
23
|
-
*
|
|
24
|
-
* @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user
|
|
25
|
-
* @param this
|
|
26
|
-
* @param user User data to create.
|
|
27
|
-
*/
|
|
28
35
|
async function createUser(user) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
const userData = {
|
|
37
|
+
username: user.username,
|
|
38
|
+
email: user.email
|
|
39
|
+
};
|
|
40
|
+
if (user.firstName) {
|
|
41
|
+
userData.first_name = user.firstName;
|
|
42
|
+
}
|
|
43
|
+
if (user.lastName) {
|
|
44
|
+
userData.last_name = user.lastName;
|
|
45
|
+
}
|
|
46
|
+
if (user.password) {
|
|
47
|
+
userData.password = user.password;
|
|
48
|
+
}
|
|
49
|
+
if (user.roles) {
|
|
50
|
+
userData.roles = user.roles;
|
|
51
|
+
}
|
|
52
|
+
const response = await this.rest({
|
|
53
|
+
method: "POST",
|
|
54
|
+
path: "/wp/v2/users",
|
|
55
|
+
data: userData
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
51
58
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Delete a user.
|
|
54
|
-
*
|
|
55
|
-
* @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user
|
|
56
|
-
* @param this
|
|
57
|
-
* @param userId The ID of the user.
|
|
58
|
-
*/
|
|
59
59
|
async function deleteUser(userId) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const response = await this.rest({
|
|
61
|
+
method: "DELETE",
|
|
62
|
+
path: `/wp/v2/users/${userId}`,
|
|
63
|
+
params: { force: true, reassign: 1 }
|
|
64
|
+
});
|
|
65
|
+
return response;
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Delete all users except main root user.
|
|
69
|
-
*
|
|
70
|
-
* @param this
|
|
71
|
-
*/
|
|
72
67
|
async function deleteAllUsers() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
const users = await listUsers.bind(this)();
|
|
69
|
+
const responses = await Promise.all(
|
|
70
|
+
users.filter(
|
|
71
|
+
(user) => user.id !== 1 && user.name !== this.user.username
|
|
72
|
+
).map((user) => deleteUser.bind(this)(user.id))
|
|
73
|
+
);
|
|
74
|
+
return responses;
|
|
80
75
|
}
|
|
81
|
-
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
createUser,
|
|
79
|
+
deleteAllUsers
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/request-utils/users.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\nexport interface User {\n\tid: number;\n\tname: string;\n\temail: string;\n}\n\nexport interface UserData {\n\tusername: string;\n\temail: string;\n\tfirstName?: string;\n\tlastName?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\nexport interface UserRequestData {\n\tusername: string;\n\temail: string;\n\tfirst_name?: string;\n\tlast_name?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\n/**\n * List all users.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#list-users\n * @param this\n */\nasync function listUsers( this: RequestUtils ) {\n\tconst response = await this.rest< User[] >( {\n\t\tmethod: 'GET',\n\t\tpath: '/wp/v2/users',\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n\n\treturn response;\n}\n\n/**\n * Add a test user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user\n * @param this\n * @param user User data to create.\n */\nasync function createUser( this: RequestUtils, user: UserData ) {\n\tconst userData: UserRequestData = {\n\t\tusername: user.username,\n\t\temail: user.email,\n\t};\n\n\tif ( user.firstName ) {\n\t\tuserData.first_name = user.firstName;\n\t}\n\n\tif ( user.lastName ) {\n\t\tuserData.last_name = user.lastName;\n\t}\n\n\tif ( user.password ) {\n\t\tuserData.password = user.password;\n\t}\n\n\tif ( user.roles ) {\n\t\tuserData.roles = user.roles;\n\t}\n\n\tconst response = await this.rest< User >( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/users',\n\t\tdata: userData,\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete a user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user\n * @param this\n * @param userId The ID of the user.\n */\nasync function deleteUser( this: RequestUtils, userId: number ) {\n\tconst response = await this.rest( {\n\t\tmethod: 'DELETE',\n\t\tpath: `/wp/v2/users/${ userId }`,\n\t\tparams: { force: true, reassign: 1 },\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete all users except main root user.\n *\n * @param this\n */\nasync function deleteAllUsers( this: RequestUtils ) {\n\tconst users = await listUsers.bind( this )();\n\n\t// The users endpoint doesn't support batch request yet.\n\tconst responses = await Promise.all(\n\t\tusers\n\t\t\t// Do not delete neither root user nor the current user.\n\t\t\t.filter(\n\t\t\t\t( user: User ) =>\n\t\t\t\t\tuser.id !== 1 && user.name !== this.user.username\n\t\t\t)\n\t\t\t.map( ( user: User ) => deleteUser.bind( this )( user.id ) )\n\t);\n\n\treturn responses;\n}\n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EA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,61 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 widgets_exports = {};
|
|
20
|
+
__export(widgets_exports, {
|
|
21
|
+
addWidgetBlock: () => addWidgetBlock,
|
|
22
|
+
deleteAllWidgets: () => deleteAllWidgets
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(widgets_exports);
|
|
10
25
|
async function deleteAllWidgets() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const [widgets, sidebars] = await Promise.all([
|
|
27
|
+
this.rest({ path: "/wp/v2/widgets" }),
|
|
28
|
+
this.rest({ path: "/wp/v2/sidebars" })
|
|
29
|
+
]);
|
|
30
|
+
await this.batchRest(
|
|
31
|
+
widgets.map((widget) => ({
|
|
32
|
+
method: "DELETE",
|
|
33
|
+
path: `/wp/v2/widgets/${widget.id}?force=true`
|
|
34
|
+
}))
|
|
35
|
+
);
|
|
36
|
+
await Promise.all(
|
|
37
|
+
sidebars.map(
|
|
38
|
+
(sidebar) => this.rest({
|
|
39
|
+
method: "POST",
|
|
22
40
|
path: `/wp/v2/sidebars/${sidebar.id}`,
|
|
23
|
-
data: { id: sidebar.id, widgets: [] }
|
|
24
|
-
|
|
41
|
+
data: { id: sidebar.id, widgets: [] }
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
);
|
|
25
45
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Add a widget block to the widget area.
|
|
28
|
-
*
|
|
29
|
-
* @this {import('./index').RequestUtils}
|
|
30
|
-
* @param {string} serializedBlock The serialized content of the inserted block HTML.
|
|
31
|
-
* @param {string} widgetAreaId The ID of the widget area.
|
|
32
|
-
*/
|
|
33
46
|
async function addWidgetBlock(serializedBlock, widgetAreaId) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
});
|
|
47
|
+
const { id: blockId } = await this.rest({
|
|
48
|
+
method: "POST",
|
|
49
|
+
path: "/wp/v2/widgets",
|
|
50
|
+
data: {
|
|
51
|
+
id_base: "block",
|
|
52
|
+
sidebar: widgetAreaId,
|
|
53
|
+
instance: {
|
|
54
|
+
raw: { content: serializedBlock }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const { widgets } = await this.rest({
|
|
59
|
+
path: `/wp/v2/sidebars/${widgetAreaId}`
|
|
60
|
+
});
|
|
61
|
+
const updatedWidgets = new Set(widgets);
|
|
62
|
+
updatedWidgets.delete(blockId);
|
|
63
|
+
updatedWidgets.add(blockId);
|
|
64
|
+
await this.rest({
|
|
65
|
+
method: "PUT",
|
|
66
|
+
path: `/wp/v2/sidebars/${widgetAreaId}`,
|
|
67
|
+
data: {
|
|
68
|
+
widgets: [...updatedWidgets]
|
|
69
|
+
}
|
|
70
|
+
});
|
|
60
71
|
}
|
|
61
|
-
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
addWidgetBlock,
|
|
75
|
+
deleteAllWidgets
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=widgets.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/request-utils/widgets.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Delete all the widgets in the widgets screen.\n *\n * @this {import('./index').RequestUtils}\n */\nexport async function deleteAllWidgets() {\n\tconst [ widgets, sidebars ] = await Promise.all( [\n\t\tthis.rest( { path: '/wp/v2/widgets' } ),\n\t\tthis.rest( { path: '/wp/v2/sidebars' } ),\n\t] );\n\n\tawait this.batchRest(\n\t\twidgets.map( ( widget ) => ( {\n\t\t\tmethod: 'DELETE',\n\t\t\tpath: `/wp/v2/widgets/${ widget.id }?force=true`,\n\t\t} ) )\n\t);\n\n\t// The endpoint doesn't support batch requests yet.\n\tawait Promise.all(\n\t\tsidebars.map( ( sidebar ) =>\n\t\t\tthis.rest( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: `/wp/v2/sidebars/${ sidebar.id }`,\n\t\t\t\tdata: { id: sidebar.id, widgets: [] },\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Add a widget block to the widget area.\n *\n * @this {import('./index').RequestUtils}\n * @param {string} serializedBlock The serialized content of the inserted block HTML.\n * @param {string} widgetAreaId The ID of the widget area.\n */\nexport async function addWidgetBlock( serializedBlock, widgetAreaId ) {\n\tconst { id: blockId } = await this.rest( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/widgets',\n\t\tdata: {\n\t\t\tid_base: 'block',\n\t\t\tsidebar: widgetAreaId,\n\t\t\tinstance: {\n\t\t\t\traw: { content: serializedBlock },\n\t\t\t},\n\t\t},\n\t} );\n\n\tconst { widgets } = await this.rest( {\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId }`,\n\t} );\n\n\tconst updatedWidgets = new Set( widgets );\n\t// Remove duplicate.\n\tupdatedWidgets.delete( blockId );\n\t// Add to last block.\n\tupdatedWidgets.add( blockId );\n\n\tawait this.rest( {\n\t\tmethod: 'PUT',\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId }`,\n\t\tdata: {\n\t\t\twidgets: [ ...updatedWidgets ],\n\t\t},\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,eAAsB,mBAAmB;AACxC,QAAM,CAAE,SAAS,QAAS,IAAI,MAAM,QAAQ,IAAK;AAAA,IAChD,KAAK,KAAM,EAAE,MAAM,iBAAiB,CAAE;AAAA,IACtC,KAAK,KAAM,EAAE,MAAM,kBAAkB,CAAE;AAAA,EACxC,CAAE;AAEF,QAAM,KAAK;AAAA,IACV,QAAQ,IAAK,CAAE,YAAc;AAAA,MAC5B,QAAQ;AAAA,MACR,MAAM,kBAAmB,OAAO,EAAG;AAAA,IACpC,EAAI;AAAA,EACL;AAGA,QAAM,QAAQ;AAAA,IACb,SAAS;AAAA,MAAK,CAAE,YACf,KAAK,KAAM;AAAA,QACV,QAAQ;AAAA,QACR,MAAM,mBAAoB,QAAQ,EAAG;AAAA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