@quintype/framework 7.7.5-cta-test.0 → 7.8.0-prerender-query-param.2

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/CHANGELOG.md CHANGED
@@ -2,15 +2,6 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [7.7.4](https://github.com/quintype/quintype-node-framework/compare/v7.7.3...v7.7.4) (2022-07-13)
6
-
7
- ### [7.7.3](https://github.com/quintype/quintype-node-framework/compare/v7.7.2...v7.7.3) (2022-07-13)
8
-
9
-
10
- ### Bug Fixes
11
-
12
- * remove prerender query param after the prerender check ([#314](https://github.com/quintype/quintype-node-framework/issues/314)) ([94eac28](https://github.com/quintype/quintype-node-framework/commit/94eac28bfd04483cc665c5ce4d2fc8768c84a31b))
13
-
14
5
  ### [7.7.2](https://github.com/quintype/quintype-node-framework/compare/v7.7.1...v7.7.2) (2022-07-08)
15
6
 
16
7
  ### [7.7.1](https://github.com/quintype/quintype-node-framework/compare/v7.7.0...v7.7.1) (2022-07-06)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.7.5-cta-test.0",
3
+ "version": "7.8.0-prerender-query-param.2",
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": "^2.4.26-cta.0",
34
+ "@quintype/amp": "^2.4.23",
35
35
  "@quintype/backend": "^2.3.1",
36
36
  "@quintype/components": "^3.0.0",
37
37
  "@quintype/prerender-node": "^3.2.24",
@@ -1,7 +1,9 @@
1
1
  const { ampStoryPageHandler } = require("./story-page");
2
2
  const { storyPageInfiniteScrollHandler } = require("./infinite-scroll");
3
+ const { bookendHandler } = require("./visual-stories-bookend");
3
4
 
4
5
  module.exports = {
5
6
  ampStoryPageHandler,
6
7
  storyPageInfiniteScrollHandler,
8
+ bookendHandler,
7
9
  };
@@ -0,0 +1,77 @@
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 };
package/server/routes.js CHANGED
@@ -347,6 +347,7 @@ exports.isomorphicRoutes = function isomorphicRoutes(
347
347
  if (req.query.prerender) {
348
348
  try {
349
349
  // eslint-disable-next-line global-require
350
+ prerender.set("protocol", "https");
350
351
  prerender.set("prerenderServiceUrl", prerenderServiceUrl)(req, res, next);
351
352
  } catch (e) {
352
353
  logError(e);
@@ -626,9 +627,10 @@ exports.mountQuintypeAt = function (app, mountAt) {
626
627
  *
627
628
  */
628
629
  exports.ampRoutes = (app, opts = {}) => {
629
- const { ampStoryPageHandler, storyPageInfiniteScrollHandler } = require("./amp/handlers");
630
+ const { ampStoryPageHandler, storyPageInfiniteScrollHandler, bookendHandler } = require("./amp/handlers");
630
631
 
631
632
  getWithConfig(app, "/amp/story/*", ampStoryPageHandler, opts);
632
633
  getWithConfig(app, "/amp/api/v1/amp-infinite-scroll", storyPageInfiniteScrollHandler, opts);
634
+ getWithConfig(app, "/amp/api/v1/bookend.json", bookendHandler, opts);
633
635
  getWithConfig(app, "/ampstories/*", ampStoryPageHandler, { ...opts, isVisualStory: true });
634
636
  };
@@ -446,3 +446,41 @@ 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&sectionId=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&sectionId=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
+ });