@quintype/framework 7.26.1-fw-sub-cat-404.0 → 7.26.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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
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.26.1](https://github.com/quintype/quintype-node-framework/compare/v7.26.0...v7.26.1) (2024-03-28)
6
+
5
7
  ## [7.26.0](https://github.com/quintype/quintype-node-framework/compare/v7.23.0...v7.26.0) (2024-03-21)
6
8
 
7
9
 
@@ -1,6 +1,6 @@
1
1
  #!/bin/bash -e
2
2
 
3
- npm install
3
+ npm install --legacy-peer-deps
4
4
  git diff --quiet
5
5
  npm run docs
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.26.1-fw-sub-cat-404.0",
3
+ "version": "7.26.1",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@ampproject/toolbox-optimizer": "2.8.3",
34
34
  "@quintype/amp": "^2.17.13",
35
- "@quintype/backend": "2.5.0-bk-sub-cat-404.0",
35
+ "@quintype/backend": "^2.4.0",
36
36
  "@quintype/components": "^3.5.0",
37
37
  "@quintype/prerender-node": "^3.2.26",
38
38
  "@quintype/seo": "^1.45.0",
@@ -9,7 +9,6 @@ const { optimize, getDomainSpecificOpts } = require("../helpers");
9
9
  const { storyToCacheKey } = require("../../caching");
10
10
  const { addCacheHeadersToResult } = require("../../handlers/cdn-caching");
11
11
  const { getRedirectUrl } = require("../../../server/redirect-url-helper");
12
- const { getAmpPageBasePath } = require("../helpers/get-amp-page-base-path");
13
12
 
14
13
  /**
15
14
  * ampStoryPageHandler gets all the things needed and calls "ampifyStory" function (which comes from ampLib)
@@ -41,10 +40,6 @@ async function ampStoryPageHandler(
41
40
  ) {
42
41
  try {
43
42
  const opts = cloneDeep(rest);
44
- const isCorrectAmpPath = req.path.startsWith(`${getAmpPageBasePath(opts, config)}/`);
45
- if (!isCorrectAmpPath) {
46
- return next();
47
- }
48
43
  const redirectUrls = opts && opts.redirectUrls;
49
44
  const getEnableAmp = get(opts, ["enableAmp"], true);
50
45
  const enableAmp = typeof getEnableAmp === "function" ? opts.enableAmp(config) : getEnableAmp;
@@ -52,16 +47,9 @@ async function ampStoryPageHandler(
52
47
  if (typeof redirectUrls === "function" || (redirectUrls && Object.keys(redirectUrls).length > 0)) {
53
48
  await getRedirectUrl(req, res, next, { redirectUrls, config });
54
49
  }
55
- const story = await Story.getStoryBySlug(client, req.params["0"]);
56
- const isAmpDisabled = get(story, ["metadata", "story-attributes", "disable-amp-for-single-story", "0"], "false");
57
50
 
58
- if ((!isVisualStory && !enableAmp) || isAmpDisabled === "true") {
59
- const ampPageBasePath = getAmpPageBasePath(opts, config);
60
- const redirectUrl = `/${req.params[0]}`.startsWith(ampPageBasePath)
61
- ? `/${req.params[0]}`.replace(ampPageBasePath, "")
62
- : `/${req.params[0]}`;
63
-
64
- return res.redirect(301, redirectUrl);
51
+ if (!isVisualStory && !enableAmp) {
52
+ return res.redirect(301, `/${req.params[0]}`);
65
53
  }
66
54
 
67
55
  const domainSpecificOpts = getDomainSpecificOpts(opts, domainSlug);
@@ -69,6 +57,7 @@ async function ampStoryPageHandler(
69
57
  const { ampifyStory, unsupportedStoryElementsPresent } = ampLibrary;
70
58
  // eslint-disable-next-line no-return-await
71
59
  const ampConfig = await config.memoizeAsync("amp-config", async () => await AmpConfig.getAmpConfig(client));
60
+ const story = await Story.getStoryBySlug(client, req.params["0"]);
72
61
  let relatedStoriesCollection;
73
62
  let relatedStories = [];
74
63
 
package/server/routes.js CHANGED
@@ -657,9 +657,6 @@ exports.mountQuintypeAt = function (app, mountAt) {
657
657
  * GET - "/amp/:slug"* returns amp story page
658
658
  * GET - "/amp/api/v1/amp-infinite-scroll" returns the infinite scroll config JSON. Passed to <amp-next-page> component's `src` attribute
659
659
  *
660
- * To disable amp version for a specific story, you need to create a story attribute in bold with the slug {disable-amp-for-single-story} and values {true} and {false}. Set its value to "true" in the story which you want to disable amp. Please make sure to name the attributes and values in the exact same way as mentioned
661
- * attribute slug: "disable-amp-for-single-story" values: "true" , "false". This will redirect '<amp-page-base-path>/:slug' to the non-amp page
662
- *
663
660
  * @param {Express} app Express app to add the routes to
664
661
  * @param {Object} opts Options object used to configure amp. Passing this is optional
665
662
  * @param {Object} opts.templates An object that's used to pass custom templates. Each key corresponds to the template name and corresponding value is the template
@@ -675,6 +672,6 @@ exports.ampRoutes = (app, opts = {}) => {
675
672
  const { ampStoryPageHandler, storyPageInfiniteScrollHandler } = require("./amp/handlers");
676
673
 
677
674
  getWithConfig(app, "/amp/api/v1/amp-infinite-scroll", storyPageInfiniteScrollHandler, opts);
675
+ getWithConfig(app, "/amp/*", ampStoryPageHandler, opts);
678
676
  getWithConfig(app, "/ampstories/*", ampStoryPageHandler, { ...opts, isVisualStory: true });
679
- getWithConfig(app, "/*", ampStoryPageHandler, opts);
680
677
  };
@@ -239,148 +239,12 @@ describe("ampStoryPageHandler integration tests", () => {
239
239
  return done();
240
240
  });
241
241
  });
242
- it("should redirect to non-amp page if isAmpDisabled is true", (done) => {
243
- const clientStubWithRedirectToWebVersion = () =>
244
- getClientStub({
245
- getStoryBySlug: (slug, params) =>
246
- Promise.resolve({
247
- story: {
248
- id: "1",
249
- url: "https://www.foo.com/cricket/ipl-2021",
250
- "hero-image-metadata": {
251
- width: 5472,
252
- height: 3648,
253
- "mime-type": "image/jpeg",
254
- "file-size": 6127839,
255
- "file-name": "Sample file",
256
- "focus-point": [2609, 1102],
257
- },
258
- "hero-image-s3-key": "barandbench/2020-01/sample.jpg",
259
- "story-content-id": "987c0480-41c8-41d2-ad35-36b5f92be73e",
260
- metadata: {
261
- "story-attributes": {
262
- "disable-amp-for-single-story": ["true"],
263
- },
264
- },
265
- cards: [
266
- {
267
- "story-elements": [
268
- {
269
- description: "",
270
- "page-url":
271
- "/story/7f3d5bdb-ec52-4047-ac0d-df4036ec974b/element/9eb8f5cc-6ebe-4fb0-88b8-eca79efde210",
272
- type: "text",
273
- "family-id": "e9e12f9f-8b9f-4b93-a8c8-83c7b278000f",
274
- title: "",
275
- id: "9eb8f5cc-6ebe-4fb0-88b8-eca79efde210",
276
- metadata: {},
277
- subtype: null,
278
- text: "<p>In India today, the legal profession is growing in lockstep with one of the world’s most dynamic economies. It’s no surprise then— that in terms of absolute numbers— India’s legal profession is the world’s second largest, with over 1.4 million enrolled lawyers in legal practices nationwide.</p>",
279
- },
280
- ],
281
- "card-updated-at": 1581327522163,
282
- "content-version-id": "efaf78de-c90b-4d15-b040-c84ebb29cabf",
283
- "card-added-at": 1581327522163,
284
- status: "draft",
285
- id: "bf486412-1e8b-45d1-a5fd-51939cfe1ce1",
286
- "content-id": "bf486412-1e8b-45d1-a5fd-51939cfe1ce1",
287
- version: 1,
288
- metadata: {},
289
- },
290
- ],
291
- sections: [{ id: 1, name: "Sports" }],
292
- "story-template": "text",
293
- "is-amp-supported": true,
294
- },
295
- }),
296
- });
297
- const app = createApp({
298
- clientStub: clientStubWithRedirectToWebVersion,
299
- enableAmp: true,
300
- });
301
- supertest(app)
302
- .get("/amp/story/cricket/ipl-2021")
303
- .expect(301)
304
- .expect("Location", "/cricket/ipl-2021")
305
- .end((err) => {
306
- if (err) return done(err);
307
- return done();
308
- });
309
- });
310
- it("should show amp page if isAmpDisabled is false", (done) => {
311
- const clientStubWithRedirectToWebVersion = () =>
312
- getClientStub({
313
- getStoryBySlug: (slug, params) =>
314
- Promise.resolve({
315
- story: {
316
- id: "1",
317
- url: "https://www.foo.com/cricket/ipl-2021",
318
- "hero-image-metadata": {
319
- width: 5472,
320
- height: 3648,
321
- "mime-type": "image/jpeg",
322
- "file-size": 6127839,
323
- "file-name": "Sample file",
324
- "focus-point": [2609, 1102],
325
- },
326
- "hero-image-s3-key": "barandbench/2020-01/sample.jpg",
327
- "story-content-id": "987c0480-41c8-41d2-ad35-36b5f92be73e",
328
- metadata: {
329
- "story-attributes": {
330
- "disable-amp-for-single-story": ["false"],
331
- },
332
- },
333
- cards: [
334
- {
335
- "story-elements": [
336
- {
337
- description: "",
338
- "page-url":
339
- "/story/7f3d5bdb-ec52-4047-ac0d-df4036ec974b/element/9eb8f5cc-6ebe-4fb0-88b8-eca79efde210",
340
- type: "text",
341
- "family-id": "e9e12f9f-8b9f-4b93-a8c8-83c7b278000f",
342
- title: "",
343
- id: "9eb8f5cc-6ebe-4fb0-88b8-eca79efde210",
344
- metadata: {},
345
- subtype: null,
346
- text: "<p>In India today, the legal profession is growing in lockstep with one of the world’s most dynamic economies. It’s no surprise then— that in terms of absolute numbers— India’s legal profession is the world’s second largest, with over 1.4 million enrolled lawyers in legal practices nationwide.</p>",
347
- },
348
- ],
349
- "card-updated-at": 1581327522163,
350
- "content-version-id": "efaf78de-c90b-4d15-b040-c84ebb29cabf",
351
- "card-added-at": 1581327522163,
352
- status: "draft",
353
- id: "bf486412-1e8b-45d1-a5fd-51939cfe1ce1",
354
- "content-id": "bf486412-1e8b-45d1-a5fd-51939cfe1ce1",
355
- version: 1,
356
- metadata: {},
357
- },
358
- ],
359
- sections: [{ id: 1, name: "Sports" }],
360
- "story-template": "text",
361
- "is-amp-supported": true,
362
- },
363
- }),
364
- });
365
- const app = createApp({
366
- clientStub: clientStubWithRedirectToWebVersion,
367
- enableAmp: true,
368
- });
369
- supertest(app)
370
- .get("/amp/story/cricket/ipl-2021")
371
- .expect("Content-Type", /html/)
372
- .expect(200)
373
- .end((err) => {
374
- if (err) return done(err);
375
- return done();
376
- });
377
- });
378
242
  it("should redirect to non-amp page if enableAmp is false", (done) => {
379
243
  const app = createApp({
380
244
  enableAmp: false,
381
245
  });
382
246
  supertest(app)
383
- .get("/amp/story/cricket/ipl-2021")
247
+ .get("/amp/cricket/ipl-2021")
384
248
  .expect(301)
385
249
  .expect("Location", "/cricket/ipl-2021")
386
250
  .end((err) => {
@@ -36,7 +36,6 @@ function getClientStub({
36
36
  const dummyReq = {
37
37
  url: "foo",
38
38
  params: "/story/slug",
39
- path: "/amp/story/slug",
40
39
  };
41
40
  const dummyRes = {
42
41
  redirect: () => null,