@quintype/framework 7.8.0-remove-prerender-param.0 → 7.9.0-custom-inifinite-scroller.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/CHANGELOG.md CHANGED
@@ -2,6 +2,39 @@
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.8.0](https://github.com/quintype/quintype-node-framework/compare/v7.7.7...v7.8.0) (2022-09-19)
6
+
7
+
8
+ ### Features
9
+
10
+ * add video support to web stories ([#322](https://github.com/quintype/quintype-node-framework/issues/322)) ([f41b82b](https://github.com/quintype/quintype-node-framework/commit/f41b82be8285b555970527204ec6478f21c47782))
11
+
12
+ ### [7.7.7](https://github.com/quintype/quintype-node-framework/compare/v7.7.0...v7.7.7) (2022-07-29)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * 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))
18
+ * remove prerender query param after the prerender check [#314](https://github.com/quintype/quintype-node-framework/issues/314) ([#317](https://github.com/quintype/quintype-node-framework/issues/317)) ([0067d81](https://github.com/quintype/quintype-node-framework/commit/0067d81fe545a726948db14a44768876b41f6ba8))
19
+
20
+ ### [7.7.6](https://github.com/quintype/quintype-node-framework/compare/v7.7.5...v7.7.6) (2022-07-28)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * remove prerender query param after the prerender check [#314](https://github.com/quintype/quintype-node-framework/issues/314) ([#317](https://github.com/quintype/quintype-node-framework/issues/317)) ([0067d81](https://github.com/quintype/quintype-node-framework/commit/0067d81fe545a726948db14a44768876b41f6ba8))
26
+
27
+ ### [7.7.5](https://github.com/quintype/quintype-node-framework/compare/v7.7.4...v7.7.5) (2022-07-14)
28
+
29
+ ### [7.7.4](https://github.com/quintype/quintype-node-framework/compare/v7.7.3...v7.7.4) (2022-07-13)
30
+
31
+ ### [7.7.3](https://github.com/quintype/quintype-node-framework/compare/v7.7.2...v7.7.3) (2022-07-13)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * 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))
37
+
5
38
  ### [7.7.2](https://github.com/quintype/quintype-node-framework/compare/v7.7.1...v7.7.2) (2022-07-08)
6
39
 
7
40
  ### [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.8.0-remove-prerender-param.0",
3
+ "version": "7.9.0-custom-inifinite-scroller.0",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "prepublishOnly": "npm test && ./bin-dev-scripts/standard-version-release.sh",
12
- "test": "NODE_ENV=test npx mocha --timeout 5000 --recursive --require ./test/babel",
12
+ "test": "NODE_ENV=test npx mocha --recursive --require ./test/babel",
13
13
  "watch-test": "NODE_ENV=test npx mocha --recursive --watch --require ./test/babel",
14
14
  "coverage": "nyc --all npm test",
15
15
  "coverage-html": "nyc --all --reporter=html npm test",
@@ -31,10 +31,10 @@
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.23",
35
- "@quintype/backend": "^2.3.1",
34
+ "@quintype/amp": "2.6.0-custom-infinite-scroll.0",
35
+ "@quintype/backend": "2.3.2-related-stories-inf-scroll.3",
36
36
  "@quintype/components": "^3.0.0",
37
- "@quintype/prerender-node": "^3.2.24",
37
+ "@quintype/prerender-node": "^3.2.26",
38
38
  "@quintype/seo": "^1.39.0",
39
39
  "atob": "^2.1.2",
40
40
  "babel-plugin-react-css-modules": "^5.2.6",
@@ -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
  };
@@ -12,7 +12,7 @@ async function storyPageInfiniteScrollHandler(req, res, next, { client, config }
12
12
  client,
13
13
  queryParams: req.query,
14
14
  });
15
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 5 }); // itemsTaken has to match with itemsToTake in ampStoryPageHandler
15
+ const jsonResponse = await infiniteScrollAmp.getResponse();
16
16
  if (jsonResponse instanceof Error) return next(jsonResponse);
17
17
  res.set("Content-Type", "application/json; charset=utf-8");
18
18
  setCorsHeaders({ req, res, next, publisherConfig: config });
@@ -86,15 +86,29 @@ async function ampStoryPageHandler(
86
86
  const seoTags =
87
87
  seoInstance && seoInstance.getMetaTags(config, "story-page-amp", { data: { story, timezone }, config }, { url });
88
88
 
89
- const infiniteScrollAmp = new InfiniteScrollAmp({
90
- ampConfig,
91
- publisherConfig: config,
92
- client,
93
- });
94
- const infiniteScrollInlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
95
- itemsToTake: 5,
96
- storyId: story["story-content-id"],
97
- });
89
+ const infiniteScrollConfig = get(opts, ["featureConfig", "infiniteScroll"], "");
90
+ const infiniteScrollSource = get(infiniteScrollConfig, ["source"], "collection");
91
+ const inlineConfig = get(infiniteScrollConfig, ["inlineConfig"], "");
92
+ const remoteConfigEndpoint = get(infiniteScrollConfig, ["remoteConfigEndpoint"], "");
93
+
94
+ let infiniteScrollInlineConfig = [];
95
+
96
+ if (infiniteScrollSource === "custom") {
97
+ if (!inlineConfig || !remoteConfigEndpoint)
98
+ throw new Error("Required params of 'custom' source (inlineConfig /remoteConfigEndpoint) is missing!!");
99
+ infiniteScrollInlineConfig = await inlineConfig();
100
+ } else {
101
+ const infiniteScrollAmp = new InfiniteScrollAmp({
102
+ story,
103
+ ampConfig,
104
+ publisherConfig: config,
105
+ client,
106
+ infiniteScrollSource,
107
+ });
108
+ infiniteScrollInlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
109
+ storyId: story["story-content-id"],
110
+ });
111
+ }
98
112
  if (infiniteScrollInlineConfig instanceof Error) return next(infiniteScrollInlineConfig);
99
113
  if (infiniteScrollInlineConfig) {
100
114
  set(
@@ -1,9 +1,10 @@
1
1
  class InfiniteScrollAmp {
2
- constructor({ ampConfig, client, publisherConfig, queryParams }) {
2
+ constructor({ story, ampConfig, client, publisherConfig, queryParams, infiniteScrollSource }) {
3
+ this.story = story;
3
4
  this.client = client;
4
5
  this.publisherConfig = publisherConfig;
5
6
  this.queryParams = queryParams;
6
- this.collSlug = "amp-infinite-scroll"; // this is hardcoded to "amp-infinite-scroll" temporarily. Ideally it should come from ampConfig from platform
7
+ this.infiniteScrollSource = infiniteScrollSource;
7
8
  }
8
9
 
9
10
  // eslint-disable-next-line class-methods-use-this
@@ -17,6 +18,14 @@ class InfiniteScrollAmp {
17
18
  );
18
19
  }
19
20
 
21
+ getFilteredApiItems(relatedStories) {
22
+ return relatedStories.filter(
23
+ (story) =>
24
+ story.access !== "subscription" &&
25
+ story["story-template"] !== "visual-story"
26
+ );
27
+ }
28
+
20
29
  formatData({ itemsArr, type }) {
21
30
  // formats configuration as per need of amp infinite scroll
22
31
  const arr = itemsArr.map((item) => ({
@@ -41,34 +50,42 @@ class InfiniteScrollAmp {
41
50
  return `${hostWithProtocol}/${s3Key}?format=webp&w=250`;
42
51
  }
43
52
 
44
- async getResponse({ itemsTaken }) {
53
+ async getInfiniteScrollList(storyId, offset, limit) {
54
+ let filteredItems = [];
55
+ const params = { offset, limit };
56
+ if (this.infiniteScrollSource === "relatedStoriesApi") {
57
+ const relatedStoriesList = await this.story.getRelatedStories(this.client, params);
58
+ if (!relatedStoriesList)
59
+ return new Error();
60
+ return filteredItems = this.getFilteredApiItems(relatedStoriesList);
61
+ } else {
62
+ const collection = await this.client.getCollectionBySlug("amp-infinite-scroll");
63
+ if (!collection || (collection.items && !collection.items.length) || collection.error || collection === null)
64
+ return new Error();
65
+ return filteredItems = this.getFilteredCollItems(collection, storyId);
66
+ }
67
+ }
68
+
69
+ async getResponse() {
45
70
  const { "story-id": storyId } = this.queryParams;
46
71
  if (!storyId) return new Error(`Query param "story-id" missing`);
47
-
48
- const collection = await this.client.getCollectionBySlug(this.collSlug);
49
- if (!collection || collection.error)
50
- return new Error(`Infinite scroll collection ${this.collSlug} returned falsy value`);
51
- const filteredItems = this.getFilteredCollItems(collection, storyId);
52
- const slicedItems = filteredItems.slice(itemsTaken);
72
+ const filteredItems = await this.getInfiniteScrollList(storyId, 5);
73
+ if (filteredItems instanceof Error) return new Error(`Infinite scroll collection amp-infinite-scroll returned falsy value`);
74
+ const slicedItems = filteredItems.slice(5);
53
75
  const formattedData = this.formatData({ itemsArr: slicedItems });
54
-
55
76
  return JSON.stringify(formattedData);
56
77
  }
57
78
 
58
- async getInitialInlineConfig({ itemsToTake, storyId }) {
59
- if (!itemsToTake || !storyId) return new Error("Required params for getInitialInlineConfig missing");
60
-
61
- const collection = await this.client.getCollectionBySlug(this.collSlug);
62
- if (!collection || (collection.items && !collection.items.length) || collection.error) return null;
63
- const filteredItems = this.getFilteredCollItems(collection, storyId);
64
- const slicedItems = filteredItems.slice(0, itemsToTake);
65
- const formattedData = this.formatData({
79
+ async getInitialInlineConfig(storyId) {
80
+ if (!storyId) return new Error("Required params for getInitialInlineConfig missing");
81
+ const filteredItems = await this.getInfiniteScrollList(storyId, 0, 5);
82
+ if (filteredItems instanceof Error) return null;
83
+ const slicedItems = filteredItems.slice(0, 5);
84
+ const formattedData = slicedItems.length > 0 && this.formatData({
66
85
  itemsArr: slicedItems,
67
86
  type: "inline",
68
87
  });
69
-
70
88
  return JSON.stringify(formattedData);
71
89
  }
72
90
  }
73
-
74
91
  module.exports = InfiniteScrollAmp;
package/server/routes.js CHANGED
@@ -345,9 +345,9 @@ exports.isomorphicRoutes = function isomorphicRoutes(
345
345
  if (prerenderServiceUrl) {
346
346
  app.use((req, res, next) => {
347
347
  if (req.query.prerender) {
348
- delete req.query.prerender;
349
348
  try {
350
349
  // eslint-disable-next-line global-require
350
+ prerender.set("protocol", "https");
351
351
  prerender.set("prerenderServiceUrl", prerenderServiceUrl)(req, res, next);
352
352
  } catch (e) {
353
353
  logError(e);
@@ -627,10 +627,9 @@ exports.mountQuintypeAt = function (app, mountAt) {
627
627
  *
628
628
  */
629
629
  exports.ampRoutes = (app, opts = {}) => {
630
- const { ampStoryPageHandler, storyPageInfiniteScrollHandler, bookendHandler } = require("./amp/handlers");
630
+ const { ampStoryPageHandler, storyPageInfiniteScrollHandler } = require("./amp/handlers");
631
631
 
632
632
  getWithConfig(app, "/amp/story/*", ampStoryPageHandler, opts);
633
633
  getWithConfig(app, "/amp/api/v1/amp-infinite-scroll", storyPageInfiniteScrollHandler, opts);
634
- getWithConfig(app, "/amp/api/v1/bookend.json", bookendHandler, opts);
635
634
  getWithConfig(app, "/ampstories/*", ampStoryPageHandler, { ...opts, isVisualStory: true });
636
635
  };
@@ -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&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
- });
@@ -3,8 +3,17 @@
3
3
 
4
4
  const assert = require("assert");
5
5
  const InfiniteScrollAmp = require("../../../server/amp/helpers/infinite-scroll");
6
+ const { getTextStory } = require("../../data/amp-test-data");
6
7
 
7
8
  function getClientStub({
9
+ getStoryById = (id) =>
10
+ new Promise((resolve) => {
11
+ if (id === "4444")
12
+ resolve({
13
+ story: getTextStory({ "story-content-id": "7f3d5bdb-ec52-4047-ac0d-df4036ec974b" }),
14
+ });
15
+ resolve(null);
16
+ }),
8
17
  getCollectionBySlug = (slug) =>
9
18
  new Promise((resolve) => {
10
19
  if (slug === "amp-infinite-scroll")
@@ -19,6 +28,7 @@ function getClientStub({
19
28
  "story-content-id": 1111,
20
29
  slug: "sports/aa",
21
30
  "hero-image-s3-key": "aa/a.jpg",
31
+ access: "public",
22
32
  },
23
33
  },
24
34
  {
@@ -30,6 +40,7 @@ function getClientStub({
30
40
  "story-content-id": 2222,
31
41
  slug: "sports/bb",
32
42
  "hero-image-s3-key": "bb/b.jpg",
43
+ access: "public",
33
44
  },
34
45
  },
35
46
  {
@@ -41,6 +52,7 @@ function getClientStub({
41
52
  "story-content-id": 3333,
42
53
  slug: "sports/cc",
43
54
  "hero-image-s3-key": "cc/c.jpg",
55
+ access: "public",
44
56
  },
45
57
  },
46
58
  {
@@ -52,6 +64,7 @@ function getClientStub({
52
64
  "story-content-id": 4444,
53
65
  slug: "sports/dd",
54
66
  "hero-image-s3-key": "dd/d.jpg",
67
+ access: "public",
55
68
  },
56
69
  },
57
70
  {
@@ -63,6 +76,7 @@ function getClientStub({
63
76
  "story-content-id": 5555,
64
77
  slug: "sports/ee",
65
78
  "hero-image-s3-key": "ee/e.jpg",
79
+ access: "public",
66
80
  },
67
81
  },
68
82
  {
@@ -74,6 +88,31 @@ function getClientStub({
74
88
  "story-content-id": 6666,
75
89
  slug: "sports/ff",
76
90
  "hero-image-s3-key": "ff/f.jpg",
91
+ access: "public",
92
+ },
93
+ },
94
+ {
95
+ type: "story",
96
+ id: 7777,
97
+ story: {
98
+ "story-template": "text",
99
+ headline: "ggg",
100
+ "story-content-id": 7777,
101
+ slug: "sports/gg",
102
+ "hero-image-s3-key": "gg/g.jpg",
103
+ access: "public",
104
+ },
105
+ },
106
+ {
107
+ type: "story",
108
+ id: 8888,
109
+ story: {
110
+ "story-template": "text",
111
+ headline: "hhh",
112
+ "story-content-id": 8888,
113
+ slug: "sports/hh",
114
+ "hero-image-s3-key": "hh/h.jpg",
115
+ access: "public",
77
116
  },
78
117
  },
79
118
  ],
@@ -83,6 +122,7 @@ function getClientStub({
83
122
  } = {}) {
84
123
  return {
85
124
  getCollectionBySlug,
125
+ getStoryById
86
126
  };
87
127
  }
88
128
  const dummyPublisherConfig = {
@@ -96,9 +136,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
96
136
  client: getClientStub(),
97
137
  publisherConfig: dummyPublisherConfig,
98
138
  });
99
- const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
100
- itemsToTake: 5,
101
- });
139
+ const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig();
102
140
  assert.strictEqual(inlineConfig instanceof Error, true);
103
141
  assert.throws(() => {
104
142
  throw new Error("Required params for getInitialInlineConfig missing");
@@ -117,8 +155,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
117
155
  publisherConfig: dummyPublisherConfig,
118
156
  });
119
157
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
120
- itemsToTake: 5,
121
- storyId: 2222,
158
+ storyId: 1111,
122
159
  });
123
160
  assert.strictEqual(inlineConfig, null);
124
161
  });
@@ -137,8 +174,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
137
174
  publisherConfig: dummyPublisherConfig,
138
175
  });
139
176
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
140
- itemsToTake: 5,
141
- storyId: 2222,
177
+ storyId: 1111,
142
178
  });
143
179
  assert.strictEqual(inlineConfig, null);
144
180
  });
@@ -150,8 +186,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
150
186
  publisherConfig: dummyPublisherConfig,
151
187
  });
152
188
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
153
- itemsToTake: 5,
154
- storyId: 2222,
189
+ storyId: 1111,
155
190
  });
156
191
  assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
157
192
  assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
@@ -164,8 +199,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
164
199
  publisherConfig: dummyPublisherConfig,
165
200
  });
166
201
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
167
- itemsToTake: 5,
168
- storyId: 3333,
202
+ storyId: 1111,
169
203
  });
170
204
  assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
171
205
  assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
@@ -179,8 +213,7 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
179
213
  publisherConfig: dummyPublisherConfig,
180
214
  });
181
215
  const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
182
- itemsToTake: 5,
183
- storyId: 2222,
216
+ storyId: 1111,
184
217
  });
185
218
  function isInlineConfigStructureValid(jsonStr) {
186
219
  const stories = JSON.parse(jsonStr);
@@ -207,7 +240,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
207
240
  publisherConfig: dummyPublisherConfig,
208
241
  queryParams: { foo: "bar" },
209
242
  });
210
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
243
+ const jsonResponse = await infiniteScrollAmp.getResponse();
211
244
  assert.strictEqual(jsonResponse instanceof Error, true);
212
245
  assert.throws(() => {
213
246
  throw new Error(`Query param "story-id" missing`);
@@ -226,7 +259,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
226
259
  publisherConfig: dummyPublisherConfig,
227
260
  queryParams: { "story-id": 2222 },
228
261
  });
229
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
262
+ const jsonResponse = await infiniteScrollAmp.getResponse();
230
263
  assert.strictEqual(jsonResponse instanceof Error, true);
231
264
  });
232
265
  it("should remove current story from response", async function () {
@@ -237,7 +270,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
237
270
  publisherConfig: dummyPublisherConfig,
238
271
  queryParams: { "story-id": 4444 },
239
272
  });
240
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
273
+ const jsonResponse = await infiniteScrollAmp.getResponse();
241
274
  assert.strictEqual(false, /sports\/dd/.test(jsonResponse));
242
275
  assert.strictEqual(false, /dd\/d.jpg/.test(jsonResponse));
243
276
  });
@@ -249,7 +282,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
249
282
  publisherConfig: dummyPublisherConfig,
250
283
  queryParams: { "story-id": 4444 },
251
284
  });
252
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
285
+ const jsonResponse = await infiniteScrollAmp.getResponse();
253
286
  assert.strictEqual(false, /sports\/bb/.test(jsonResponse));
254
287
  assert.strictEqual(false, /bb\/b.jpg/.test(jsonResponse));
255
288
  });
@@ -262,7 +295,8 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
262
295
  publisherConfig: dummyPublisherConfig,
263
296
  queryParams: { "story-id": 4444 },
264
297
  });
265
- const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
298
+ const jsonResponse = await infiniteScrollAmp.getResponse();
299
+
266
300
  function isJsonConfigStructureValid(jsonStr) {
267
301
  const parsed = JSON.parse(jsonStr);
268
302
  const stories = parsed.pages;
@@ -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 };