@mindful-web/marko-web 1.42.0 → 1.44.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/bot-scores.marko +1 -12
- package/components/bot-scores.marko.js +4 -23
- package/components/browser-component/script.marko.js +2 -2
- package/components/browser-component.marko.js +2 -2
- package/components/deferred-stylesheet.marko.js +2 -2
- package/components/document/components/body-wrapper.marko.js +2 -2
- package/components/document/components/error.marko.js +2 -2
- package/components/document/components/live-reload.marko.js +2 -2
- package/components/document/components/polyfill.marko.js +2 -2
- package/components/document/components/styles.marko.js +2 -2
- package/components/document/container.marko.js +2 -2
- package/components/document/index.marko +2 -2
- package/components/document/index.marko.js +10 -10
- package/components/element/array.marko.js +2 -2
- package/components/element/audio.marko.js +2 -2
- package/components/element/block.marko.js +2 -2
- package/components/element/clear.marko.js +2 -2
- package/components/element/components/image.marko.js +2 -2
- package/components/element/components/text.marko.js +2 -2
- package/components/element/content/address1.marko.js +2 -2
- package/components/element/content/address2.marko.js +2 -2
- package/components/element/content/audio.marko.js +2 -2
- package/components/element/content/authors.marko.js +2 -2
- package/components/element/content/body.marko.js +2 -2
- package/components/element/content/byline.marko.js +2 -2
- package/components/element/content/city-state-zip.marko.js +2 -2
- package/components/element/content/contributors.marko.js +2 -2
- package/components/element/content/country.marko.js +2 -2
- package/components/element/content/embed-code.marko.js +2 -2
- package/components/element/content/end-date.marko.js +2 -2
- package/components/element/content/ends.marko.js +2 -2
- package/components/element/content/fax.marko.js +2 -2
- package/components/element/content/images.marko.js +2 -2
- package/components/element/content/mobile.marko.js +2 -2
- package/components/element/content/name.marko.js +2 -2
- package/components/element/content/phone.marko.js +2 -2
- package/components/element/content/photographers.marko.js +2 -2
- package/components/element/content/public-email.marko.js +2 -2
- package/components/element/content/published.marko.js +2 -2
- package/components/element/content/short-name.marko.js +2 -2
- package/components/element/content/sidebar-stubs.marko.js +2 -2
- package/components/element/content/sidebars.marko.js +2 -2
- package/components/element/content/source.marko.js +2 -2
- package/components/element/content/sponsors.marko.js +2 -2
- package/components/element/content/start-date.marko.js +2 -2
- package/components/element/content/starts.marko.js +2 -2
- package/components/element/content/teaser.marko.js +2 -2
- package/components/element/content/title.marko.js +2 -2
- package/components/element/content/tollfree.marko.js +2 -2
- package/components/element/content/transcript.marko.js +2 -2
- package/components/element/content/website-deck.marko.js +2 -2
- package/components/element/content/website.marko.js +2 -2
- package/components/element/date.marko.js +2 -2
- package/components/element/image/caption.marko.js +2 -2
- package/components/element/image/credit.marko.js +2 -2
- package/components/element/image/display-name.marko.js +2 -2
- package/components/element/image/slider.marko.js +2 -2
- package/components/element/img.marko.js +2 -2
- package/components/element/index.marko.js +2 -2
- package/components/element/link.marko.js +2 -2
- package/components/element/magazine-issue/description.marko.js +2 -2
- package/components/element/magazine-issue/digital-edition-url.marko.js +2 -2
- package/components/element/magazine-issue/name.marko.js +2 -2
- package/components/element/magazine-issue/pdf-url.marko.js +2 -2
- package/components/element/magazine-publication/cancel-url.marko.js +2 -2
- package/components/element/magazine-publication/change-address-url.marko.js +2 -2
- package/components/element/magazine-publication/description.marko.js +2 -2
- package/components/element/magazine-publication/einquiry-url.marko.js +2 -2
- package/components/element/magazine-publication/name.marko.js +2 -2
- package/components/element/magazine-publication/renewal-url.marko.js +2 -2
- package/components/element/magazine-publication/reprints-url.marko.js +2 -2
- package/components/element/magazine-publication/subscribe-url.marko.js +2 -2
- package/components/element/obj-array.marko.js +2 -2
- package/components/element/obj-audio.marko.js +2 -2
- package/components/element/obj-date.marko.js +2 -2
- package/components/element/obj-nodes.marko.js +2 -2
- package/components/element/obj-text.marko.js +2 -2
- package/components/element/obj.marko.js +2 -2
- package/components/element/picture.marko.js +2 -2
- package/components/element/text.marko.js +2 -2
- package/components/element/website-section/description.marko.js +2 -2
- package/components/element/website-section/hierarchy.marko.js +2 -2
- package/components/element/website-section/name.marko.js +2 -2
- package/components/font/google.marko.js +2 -2
- package/components/font/link.marko.js +2 -2
- package/components/font/typekit.marko.js +2 -2
- package/components/load-more/index.marko.js +2 -2
- package/components/load-more/trigger.marko.js +2 -2
- package/components/node/body.marko.js +2 -2
- package/components/node/element.marko.js +2 -2
- package/components/node/footer.marko.js +2 -2
- package/components/node/header.marko.js +2 -2
- package/components/node/image-inner-wrapper.marko.js +2 -2
- package/components/node/image-wrapper.marko.js +2 -2
- package/components/node/image.marko.js +2 -2
- package/components/node/index.marko.js +2 -2
- package/components/node-list/body.marko.js +2 -2
- package/components/node-list/element.marko.js +2 -2
- package/components/node-list/footer.marko.js +2 -2
- package/components/node-list/header.marko.js +2 -2
- package/components/node-list/index.marko.js +2 -2
- package/components/node-list/node.marko.js +2 -2
- package/components/node-list/nodes.marko.js +2 -2
- package/components/page/container.marko.js +2 -2
- package/components/page/description.marko.js +2 -2
- package/components/page/image.marko.js +2 -2
- package/components/page/layouts/content.marko.js +2 -2
- package/components/page/layouts/default.marko.js +2 -2
- package/components/page/layouts/dynamic-page.marko.js +2 -2
- package/components/page/layouts/magazine-issue.marko.js +2 -2
- package/components/page/layouts/magazine-publication.marko.js +2 -2
- package/components/page/layouts/website-section.marko.js +2 -2
- package/components/page/metadata/components/common.marko.js +2 -2
- package/components/page/metadata/content.marko.js +2 -2
- package/components/page/metadata/default.marko.js +2 -2
- package/components/page/metadata/dynamic-page.marko.js +2 -2
- package/components/page/metadata/magazine-issue.marko.js +2 -2
- package/components/page/metadata/magazine-publication.marko.js +2 -2
- package/components/page/metadata/website-section.marko.js +2 -2
- package/components/page/rel-canonical.marko.js +2 -2
- package/components/page/title.marko.js +2 -2
- package/components/page/wrapper.marko.js +2 -2
- package/components/resolve/page.marko.js +2 -2
- package/components/rss/website-section.marko.js +2 -2
- package/express/bot-scores.js +53 -50
- package/express/website-context.js +2 -9
- package/package.json +2 -2
package/express/bot-scores.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { asyncRoute, cleanPath } = require('@mindful-web/utils');
|
|
2
2
|
const fetch = require('node-fetch');
|
|
3
|
-
const { extname } = require('path');
|
|
4
3
|
|
|
5
4
|
const { error } = console;
|
|
6
5
|
|
|
@@ -11,12 +10,59 @@ module.exports = function botScores({
|
|
|
11
10
|
url,
|
|
12
11
|
}) {
|
|
13
12
|
const hasRequiredProps = Boolean(apiKey && url);
|
|
14
|
-
const isEnabled = hasRequiredProps ? enabled : false;
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/** @type {BotScores} */
|
|
15
|
+
const $botScores = {
|
|
16
|
+
buildFetchHeaders: () => {
|
|
17
|
+
const [org] = app.locals.tenantKey.split('_');
|
|
18
|
+
return {
|
|
19
|
+
'content-type': 'application/json',
|
|
20
|
+
'x-host': app.locals.config.website('host'),
|
|
21
|
+
'x-org-key': org,
|
|
22
|
+
'x-requested-with': 'XMLHttpRequest',
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
enabled: hasRequiredProps ? enabled : false,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const loadToken = async () => {
|
|
29
|
+
if (!$botScores.enabled) return null;
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(`${cleanPath(url)}/token`, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) throw new Error(`Bad response: ${response.status}`);
|
|
36
|
+
const { token } = await response.json();
|
|
37
|
+
return token;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// @todo better logging
|
|
40
|
+
error(`error retrieving bot scores token: ${e.message}`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
app.post('/__bs/:event(gam|gtm)', asyncRoute(async (req, res) => {
|
|
46
|
+
const { event } = req.params;
|
|
47
|
+
if (!$botScores.enabled) return res.set({ 'x-send': JSON.stringify({ event, ...$botScores.buildFetchHeaders() }) }).send('');
|
|
48
|
+
|
|
49
|
+
const token = await loadToken();
|
|
50
|
+
|
|
51
|
+
const headers = ['asn', 'vbc', 'bmsc', 'bmvb'].reduce((o, k) => {
|
|
52
|
+
const header = `x-${k}`;
|
|
53
|
+
const v = req.headers[header];
|
|
54
|
+
return { ...o, ...(v && { [header]: v }) };
|
|
55
|
+
}, { ...(token && { 'x-event': event, 'x-token': token, ...$botScores.buildFetchHeaders() }) });
|
|
56
|
+
|
|
57
|
+
res.set({ 'x-send': JSON.stringify(headers) });
|
|
58
|
+
return res.send('');
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
app.post('/__bs/:event(gam|gtm)/s', asyncRoute(async (req, res) => {
|
|
62
|
+
if (!$botScores.enabled) return res.send({ noop: true });
|
|
63
|
+
|
|
18
64
|
const env = process.env.NODE_ENV;
|
|
19
|
-
const showInfo = env === 'development' || req.
|
|
65
|
+
const showInfo = env === 'development' || req.headers['x-debug'] === 'true';
|
|
20
66
|
try {
|
|
21
67
|
// remove incoming host header
|
|
22
68
|
const { host, ...headers } = req.headers;
|
|
@@ -35,51 +81,15 @@ module.exports = function botScores({
|
|
|
35
81
|
if (!response.ok) throw new Error(`Bad response: ${response.status}`);
|
|
36
82
|
const info = showInfo ? await response.json() : undefined;
|
|
37
83
|
|
|
38
|
-
res.send({ ok: true, info });
|
|
84
|
+
return res.send({ ok: true, info });
|
|
39
85
|
} catch (e) {
|
|
40
86
|
// @todo better logging
|
|
41
87
|
error(`error collecting bot score info: ${e.message}`);
|
|
42
|
-
res.send({ ok: false, ...(showInfo && { info: e.message }) });
|
|
88
|
+
return res.send({ ok: false, ...(showInfo && { info: e.message }) });
|
|
43
89
|
}
|
|
44
90
|
}));
|
|
45
91
|
|
|
46
92
|
return (_, res, next) => {
|
|
47
|
-
/** @type {BotScores} */
|
|
48
|
-
const $botScores = {
|
|
49
|
-
buildFetchHeaders() {
|
|
50
|
-
const [org] = app.locals.tenantKey.split('_');
|
|
51
|
-
return {
|
|
52
|
-
'content-type': 'application/json',
|
|
53
|
-
'x-host': app.locals.config.website('host'),
|
|
54
|
-
'x-org-key': org,
|
|
55
|
-
'x-requested-with': 'XMLHttpRequest',
|
|
56
|
-
'x-token': this.token,
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
enabled: isEnabled,
|
|
60
|
-
isValidRequestPath: (path) => {
|
|
61
|
-
if (!path) return false;
|
|
62
|
-
if (path.startsWith('/__') || path.startsWith('/dist') || path.startsWith('/print/content')) return false;
|
|
63
|
-
if (extname(path)) return false;
|
|
64
|
-
return true;
|
|
65
|
-
},
|
|
66
|
-
loadToken: async () => {
|
|
67
|
-
if (!isEnabled) return;
|
|
68
|
-
if ($botScores.token) return;
|
|
69
|
-
try {
|
|
70
|
-
const response = await fetch(`${cleanPath(url)}/token`, {
|
|
71
|
-
method: 'GET',
|
|
72
|
-
headers: { authorization: `Bearer ${apiKey}` },
|
|
73
|
-
});
|
|
74
|
-
if (!response.ok) throw new Error(`Bad response: ${response.status}`);
|
|
75
|
-
const { token } = await response.json();
|
|
76
|
-
$botScores.token = token;
|
|
77
|
-
} catch (e) {
|
|
78
|
-
// @todo better logging
|
|
79
|
-
error(`error retrieving bot scores token: ${e.message}`);
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
93
|
res.locals.$botScores = $botScores;
|
|
84
94
|
next();
|
|
85
95
|
};
|
|
@@ -89,13 +99,6 @@ module.exports = function botScores({
|
|
|
89
99
|
* @typedef BotScores
|
|
90
100
|
* @prop {BuildFetchHeadersFn} buildFetchHeaders
|
|
91
101
|
* @prop {boolean} enabled
|
|
92
|
-
* @prop {IsValidRequestPathFn} isValidRequestPath
|
|
93
|
-
* @prop {BotScoresLoadTokenFn} loadToken
|
|
94
|
-
* @prop {string} [token]
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* @callback BotScoresLoadTokenFn
|
|
98
|
-
* @returns {Promise<void>}
|
|
99
102
|
*/
|
|
100
103
|
/**
|
|
101
104
|
* @callback BuildFetchHeadersFn
|
|
@@ -3,15 +3,8 @@ const { asyncRoute } = require('@mindful-web/utils');
|
|
|
3
3
|
const { setDayjsLocale } = require('@mindful-web/dayjs/utils');
|
|
4
4
|
|
|
5
5
|
module.exports = (coreConfig) => asyncRoute(async (req, res, next) => {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const [websiteContext] = await Promise.all([
|
|
9
|
-
loadWebsite(apollo),
|
|
10
|
-
(async () => {
|
|
11
|
-
if (!$botScores || !$botScores.isValidRequestPath(req.path)) return null;
|
|
12
|
-
return $botScores.loadToken();
|
|
13
|
-
})(),
|
|
14
|
-
]);
|
|
6
|
+
const { apollo } = res.locals;
|
|
7
|
+
const websiteContext = await loadWebsite(apollo);
|
|
15
8
|
coreConfig.setWebsiteContext(websiteContext);
|
|
16
9
|
|
|
17
10
|
const locale = coreConfig.website('date.locale');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindful-web/marko-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.44.0",
|
|
4
4
|
"description": "Core Marko+Express components for Mindful Web websites",
|
|
5
5
|
"author": "Jacob Bare <jacob@parameter1.com>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "e3023eb179d3a67663791eb2f3d13bd9fc255f4a"
|
|
64
64
|
}
|