ghost 5.27.0 → 5.28.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/components/{tryghost-adapter-manager-5.27.0.tgz → tryghost-adapter-manager-5.28.0.tgz} +0 -0
- package/components/{tryghost-api-framework-5.27.0.tgz → tryghost-api-framework-5.28.0.tgz} +0 -0
- package/components/{tryghost-api-version-compatibility-service-5.27.0.tgz → tryghost-api-version-compatibility-service-5.28.0.tgz} +0 -0
- package/components/tryghost-audience-feedback-5.28.0.tgz +0 -0
- package/components/tryghost-bootstrap-socket-5.28.0.tgz +0 -0
- package/components/{tryghost-constants-5.27.0.tgz → tryghost-constants-5.28.0.tgz} +0 -0
- package/components/{tryghost-custom-theme-settings-service-5.27.0.tgz → tryghost-custom-theme-settings-service-5.28.0.tgz} +0 -0
- package/components/{tryghost-data-generator-5.27.0.tgz → tryghost-data-generator-5.28.0.tgz} +0 -0
- package/components/tryghost-domain-events-5.28.0.tgz +0 -0
- package/components/tryghost-email-analytics-provider-mailgun-5.28.0.tgz +0 -0
- package/components/tryghost-email-analytics-service-5.28.0.tgz +0 -0
- package/components/tryghost-email-content-generator-5.28.0.tgz +0 -0
- package/components/tryghost-email-events-5.28.0.tgz +0 -0
- package/components/{tryghost-email-service-5.27.0.tgz → tryghost-email-service-5.28.0.tgz} +0 -0
- package/components/tryghost-email-suppression-list-5.28.0.tgz +0 -0
- package/components/tryghost-express-dynamic-redirects-5.28.0.tgz +0 -0
- package/components/tryghost-extract-api-key-5.28.0.tgz +0 -0
- package/components/tryghost-html-to-plaintext-5.28.0.tgz +0 -0
- package/components/tryghost-importer-revue-5.28.0.tgz +0 -0
- package/components/{tryghost-job-manager-5.27.0.tgz → tryghost-job-manager-5.28.0.tgz} +0 -0
- package/components/tryghost-link-redirects-5.28.0.tgz +0 -0
- package/components/tryghost-link-replacer-5.28.0.tgz +0 -0
- package/components/{tryghost-link-tracking-5.27.0.tgz → tryghost-link-tracking-5.28.0.tgz} +0 -0
- package/components/{tryghost-magic-link-5.27.0.tgz → tryghost-magic-link-5.28.0.tgz} +0 -0
- package/components/{tryghost-mailgun-client-5.27.0.tgz → tryghost-mailgun-client-5.28.0.tgz} +0 -0
- package/components/{tryghost-member-attribution-5.27.0.tgz → tryghost-member-attribution-5.28.0.tgz} +0 -0
- package/components/tryghost-member-events-5.28.0.tgz +0 -0
- package/components/{tryghost-members-api-5.27.0.tgz → tryghost-members-api-5.28.0.tgz} +0 -0
- package/components/tryghost-members-csv-5.28.0.tgz +0 -0
- package/components/{tryghost-members-events-service-5.27.0.tgz → tryghost-members-events-service-5.28.0.tgz} +0 -0
- package/components/{tryghost-members-importer-5.27.0.tgz → tryghost-members-importer-5.28.0.tgz} +0 -0
- package/components/tryghost-members-offers-5.28.0.tgz +0 -0
- package/components/tryghost-members-payments-5.28.0.tgz +0 -0
- package/components/tryghost-members-ssr-5.28.0.tgz +0 -0
- package/components/tryghost-members-stripe-service-5.28.0.tgz +0 -0
- package/components/tryghost-minifier-5.28.0.tgz +0 -0
- package/components/tryghost-mw-api-version-mismatch-5.28.0.tgz +0 -0
- package/components/{tryghost-mw-cache-control-5.27.0.tgz → tryghost-mw-cache-control-5.28.0.tgz} +0 -0
- package/components/tryghost-mw-error-handler-5.28.0.tgz +0 -0
- package/components/tryghost-mw-session-from-token-5.28.0.tgz +0 -0
- package/components/tryghost-mw-update-user-last-seen-5.28.0.tgz +0 -0
- package/components/tryghost-mw-vhost-5.28.0.tgz +0 -0
- package/components/tryghost-oembed-service-5.28.0.tgz +0 -0
- package/components/{tryghost-package-json-5.27.0.tgz → tryghost-package-json-5.28.0.tgz} +0 -0
- package/components/{tryghost-referrers-5.27.0.tgz → tryghost-referrers-5.28.0.tgz} +0 -0
- package/components/tryghost-security-5.28.0.tgz +0 -0
- package/components/tryghost-session-service-5.28.0.tgz +0 -0
- package/components/{tryghost-settings-path-manager-5.27.0.tgz → tryghost-settings-path-manager-5.28.0.tgz} +0 -0
- package/components/{tryghost-staff-service-5.27.0.tgz → tryghost-staff-service-5.28.0.tgz} +0 -0
- package/components/tryghost-stats-service-5.28.0.tgz +0 -0
- package/components/tryghost-tiers-5.28.0.tgz +0 -0
- package/components/tryghost-update-check-service-5.28.0.tgz +0 -0
- package/components/tryghost-verification-trigger-5.28.0.tgz +0 -0
- package/components/tryghost-version-notifications-data-service-5.28.0.tgz +0 -0
- package/core/built/admin/assets/{chunk.143.90a7ca5db49aa2d315c8.js → chunk.143.16c07be45a0c39262995.js} +5 -5
- package/core/built/admin/assets/{chunk.178.4723d26b77c02377c107.js → chunk.178.93714202b2fc31b2b86a.js} +4 -4
- package/core/built/admin/assets/{ghost-b2e01b65312f0de8a3fb6a3d87ed5d89.js → ghost-d8834e309d8e4800057d6d17fed9415b.js} +105 -104
- package/core/built/admin/index.html +3 -3
- package/core/frontend/helpers/get.js +2 -2
- package/core/frontend/web/middleware/error-handler.js +0 -2
- package/core/server/api/endpoints/themes.js +13 -9
- package/core/server/data/migrations/versions/5.28/2023-01-05-15-13-add-active-theme-permissions.js +12 -0
- package/core/server/data/schema/fixtures/fixtures.json +7 -2
- package/core/server/services/themes/activate.js +3 -3
- package/core/server/services/themes/index.js +4 -2
- package/core/server/services/themes/storage.js +3 -1
- package/core/server/services/themes/to-json.js +6 -6
- package/core/server/services/themes/validate.js +80 -8
- package/core/server/web/api/endpoints/admin/routes.js +5 -0
- package/core/shared/config/defaults.json +2 -1
- package/core/shared/labs.js +3 -3
- package/package.json +105 -105
- package/yarn.lock +28 -50
- package/components/tryghost-audience-feedback-5.27.0.tgz +0 -0
- package/components/tryghost-bootstrap-socket-5.27.0.tgz +0 -0
- package/components/tryghost-domain-events-5.27.0.tgz +0 -0
- package/components/tryghost-email-analytics-provider-mailgun-5.27.0.tgz +0 -0
- package/components/tryghost-email-analytics-service-5.27.0.tgz +0 -0
- package/components/tryghost-email-content-generator-5.27.0.tgz +0 -0
- package/components/tryghost-email-events-5.27.0.tgz +0 -0
- package/components/tryghost-email-suppression-list-5.27.0.tgz +0 -0
- package/components/tryghost-express-dynamic-redirects-5.27.0.tgz +0 -0
- package/components/tryghost-extract-api-key-5.27.0.tgz +0 -0
- package/components/tryghost-html-to-plaintext-5.27.0.tgz +0 -0
- package/components/tryghost-importer-revue-5.27.0.tgz +0 -0
- package/components/tryghost-link-redirects-5.27.0.tgz +0 -0
- package/components/tryghost-link-replacer-5.27.0.tgz +0 -0
- package/components/tryghost-member-events-5.27.0.tgz +0 -0
- package/components/tryghost-members-csv-5.27.0.tgz +0 -0
- package/components/tryghost-members-offers-5.27.0.tgz +0 -0
- package/components/tryghost-members-payments-5.27.0.tgz +0 -0
- package/components/tryghost-members-ssr-5.27.0.tgz +0 -0
- package/components/tryghost-members-stripe-service-5.27.0.tgz +0 -0
- package/components/tryghost-minifier-5.27.0.tgz +0 -0
- package/components/tryghost-mw-api-version-mismatch-5.27.0.tgz +0 -0
- package/components/tryghost-mw-error-handler-5.27.0.tgz +0 -0
- package/components/tryghost-mw-session-from-token-5.27.0.tgz +0 -0
- package/components/tryghost-mw-update-user-last-seen-5.27.0.tgz +0 -0
- package/components/tryghost-mw-vhost-5.27.0.tgz +0 -0
- package/components/tryghost-oembed-service-5.27.0.tgz +0 -0
- package/components/tryghost-security-5.27.0.tgz +0 -0
- package/components/tryghost-session-service-5.27.0.tgz +0 -0
- package/components/tryghost-stats-service-5.27.0.tgz +0 -0
- package/components/tryghost-tiers-5.27.0.tgz +0 -0
- package/components/tryghost-update-check-service-5.27.0.tgz +0 -0
- package/components/tryghost-verification-trigger-5.27.0.tgz +0 -0
- package/components/tryghost-version-notifications-data-service-5.27.0.tgz +0 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<title>Ghost Admin</title>
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%225.
|
|
11
|
+
<meta name="ghost-admin/config/environment" content="%7B%22modulePrefix%22%3A%22ghost-admin%22%2C%22environment%22%3A%22production%22%2C%22rootURL%22%3A%22%22%2C%22locationType%22%3A%22trailing-hash%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%2C%22EXTEND_PROTOTYPES%22%3A%7B%22Date%22%3Afalse%2C%22Array%22%3Atrue%2C%22String%22%3Atrue%2C%22Function%22%3Afalse%7D%2C%22_APPLICATION_TEMPLATE_WRAPPER%22%3Afalse%2C%22_JQUERY_INTEGRATION%22%3Atrue%2C%22_TEMPLATE_ONLY_GLIMMER_COMPONENTS%22%3Atrue%7D%2C%22APP%22%3A%7B%22version%22%3A%225.28%22%2C%22name%22%3A%22ghost-admin%22%7D%2C%22ember-simple-auth%22%3A%7B%7D%2C%22%40sentry%2Fember%22%3A%7B%22disablePerformance%22%3Atrue%2C%22sentry%22%3A%7B%7D%7D%2C%22ember-cli-mirage%22%3A%7B%22usingProxy%22%3Afalse%2C%22useDefaultPassthroughs%22%3Atrue%7D%2C%22exportApplicationGlobal%22%3Afalse%2C%22ember-load%22%3A%7B%22loadingIndicatorClass%22%3A%22ember-load-indicator%22%7D%7D" />
|
|
12
12
|
|
|
13
13
|
<meta name="HandheldFriendly" content="True" />
|
|
14
14
|
<meta name="MobileOptimized" content="320" />
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
|
|
59
59
|
<script src="assets/vendor-dbf84caa0968ef5da0486055da6636da.js"></script>
|
|
60
60
|
<script src="assets/chunk.380.de3a9bf5161ab5300d23.js"></script>
|
|
61
|
-
<script src="assets/chunk.143.
|
|
62
|
-
<script src="assets/ghost-
|
|
61
|
+
<script src="assets/chunk.143.16c07be45a0c39262995.js"></script>
|
|
62
|
+
<script src="assets/ghost-d8834e309d8e4800057d6d17fed9415b.js"></script>
|
|
63
63
|
</body>
|
|
64
64
|
</html>
|
|
@@ -13,7 +13,7 @@ const jsonpath = require('jsonpath');
|
|
|
13
13
|
|
|
14
14
|
const messages = {
|
|
15
15
|
mustBeCalledAsBlock: 'The {\\{{helperName}}} helper must be called as a block. E.g. {{#{helperName}}}...{{/{helperName}}}',
|
|
16
|
-
invalidResource: 'Invalid resource given to get helper'
|
|
16
|
+
invalidResource: 'Invalid "{resource}" resource given to get helper'
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const createFrame = hbs.handlebars.createFrame;
|
|
@@ -193,7 +193,7 @@ module.exports = async function get(resource, options) {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
if (!RESOURCES[resource]) {
|
|
196
|
-
data.error = tpl(messages.invalidResource);
|
|
196
|
+
data.error = tpl(messages.invalidResource, {resource});
|
|
197
197
|
logging.warn(data.error);
|
|
198
198
|
return options.inverse(self, {data: data});
|
|
199
199
|
}
|
|
@@ -4,6 +4,7 @@ const models = require('../../models');
|
|
|
4
4
|
|
|
5
5
|
// Used to emit theme.uploaded which is used in core/server/analytics-events
|
|
6
6
|
const events = require('../../lib/common/events');
|
|
7
|
+
const {settingsCache} = require('../../services/settings-helpers');
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
docName: 'themes',
|
|
@@ -15,6 +16,15 @@ module.exports = {
|
|
|
15
16
|
}
|
|
16
17
|
},
|
|
17
18
|
|
|
19
|
+
readActive: {
|
|
20
|
+
permissions: true,
|
|
21
|
+
async query() {
|
|
22
|
+
let themeName = settingsCache.get('active_theme');
|
|
23
|
+
const themeErrors = await themeService.api.getThemeErrors(themeName);
|
|
24
|
+
return themeService.api.getJSON(themeName, themeErrors);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
|
|
18
28
|
activate: {
|
|
19
29
|
headers: {
|
|
20
30
|
cacheInvalidate: true
|
|
@@ -42,15 +52,9 @@ module.exports = {
|
|
|
42
52
|
value: themeName
|
|
43
53
|
}];
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return models.Settings.edit(newSettings, frame.options)
|
|
49
|
-
.then(() => checkedTheme);
|
|
50
|
-
})
|
|
51
|
-
.then((checkedTheme) => {
|
|
52
|
-
return themeService.api.getJSON(themeName, checkedTheme);
|
|
53
|
-
});
|
|
55
|
+
const themeErrors = await themeService.api.activate(themeName);
|
|
56
|
+
await models.Settings.edit(newSettings, frame.options);
|
|
57
|
+
return themeService.api.getJSON(themeName, themeErrors);
|
|
54
58
|
}
|
|
55
59
|
},
|
|
56
60
|
|
package/core/server/data/migrations/versions/5.28/2023-01-05-15-13-add-active-theme-permissions.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const {addPermissionWithRoles} = require('../../utils');
|
|
2
|
+
|
|
3
|
+
module.exports = addPermissionWithRoles({
|
|
4
|
+
name: 'View active theme details',
|
|
5
|
+
action: 'readActive',
|
|
6
|
+
object: 'theme'
|
|
7
|
+
}, [
|
|
8
|
+
'Author',
|
|
9
|
+
'Editor',
|
|
10
|
+
'Administrator',
|
|
11
|
+
'Admin Integration'
|
|
12
|
+
]);
|
|
@@ -214,6 +214,11 @@
|
|
|
214
214
|
"action_type": "activate",
|
|
215
215
|
"object_type": "theme"
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
"name": "View active theme details",
|
|
219
|
+
"action_type": "readActive",
|
|
220
|
+
"object_type": "theme"
|
|
221
|
+
},
|
|
217
222
|
{
|
|
218
223
|
"name": "Upload themes",
|
|
219
224
|
"action_type": "add",
|
|
@@ -804,7 +809,7 @@
|
|
|
804
809
|
"user": "all",
|
|
805
810
|
"role": "all",
|
|
806
811
|
"invite": "all",
|
|
807
|
-
"theme": ["browse"],
|
|
812
|
+
"theme": ["browse", "readActive"],
|
|
808
813
|
"email_preview": "all",
|
|
809
814
|
"email": "all",
|
|
810
815
|
"snippet": "all",
|
|
@@ -819,7 +824,7 @@
|
|
|
819
824
|
"tag": ["browse", "read", "add"],
|
|
820
825
|
"user": ["browse", "read"],
|
|
821
826
|
"role": ["browse"],
|
|
822
|
-
"theme": ["browse"],
|
|
827
|
+
"theme": ["browse", "readActive"],
|
|
823
828
|
"email_preview": "read",
|
|
824
829
|
"email": "read",
|
|
825
830
|
"snippet": ["browse", "read"],
|
|
@@ -21,7 +21,7 @@ module.exports.loadAndActivate = async (themeName) => {
|
|
|
21
21
|
const loadedTheme = await themeLoader.loadOneTheme(themeName);
|
|
22
22
|
// Validate
|
|
23
23
|
// @NOTE: this is now the only usage of check, rather than checkSafe...
|
|
24
|
-
const checkedTheme = await validate.check(loadedTheme);
|
|
24
|
+
const checkedTheme = await validate.check(themeName, loadedTheme);
|
|
25
25
|
|
|
26
26
|
if (!validate.canActivate(checkedTheme)) {
|
|
27
27
|
logging.error(validate.getThemeValidationError('activeThemeHasFatalErrors', themeName, checkedTheme));
|
|
@@ -57,6 +57,6 @@ module.exports.activate = async (themeName) => {
|
|
|
57
57
|
const checkedTheme = await validate.checkSafe(themeName, loadedTheme);
|
|
58
58
|
// Activate
|
|
59
59
|
await activator.activateFromAPI(themeName, loadedTheme, checkedTheme);
|
|
60
|
-
// Return the
|
|
61
|
-
return checkedTheme;
|
|
60
|
+
// Return the theme errors
|
|
61
|
+
return validate.getErrorsFromCheckedTheme(checkedTheme);
|
|
62
62
|
};
|
|
@@ -3,7 +3,7 @@ const themeLoader = require('./loader');
|
|
|
3
3
|
const storage = require('./storage');
|
|
4
4
|
const getJSON = require('./to-json');
|
|
5
5
|
const installer = require('./installer');
|
|
6
|
-
|
|
6
|
+
const validate = require('./validate');
|
|
7
7
|
const settingsCache = require('../../../shared/settings-cache');
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
@@ -11,8 +11,9 @@ module.exports = {
|
|
|
11
11
|
* Load the currently active theme
|
|
12
12
|
*/
|
|
13
13
|
init: async () => {
|
|
14
|
-
|
|
14
|
+
validate.init();
|
|
15
15
|
|
|
16
|
+
const themeName = settingsCache.get('active_theme');
|
|
16
17
|
return activate.loadAndActivate(themeName);
|
|
17
18
|
},
|
|
18
19
|
/**
|
|
@@ -25,6 +26,7 @@ module.exports = {
|
|
|
25
26
|
api: {
|
|
26
27
|
getJSON,
|
|
27
28
|
activate: activate.activate,
|
|
29
|
+
getThemeErrors: validate.getThemeErrors,
|
|
28
30
|
getZip: storage.getZip,
|
|
29
31
|
setFromZip: storage.setFromZip,
|
|
30
32
|
installFromGithub: installer.installFromGithub,
|
|
@@ -86,10 +86,12 @@ module.exports = {
|
|
|
86
86
|
await activator.activateFromAPIOverride(themeName, loadedTheme, checkedTheme);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
const themeErrors = validate.getErrorsFromCheckedTheme(checkedTheme);
|
|
90
|
+
|
|
89
91
|
// @TODO: unify the name across gscan and Ghost!
|
|
90
92
|
return {
|
|
91
93
|
themeOverridden: overrideTheme,
|
|
92
|
-
theme: toJSON(themeName,
|
|
94
|
+
theme: toJSON(themeName, themeErrors)
|
|
93
95
|
};
|
|
94
96
|
} catch (error) {
|
|
95
97
|
// restore backup if we renamed an existing theme but saving failed
|
|
@@ -13,10 +13,10 @@ const settingsCache = require('../../../shared/settings-cache');
|
|
|
13
13
|
* @TODO: settingsCache.get('active_theme') vs. active.get().name
|
|
14
14
|
*
|
|
15
15
|
* @param {string} [name] - the theme to output
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {{errors: Array, warnings: Array}} [themeErrors] - Error and warning results from checked theme (if available)
|
|
17
17
|
* @return {}
|
|
18
18
|
*/
|
|
19
|
-
module.exports = function toJSON(name,
|
|
19
|
+
module.exports = function toJSON(name, themeErrors) {
|
|
20
20
|
let themeResult;
|
|
21
21
|
let toFilter;
|
|
22
22
|
|
|
@@ -30,12 +30,12 @@ module.exports = function toJSON(name, checkedTheme) {
|
|
|
30
30
|
|
|
31
31
|
themeResult = packageJSON.filter(toFilter, settingsCache.get('active_theme'));
|
|
32
32
|
|
|
33
|
-
if (
|
|
34
|
-
themeResult[0].warnings = _.cloneDeep(
|
|
33
|
+
if (themeErrors && themeErrors.warnings.length) {
|
|
34
|
+
themeResult[0].warnings = _.cloneDeep(themeErrors.warnings);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
if (
|
|
38
|
-
themeResult[0].errors = _.cloneDeep(
|
|
37
|
+
if (themeErrors && themeErrors.errors.length) {
|
|
38
|
+
themeResult[0].errors = _.cloneDeep(themeErrors.errors);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -5,20 +5,46 @@ const config = require('../../../shared/config');
|
|
|
5
5
|
const labs = require('../../../shared/labs');
|
|
6
6
|
const tpl = require('@tryghost/tpl');
|
|
7
7
|
const errors = require('@tryghost/errors');
|
|
8
|
+
const adapterManager = require('../adapter-manager');
|
|
9
|
+
const logging = require('@tryghost/logging');
|
|
10
|
+
const list = require('./list');
|
|
8
11
|
|
|
9
12
|
const messages = {
|
|
10
13
|
themeHasErrors: 'Theme "{theme}" is not compatible or contains errors.',
|
|
11
14
|
activeThemeHasFatalErrors: 'The currently active theme "{theme}" has fatal errors.',
|
|
12
|
-
activeThemeHasErrors: 'The currently active theme "{theme}" has errors, but will still work.'
|
|
15
|
+
activeThemeHasErrors: 'The currently active theme "{theme}" has errors, but will still work.',
|
|
16
|
+
themeNotLoaded: 'Theme "{themeName}" is not loaded and cannot be checked.'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} CacheStore
|
|
21
|
+
* @property {(key: string) => Promise<any>} get - get a value from the cache. Returns undefined if not found
|
|
22
|
+
* @property {(key: string, value: any) => Promise<void>} set - set a value in the cache
|
|
23
|
+
* @property {() => Promise<void>} reset - reset the cache
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The cache store for storing the result of the last theme validation
|
|
28
|
+
* @type {CacheStore}
|
|
29
|
+
*/
|
|
30
|
+
let gscanCacheStore;
|
|
31
|
+
|
|
32
|
+
module.exports.init = () => {
|
|
33
|
+
gscanCacheStore = adapterManager.getAdapter('cache:gscan');
|
|
13
34
|
};
|
|
14
35
|
|
|
15
36
|
const canActivate = function canActivate(checkedTheme) {
|
|
16
|
-
|
|
17
|
-
// CASE: development returns fatal and none fatal errors, theme is only invalid if fatal errors
|
|
18
|
-
return !checkedTheme.results.error.length || (config.get('env') === 'development') && !checkedTheme.results.hasFatalErrors;
|
|
37
|
+
return !checkedTheme.results.hasFatalErrors;
|
|
19
38
|
};
|
|
20
39
|
|
|
21
|
-
const
|
|
40
|
+
const getErrorsFromCheckedTheme = function getErrorsFromCheckedTheme(checkedTheme) {
|
|
41
|
+
return {
|
|
42
|
+
errors: checkedTheme.results.error ?? [],
|
|
43
|
+
warnings: checkedTheme.results.warning ?? []
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const check = async function check(themeName, theme, isZip) {
|
|
22
48
|
debug('Begin: Check');
|
|
23
49
|
// gscan can slow down boot time if we require on boot, for now nest the require.
|
|
24
50
|
const gscan = require('gscan');
|
|
@@ -41,16 +67,59 @@ const check = async function check(theme, isZip) {
|
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
checkedTheme = gscan.format(checkedTheme, {
|
|
44
|
-
onlyFatalErrors:
|
|
70
|
+
onlyFatalErrors: false,
|
|
45
71
|
checkVersion: checkedVersion
|
|
46
72
|
});
|
|
47
73
|
|
|
74
|
+
// In production we don't want to show warnings
|
|
75
|
+
// Warnings are meant for developers only
|
|
76
|
+
if (config.get('env') === 'production') {
|
|
77
|
+
checkedTheme.results.warning = [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Cache warnings and errors
|
|
81
|
+
try {
|
|
82
|
+
await gscanCacheStore.set(themeName, getErrorsFromCheckedTheme(checkedTheme));
|
|
83
|
+
} catch (err) {
|
|
84
|
+
logging.error('Failed to cache gscan result');
|
|
85
|
+
logging.error(err);
|
|
86
|
+
}
|
|
87
|
+
|
|
48
88
|
debug('End: Check');
|
|
49
89
|
return checkedTheme;
|
|
50
90
|
};
|
|
51
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Returns the last cached errors and warnings of check() if available.
|
|
94
|
+
* Otherwise runs check() on the loaded theme with that name (which will always cache the error and warning results)
|
|
95
|
+
* @returns {Promise<{errors: Array, warnings: Array}>}
|
|
96
|
+
*/
|
|
97
|
+
const getThemeErrors = async function getThemeErrors(themeName) {
|
|
98
|
+
try {
|
|
99
|
+
const cachedThemeErrors = await gscanCacheStore.get(themeName);
|
|
100
|
+
if (cachedThemeErrors) {
|
|
101
|
+
return cachedThemeErrors;
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
logging.error('Failed to get gscan result from cache');
|
|
105
|
+
logging.error(err);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const loadedTheme = list.get(themeName);
|
|
109
|
+
|
|
110
|
+
if (!loadedTheme) {
|
|
111
|
+
throw new errors.ValidationError({
|
|
112
|
+
message: tpl(messages.themeNotLoaded, {themeName: themeName}),
|
|
113
|
+
errorDetails: themeName
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result = await check(themeName, loadedTheme);
|
|
118
|
+
return getErrorsFromCheckedTheme(result);
|
|
119
|
+
};
|
|
120
|
+
|
|
52
121
|
const checkSafe = async function checkSafe(themeName, theme, isZip) {
|
|
53
|
-
const checkedTheme = await check(theme, isZip);
|
|
122
|
+
const checkedTheme = await check(themeName, theme, isZip);
|
|
54
123
|
|
|
55
124
|
if (canActivate(checkedTheme)) {
|
|
56
125
|
return checkedTheme;
|
|
@@ -74,7 +143,8 @@ const getThemeValidationError = (message, themeName, checkedTheme) => {
|
|
|
74
143
|
message: tpl(messages[message], {theme: themeName}),
|
|
75
144
|
errorDetails: Object.assign(
|
|
76
145
|
_.pick(checkedTheme, ['checkedVersion', 'name', 'path', 'version']), {
|
|
77
|
-
errors: checkedTheme.results.error
|
|
146
|
+
errors: checkedTheme.results.error,
|
|
147
|
+
warnings: checkedTheme.results.warning
|
|
78
148
|
}
|
|
79
149
|
)
|
|
80
150
|
});
|
|
@@ -83,4 +153,6 @@ const getThemeValidationError = (message, themeName, checkedTheme) => {
|
|
|
83
153
|
module.exports.check = check;
|
|
84
154
|
module.exports.checkSafe = checkSafe;
|
|
85
155
|
module.exports.canActivate = canActivate;
|
|
156
|
+
module.exports.getErrorsFromCheckedTheme = getErrorsFromCheckedTheme;
|
|
86
157
|
module.exports.getThemeValidationError = getThemeValidationError;
|
|
158
|
+
module.exports.getThemeErrors = getThemeErrors;
|
|
@@ -159,6 +159,11 @@ module.exports = function apiRoutes() {
|
|
|
159
159
|
http(api.themes.download)
|
|
160
160
|
);
|
|
161
161
|
|
|
162
|
+
router.get('/themes/active',
|
|
163
|
+
mw.authAdminApi,
|
|
164
|
+
http(api.themes.readActive)
|
|
165
|
+
);
|
|
166
|
+
|
|
162
167
|
router.post('/themes/upload',
|
|
163
168
|
mw.authAdminApi,
|
|
164
169
|
apiMw.upload.single('file'),
|
package/core/shared/labs.js
CHANGED
|
@@ -17,7 +17,8 @@ const messages = {
|
|
|
17
17
|
const GA_FEATURES = [
|
|
18
18
|
'sourceAttribution',
|
|
19
19
|
'memberAttribution',
|
|
20
|
-
'audienceFeedback'
|
|
20
|
+
'audienceFeedback',
|
|
21
|
+
'themeErrorsNotification'
|
|
21
22
|
];
|
|
22
23
|
|
|
23
24
|
// NOTE: this allowlist is meant to be used to filter out any unexpected
|
|
@@ -31,8 +32,7 @@ const ALPHA_FEATURES = [
|
|
|
31
32
|
'beforeAfterCard',
|
|
32
33
|
'lexicalEditor',
|
|
33
34
|
'suppressionList',
|
|
34
|
-
'emailStability'
|
|
35
|
-
'themeErrorsNotification'
|
|
35
|
+
'emailStability'
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
module.exports.GA_KEYS = [...GA_FEATURES];
|