@quintype/framework 7.7.6 → 7.7.8-custom-inifinite-scroller.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,14 @@
|
|
|
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.7](https://github.com/quintype/quintype-node-framework/compare/v7.7.0...v7.7.7) (2022-07-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* 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))
|
|
11
|
+
* 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))
|
|
12
|
+
|
|
5
13
|
### [7.7.6](https://github.com/quintype/quintype-node-framework/compare/v7.7.5...v7.7.6) (2022-07-28)
|
|
6
14
|
|
|
7
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.7.
|
|
3
|
+
"version": "7.7.8-custom-inifinite-scroller.1",
|
|
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 --
|
|
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,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.
|
|
34
|
+
"@quintype/amp": "^2.4.29-custom-infinite-scroll.1",
|
|
35
35
|
"@quintype/backend": "^2.3.1",
|
|
36
36
|
"@quintype/components": "^3.0.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.26",
|
|
@@ -86,15 +86,23 @@ 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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
const infiniteScroll = get(opts, ["featureConfig", "infiniteScroll"], "");
|
|
90
|
+
let infiniteScrollInlineConfig = [];
|
|
91
|
+
|
|
92
|
+
if (infiniteScroll.source === "custom") {
|
|
93
|
+
infiniteScrollInlineConfig = await infiniteScroll.inlineConfig({ offset: 0, limit: 5 });
|
|
94
|
+
} else {
|
|
95
|
+
const infiniteScrollAmp = new InfiniteScrollAmp({
|
|
96
|
+
ampConfig,
|
|
97
|
+
publisherConfig: config,
|
|
98
|
+
client,
|
|
99
|
+
infiniteScroll,
|
|
100
|
+
});
|
|
101
|
+
infiniteScrollInlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
102
|
+
itemsToTake: 5,
|
|
103
|
+
story: story,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
98
106
|
if (infiniteScrollInlineConfig instanceof Error) return next(infiniteScrollInlineConfig);
|
|
99
107
|
if (infiniteScrollInlineConfig) {
|
|
100
108
|
set(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
class InfiniteScrollAmp {
|
|
2
|
-
constructor({ ampConfig, client, publisherConfig, queryParams }) {
|
|
2
|
+
constructor({ ampConfig, client, publisherConfig, queryParams, infiniteScroll }) {
|
|
3
3
|
this.client = client;
|
|
4
4
|
this.publisherConfig = publisherConfig;
|
|
5
5
|
this.queryParams = queryParams;
|
|
6
|
-
this.
|
|
6
|
+
this.infiniteScroll = infiniteScroll;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -17,6 +17,14 @@ class InfiniteScrollAmp {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
getFilteredApiItems(relatedStories) {
|
|
21
|
+
return relatedStories.filter(
|
|
22
|
+
(story) =>
|
|
23
|
+
story.access !== "subscription" &&
|
|
24
|
+
story["story-template"] !== "visual-story"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
formatData({ itemsArr, type }) {
|
|
21
29
|
// formats configuration as per need of amp infinite scroll
|
|
22
30
|
const arr = itemsArr.map((item) => ({
|
|
@@ -44,31 +52,46 @@ class InfiniteScrollAmp {
|
|
|
44
52
|
async getResponse({ itemsTaken }) {
|
|
45
53
|
const { "story-id": storyId } = this.queryParams;
|
|
46
54
|
if (!storyId) return new Error(`Query param "story-id" missing`);
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
let filteredItems = [];
|
|
56
|
+
const sourceType = this.infiniteScroll && this.infiniteScroll.source;
|
|
57
|
+
if (sourceType === "relatedStoriesApi") {
|
|
58
|
+
const story = await this.client.getStoryById(storyId);
|
|
59
|
+
const relatedStoriesList = await story.getRelatedStories(this.client);
|
|
60
|
+
if (!relatedStoriesList)
|
|
61
|
+
return new Error(`RelatedStories List returned falsy value`);
|
|
62
|
+
filteredItems = this.getFilteredApiItems(relatedStoriesList);
|
|
63
|
+
} else {
|
|
64
|
+
const collection = await this.client.getCollectionBySlug("amp-infinite-scroll");
|
|
65
|
+
if (!collection || collection.error)
|
|
66
|
+
return new Error(`Infinite scroll collection amp-infinite-scroll returned falsy value`);
|
|
67
|
+
filteredItems = this.getFilteredCollItems(collection, storyId);
|
|
68
|
+
}
|
|
52
69
|
const slicedItems = filteredItems.slice(itemsTaken);
|
|
53
70
|
const formattedData = this.formatData({ itemsArr: slicedItems });
|
|
54
|
-
|
|
55
71
|
return JSON.stringify(formattedData);
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
async getInitialInlineConfig({ itemsToTake,
|
|
74
|
+
async getInitialInlineConfig({ itemsToTake, story }) {
|
|
75
|
+
const storyId = story && story["story-content-id"];
|
|
59
76
|
if (!itemsToTake || !storyId) return new Error("Required params for getInitialInlineConfig missing");
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
77
|
+
const sourceType = this.infiniteScroll && this.infiniteScroll.source;
|
|
78
|
+
let filteredItems = [];
|
|
79
|
+
if (sourceType === "relatedStoriesApi") {
|
|
80
|
+
const relatedStoriesList = await story.getRelatedStories(this.client);
|
|
81
|
+
if (!relatedStoriesList)
|
|
82
|
+
return new Error(`RelatedStories List returned falsy value`);
|
|
83
|
+
filteredItems = this.getFilteredApiItems(relatedStoriesList);
|
|
84
|
+
} else {
|
|
85
|
+
const collection = await this.client.getCollectionBySlug("amp-infinite-scroll");
|
|
86
|
+
if (!collection || (collection.items && !collection.items.length) || collection.error) return null;
|
|
87
|
+
filteredItems = this.getFilteredCollItems(collection, storyId);
|
|
88
|
+
}
|
|
64
89
|
const slicedItems = filteredItems.slice(0, itemsToTake);
|
|
65
90
|
const formattedData = this.formatData({
|
|
66
91
|
itemsArr: slicedItems,
|
|
67
92
|
type: "inline",
|
|
68
93
|
});
|
|
69
|
-
|
|
70
94
|
return JSON.stringify(formattedData);
|
|
71
95
|
}
|
|
72
96
|
}
|
|
73
|
-
|
|
74
97
|
module.exports = InfiniteScrollAmp;
|
|
@@ -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")
|
|
@@ -83,6 +92,7 @@ function getClientStub({
|
|
|
83
92
|
} = {}) {
|
|
84
93
|
return {
|
|
85
94
|
getCollectionBySlug,
|
|
95
|
+
getStoryById
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
98
|
const dummyPublisherConfig = {
|
|
@@ -118,7 +128,13 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
118
128
|
});
|
|
119
129
|
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
120
130
|
itemsToTake: 5,
|
|
121
|
-
|
|
131
|
+
story: {
|
|
132
|
+
"story-template": "text",
|
|
133
|
+
headline: "aaa",
|
|
134
|
+
"story-content-id": 1111,
|
|
135
|
+
slug: "sports/aa",
|
|
136
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
137
|
+
},
|
|
122
138
|
});
|
|
123
139
|
assert.strictEqual(inlineConfig, null);
|
|
124
140
|
});
|
|
@@ -138,7 +154,13 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
138
154
|
});
|
|
139
155
|
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
140
156
|
itemsToTake: 5,
|
|
141
|
-
|
|
157
|
+
story: {
|
|
158
|
+
"story-template": "text",
|
|
159
|
+
headline: "aaa",
|
|
160
|
+
"story-content-id": 1111,
|
|
161
|
+
slug: "sports/aa",
|
|
162
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
163
|
+
},
|
|
142
164
|
});
|
|
143
165
|
assert.strictEqual(inlineConfig, null);
|
|
144
166
|
});
|
|
@@ -151,7 +173,13 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
151
173
|
});
|
|
152
174
|
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
153
175
|
itemsToTake: 5,
|
|
154
|
-
|
|
176
|
+
story: {
|
|
177
|
+
"story-template": "text",
|
|
178
|
+
headline: "aaa",
|
|
179
|
+
"story-content-id": 1111,
|
|
180
|
+
slug: "sports/aa",
|
|
181
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
182
|
+
},
|
|
155
183
|
});
|
|
156
184
|
assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
|
|
157
185
|
assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
|
|
@@ -165,7 +193,13 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
165
193
|
});
|
|
166
194
|
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
167
195
|
itemsToTake: 5,
|
|
168
|
-
|
|
196
|
+
story: {
|
|
197
|
+
"story-template": "text",
|
|
198
|
+
headline: "aaa",
|
|
199
|
+
"story-content-id": 1111,
|
|
200
|
+
slug: "sports/aa",
|
|
201
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
202
|
+
},
|
|
169
203
|
});
|
|
170
204
|
assert.strictEqual(false, /sports\/bb/.test(inlineConfig));
|
|
171
205
|
assert.strictEqual(false, /bb\/b.jpg/.test(inlineConfig));
|
|
@@ -180,7 +214,13 @@ describe("getInitialInlineConfig method of InfiniteScrollAmp helper function", f
|
|
|
180
214
|
});
|
|
181
215
|
const inlineConfig = await infiniteScrollAmp.getInitialInlineConfig({
|
|
182
216
|
itemsToTake: 5,
|
|
183
|
-
|
|
217
|
+
story: {
|
|
218
|
+
"story-template": "text",
|
|
219
|
+
headline: "aaa",
|
|
220
|
+
"story-content-id": 1111,
|
|
221
|
+
slug: "sports/aa",
|
|
222
|
+
"hero-image-s3-key": "aa/a.jpg",
|
|
223
|
+
},
|
|
184
224
|
});
|
|
185
225
|
function isInlineConfigStructureValid(jsonStr) {
|
|
186
226
|
const stories = JSON.parse(jsonStr);
|
|
@@ -225,6 +265,7 @@ describe("getResponse method of InfiniteScrollAmp helper function", function ()
|
|
|
225
265
|
client: clientStub,
|
|
226
266
|
publisherConfig: dummyPublisherConfig,
|
|
227
267
|
queryParams: { "story-id": 2222 },
|
|
268
|
+
infiniteScroll: { "source": "" }
|
|
228
269
|
});
|
|
229
270
|
const jsonResponse = await infiniteScrollAmp.getResponse({ itemsTaken: 2 });
|
|
230
271
|
assert.strictEqual(jsonResponse instanceof Error, true);
|