@quintype/framework 7.6.1 → 7.6.2-amp-visual-story-ads.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.6.1",
|
|
3
|
+
"version": "7.6.2-amp-visual-story-ads.1",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/quintype/quintype-node-framework#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ampproject/toolbox-optimizer": "2.8.3",
|
|
34
|
-
"@quintype/amp": "
|
|
34
|
+
"@quintype/amp": "2.4.22-visual-stories-ad.0",
|
|
35
35
|
"@quintype/backend": "^2.3.1",
|
|
36
36
|
"@quintype/components": "^3.0.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.24",
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const { ampStoryPageHandler } = require("./story-page");
|
|
2
2
|
const { storyPageInfiniteScrollHandler } = require("./infinite-scroll");
|
|
3
|
-
const { bookendHandler } = require("./visual-stories-bookend");
|
|
4
3
|
|
|
5
4
|
module.exports = {
|
|
6
5
|
ampStoryPageHandler,
|
|
7
6
|
storyPageInfiniteScrollHandler,
|
|
8
|
-
bookendHandler,
|
|
9
7
|
};
|
package/server/routes.js
CHANGED
|
@@ -625,10 +625,9 @@ exports.mountQuintypeAt = function (app, mountAt) {
|
|
|
625
625
|
*
|
|
626
626
|
*/
|
|
627
627
|
exports.ampRoutes = (app, opts = {}) => {
|
|
628
|
-
const { ampStoryPageHandler, storyPageInfiniteScrollHandler
|
|
628
|
+
const { ampStoryPageHandler, storyPageInfiniteScrollHandler } = require("./amp/handlers");
|
|
629
629
|
|
|
630
630
|
getWithConfig(app, "/amp/story/*", ampStoryPageHandler, opts);
|
|
631
631
|
getWithConfig(app, "/amp/api/v1/amp-infinite-scroll", storyPageInfiniteScrollHandler, opts);
|
|
632
|
-
getWithConfig(app, "/amp/api/v1/bookend.json", bookendHandler, opts);
|
|
633
632
|
getWithConfig(app, "/ampstories/*", ampStoryPageHandler, opts);
|
|
634
633
|
};
|
|
@@ -446,41 +446,3 @@ describe("Amp infinite scroll handler", () => {
|
|
|
446
446
|
});
|
|
447
447
|
});
|
|
448
448
|
});
|
|
449
|
-
|
|
450
|
-
describe("Amp visual stories bookend handler", () => {
|
|
451
|
-
it("returns the bookend if there are related stories", function (done) {
|
|
452
|
-
const app = createApp({
|
|
453
|
-
clientStub: getClientStubWithRelatedStories([{ headline: "foo" }]),
|
|
454
|
-
});
|
|
455
|
-
supertest(app)
|
|
456
|
-
.get("/amp/api/v1/bookend.json?storyId=111§ionId=222")
|
|
457
|
-
.expect("Content-Type", /json/)
|
|
458
|
-
.expect("Cache-Control", /public/)
|
|
459
|
-
.expect(200)
|
|
460
|
-
.then((res) => {
|
|
461
|
-
const response = JSON.parse(res.text);
|
|
462
|
-
assert.equal("v1.0", response.bookendVersion);
|
|
463
|
-
assert.equal(3, response.components.length);
|
|
464
|
-
assert.equal("foo", response.components[1].title);
|
|
465
|
-
})
|
|
466
|
-
.then(() => done());
|
|
467
|
-
});
|
|
468
|
-
it("returns a 404 if there are no related stories", (done) => {
|
|
469
|
-
const app = createApp({ clientStub: getClientStubWithRelatedStories([]) });
|
|
470
|
-
supertest(app)
|
|
471
|
-
.get("/amp/api/v1/bookend.json?storyId=111§ionId=222")
|
|
472
|
-
.expect("Content-Type", /json/)
|
|
473
|
-
.expect(404)
|
|
474
|
-
.then(() => done());
|
|
475
|
-
});
|
|
476
|
-
it("returns a 400 if 'storyId' and 'sectionId' query params aren't passed", (done) => {
|
|
477
|
-
const app = createApp({
|
|
478
|
-
clientStub: getClientStubWithRelatedStories([{ headline: "foo" }]),
|
|
479
|
-
});
|
|
480
|
-
supertest(app)
|
|
481
|
-
.get("/amp/api/v1/bookend.json")
|
|
482
|
-
.expect("Content-Type", /json/)
|
|
483
|
-
.expect(400)
|
|
484
|
-
.then(() => done());
|
|
485
|
-
});
|
|
486
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const get = require("lodash/get");
|
|
2
|
-
|
|
3
|
-
function getStoryUrl(story, config) {
|
|
4
|
-
if (get(story, ["story-template"]) === "news-elsewhere") {
|
|
5
|
-
return get(story, ["metadata", "reference-url"], "");
|
|
6
|
-
}
|
|
7
|
-
return `${config["sketches-host"]}/${story.slug}`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function bookendHandler(req, res, next, { config, client, sMaxAge = "900" }) {
|
|
11
|
-
const { storyId, sectionId } = req.query;
|
|
12
|
-
if (!storyId || !sectionId) {
|
|
13
|
-
res.status(400).json({
|
|
14
|
-
error: {
|
|
15
|
-
message: "Please provide 'storyId' and 'sectionId' query parameters",
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const relatedStoriesResponse = await client.getRelatedStories(storyId, sectionId);
|
|
22
|
-
const relatedStories = relatedStoriesResponse["related-stories"];
|
|
23
|
-
|
|
24
|
-
if (!relatedStories.length) {
|
|
25
|
-
res.status(404).json({ error: { message: "Not Found" } });
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const fbAppId = get(config, ["public-integrations", "facebook", "app-id"], "");
|
|
30
|
-
|
|
31
|
-
const jsonPayLoad = {
|
|
32
|
-
bookendVersion: "v1.0",
|
|
33
|
-
shareProviders: [
|
|
34
|
-
"twitter",
|
|
35
|
-
"email",
|
|
36
|
-
{
|
|
37
|
-
provider: "facebook",
|
|
38
|
-
app_id: fbAppId,
|
|
39
|
-
},
|
|
40
|
-
"whatsapp",
|
|
41
|
-
"linkedin",
|
|
42
|
-
"gplus",
|
|
43
|
-
],
|
|
44
|
-
components: [].concat(
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
type: "heading",
|
|
48
|
-
text: "More to read",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
relatedStories.map((story) => ({
|
|
52
|
-
type: "small",
|
|
53
|
-
title: `${story.headline}`,
|
|
54
|
-
image: `${config["cdn-name"]}${story["hero-image-s3-key"]}?w=480&auto=format&compress`,
|
|
55
|
-
url: getStoryUrl(story, config),
|
|
56
|
-
})),
|
|
57
|
-
[
|
|
58
|
-
{
|
|
59
|
-
type: "cta-link",
|
|
60
|
-
links: [
|
|
61
|
-
{
|
|
62
|
-
text: "More stories",
|
|
63
|
-
url: `${config["sketches-host"]}`,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
]
|
|
68
|
-
),
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
res.header("Cache-Control", `public,max-age=15,s-maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error=14400`);
|
|
72
|
-
res.header("Vary", "Accept-Encoding");
|
|
73
|
-
|
|
74
|
-
res.json(jsonPayLoad);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = { bookendHandler };
|