@mindful-web/marko-web 1.28.0 → 1.43.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 +14 -0
- package/components/bot-scores.marko.js +42 -0
- 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 -0
- package/components/document/index.marko.js +20 -15
- 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/marko.json +3 -0
- 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 +109 -0
- package/express/index.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
const { asyncRoute, cleanPath } = require('@mindful-web/utils');
|
|
2
|
+
const fetch = require('node-fetch');
|
|
3
|
+
|
|
4
|
+
const { error } = console;
|
|
5
|
+
|
|
6
|
+
module.exports = function botScores({
|
|
7
|
+
apiKey,
|
|
8
|
+
app,
|
|
9
|
+
enabled,
|
|
10
|
+
url,
|
|
11
|
+
}) {
|
|
12
|
+
const hasRequiredProps = Boolean(apiKey && url);
|
|
13
|
+
|
|
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('/__bmsc/1', asyncRoute(async (req, res) => {
|
|
46
|
+
if (!$botScores.enabled) return res.set({ 'x-meta': '{}' }).send('');
|
|
47
|
+
const token = await loadToken();
|
|
48
|
+
|
|
49
|
+
const headers = ['asn', 'vbc', 'bmsc', 'bmvb'].reduce((o, k) => {
|
|
50
|
+
const header = `x-${k}`;
|
|
51
|
+
const v = req.headers[header];
|
|
52
|
+
return { ...o, ...(v && { [header]: v }) };
|
|
53
|
+
}, { ...(token && { 'x-token': token }) });
|
|
54
|
+
|
|
55
|
+
res.set({ 'x-meta': JSON.stringify(headers) });
|
|
56
|
+
return res.send('');
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
app.post('/__bmsc/2', asyncRoute(async (req, res) => {
|
|
60
|
+
if (!$botScores.enabled) return res.send({ noop: true });
|
|
61
|
+
|
|
62
|
+
const env = process.env.NODE_ENV;
|
|
63
|
+
const showInfo = env === 'development' || req.query.debug === 'true';
|
|
64
|
+
try {
|
|
65
|
+
// remove incoming host header
|
|
66
|
+
const { host, ...headers } = req.headers;
|
|
67
|
+
const response = await fetch(`${cleanPath(url)}/collect`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
...headers,
|
|
71
|
+
...(env === 'development' && {
|
|
72
|
+
origin: `https://${app.locals.config.website('host')}`,
|
|
73
|
+
}),
|
|
74
|
+
authorization: `Bearer ${apiKey}`,
|
|
75
|
+
'x-env': env,
|
|
76
|
+
},
|
|
77
|
+
body: JSON.stringify({}),
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) throw new Error(`Bad response: ${response.status}`);
|
|
80
|
+
const info = showInfo ? await response.json() : undefined;
|
|
81
|
+
|
|
82
|
+
return res.send({ ok: true, info });
|
|
83
|
+
} catch (e) {
|
|
84
|
+
// @todo better logging
|
|
85
|
+
error(`error collecting bot score info: ${e.message}`);
|
|
86
|
+
return res.send({ ok: false, ...(showInfo && { info: e.message }) });
|
|
87
|
+
}
|
|
88
|
+
}));
|
|
89
|
+
|
|
90
|
+
return (_, res, next) => {
|
|
91
|
+
res.locals.$botScores = $botScores;
|
|
92
|
+
next();
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @typedef BotScores
|
|
98
|
+
* @prop {BuildFetchHeadersFn} buildFetchHeaders
|
|
99
|
+
* @prop {boolean} enabled
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* @callback BuildFetchHeadersFn
|
|
103
|
+
* @return {Record<string, string>}
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* @callback IsValidRequestPathFn
|
|
107
|
+
* @param {string} path
|
|
108
|
+
* @return {boolean}
|
|
109
|
+
*/
|
package/express/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const path = require('path');
|
|
|
7
7
|
const helmet = require('helmet');
|
|
8
8
|
const { nanoid } = require('nanoid');
|
|
9
9
|
const apollo = require('./apollo');
|
|
10
|
+
const botScores = require('./bot-scores');
|
|
10
11
|
const graphqlProxy = require('./graphql-proxy');
|
|
11
12
|
const embeddedMedia = require('./embedded-media');
|
|
12
13
|
const loadObject = require('./load-object');
|
|
@@ -116,6 +117,14 @@ module.exports = (config = {}) => {
|
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
119
|
|
|
120
|
+
// must be loaded _before_ website context
|
|
121
|
+
app.use(botScores({
|
|
122
|
+
apiKey: process.env.BOT_SCORES_API_KEY,
|
|
123
|
+
app,
|
|
124
|
+
enabled: process.env.BOT_SCORES_DISABLE !== 'true',
|
|
125
|
+
url: process.env.BOT_SCORES_URL,
|
|
126
|
+
}));
|
|
127
|
+
|
|
119
128
|
// Set website context.
|
|
120
129
|
app.use(websiteContext(app.locals.config));
|
|
121
130
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindful-web/marko-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.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": "021bf1a470ddc22990cc680dc1a218f93cd115ed"
|
|
64
64
|
}
|