@quintype/framework 7.22.1-stories-by-external-id.6 → 7.23.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,13 @@
|
|
|
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.23.0](https://github.com/quintype/quintype-node-framework/compare/v7.22.0...v7.23.0) (2024-01-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **external id:** add support to retrieve stories with external ids ([#406](https://github.com/quintype/quintype-node-framework/issues/406)) ([a13b281](https://github.com/quintype/quintype-node-framework/commit/a13b281bb9e4aaaf28b0b01355f9937b74cb3be8))
|
|
11
|
+
|
|
5
12
|
## [7.22.0](https://github.com/quintype/quintype-node-framework/compare/v7.21.2...v7.22.0) (2023-12-01)
|
|
6
13
|
|
|
7
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.23.0",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@ampproject/toolbox-optimizer": "2.8.3",
|
|
34
34
|
"@quintype/amp": "^2.17.13",
|
|
35
35
|
"@quintype/backend": "^2.3.4",
|
|
36
|
-
"@quintype/components": "^3.
|
|
36
|
+
"@quintype/components": "^3.5.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.26",
|
|
38
38
|
"@quintype/seo": "^1.43.0-config-amp-story-path.1",
|
|
39
39
|
"atob": "^2.1.2",
|
|
@@ -84,15 +84,11 @@ function loadDataForIsomorphicRoute(
|
|
|
84
84
|
return result;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
const isExternalStoryEnabled =
|
|
87
|
+
const isExternalStoryEnabled =
|
|
88
|
+
typeof enableExternalStories === "function" ? enableExternalStories(config) : enableExternalStories;
|
|
88
89
|
if (isExternalStoryEnabled) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
return url.split("/")[index];
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const pattern = typeof externalIdPattern === "function" ? externalIdPattern(config) : externalIdPattern
|
|
95
|
-
const externalId = getExternalIdFromUrl(pattern, url.pathname);
|
|
90
|
+
const pattern = typeof externalIdPattern === "function" ? externalIdPattern(config) : externalIdPattern;
|
|
91
|
+
const externalId = url.pathname.split("/")[pattern.split("/").findIndex((e) => e === "EXTERNAL_ID")];
|
|
96
92
|
const story = await Story.getStoryByExternalId(client, externalId);
|
|
97
93
|
if (story) {
|
|
98
94
|
const params = Object.assign({}, url.query, otherParams, { storySlug: story.slug });
|
|
@@ -915,36 +915,79 @@ describe("Isomorphic Handler", function () {
|
|
|
915
915
|
});
|
|
916
916
|
|
|
917
917
|
describe("External Stories", () => {
|
|
918
|
-
it("when external stories are enabled and the route matches
|
|
918
|
+
it("should render the story page when external stories are enabled and the route matches", (done) => {
|
|
919
919
|
const app = createApp(
|
|
920
920
|
(pageType, params, config, client, { host }) =>
|
|
921
921
|
Promise.resolve({
|
|
922
922
|
pageType,
|
|
923
923
|
data: { text: "foobar", host },
|
|
924
924
|
}),
|
|
925
|
-
[{ pageType: "story-page", path: "
|
|
926
|
-
{
|
|
927
|
-
|
|
925
|
+
[{ pageType: "story-page", path: "/*/:storySlug" }],
|
|
926
|
+
{
|
|
927
|
+
enableExternalStories: true,
|
|
928
|
+
externalIdPattern: "/EXTERNAL_ID",
|
|
929
|
+
getClient: (hostname) => ({
|
|
930
|
+
getConfig: () => Promise.resolve({ "publisher-id": 42 }),
|
|
931
|
+
getStoryByExternalId: (externalId) =>
|
|
932
|
+
Promise.resolve({
|
|
933
|
+
story: { slug: `section/${externalId}`, id: "abcdefgh-blah" },
|
|
934
|
+
}),
|
|
935
|
+
}),
|
|
936
|
+
}
|
|
928
937
|
);
|
|
929
938
|
|
|
930
939
|
supertest(app)
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
response.
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
assert.equal("story-page", response.store.qt.pageType);
|
|
943
|
-
})
|
|
944
|
-
.then(done);
|
|
940
|
+
.get("/12345")
|
|
941
|
+
.expect("Content-Type", /html/)
|
|
942
|
+
.expect(200)
|
|
943
|
+
.then((res) => {
|
|
944
|
+
const response = JSON.parse(res.text);
|
|
945
|
+
assert.equal('<div data-page-type="story-page">foobar</div>', response.content);
|
|
946
|
+
assert.equal("foobar", response.store.qt.data.text);
|
|
947
|
+
assert.equal("127.0.0.1", response.store.qt.data.host);
|
|
948
|
+
assert.equal("story-page", response.store.qt.pageType);
|
|
949
|
+
})
|
|
950
|
+
.then(done);
|
|
945
951
|
});
|
|
946
952
|
|
|
947
|
-
it("when external stories are
|
|
953
|
+
it("should render the 404 page when external stories are enabled but the route doesn't match", (done) => {
|
|
954
|
+
const app = createApp(
|
|
955
|
+
(pageType, params, config, client) => Promise.resolve(),
|
|
956
|
+
[{ pageType: "story-page", path: "/:storySlug", exact: true }],
|
|
957
|
+
{
|
|
958
|
+
loadErrorData: (err, config, client, { host }) => ({
|
|
959
|
+
httpStatusCode: err.httpStatusCode,
|
|
960
|
+
pageType: "not-found",
|
|
961
|
+
data: { text: "foobar", host },
|
|
962
|
+
}),
|
|
963
|
+
enableExternalStories: true,
|
|
964
|
+
externalIdPattern: "/EXTERNAL_ID",
|
|
965
|
+
getClient: (hostname) => ({
|
|
966
|
+
getConfig: () => Promise.resolve({ "publisher-id": 42 }),
|
|
967
|
+
getStoryByExternalId: (externalId) =>
|
|
968
|
+
Promise.resolve({
|
|
969
|
+
story: null
|
|
970
|
+
}),
|
|
971
|
+
}),
|
|
972
|
+
}
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
supertest(app)
|
|
976
|
+
.get("/abc/def/12345")
|
|
977
|
+
.expect("Content-Type", /html/)
|
|
978
|
+
.expect(404)
|
|
979
|
+
.then((res) => {
|
|
980
|
+
const response = JSON.parse(res.text);
|
|
981
|
+
assert.equal(
|
|
982
|
+
'<div data-page-type="not-found">foobar</div>',
|
|
983
|
+
response.content
|
|
984
|
+
);
|
|
985
|
+
assert.equal("127.0.0.1", response.store.qt.data.host);
|
|
986
|
+
})
|
|
987
|
+
.then(done);
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
it("should render a 404 page when external stories are not enabled", (done) => {
|
|
948
991
|
const app = createApp(
|
|
949
992
|
(pageType, params, config, client) => Promise.resolve(),
|
|
950
993
|
[{ pageType: "story-page", path: "/*/:storySlug", exact: true }],
|
|
@@ -954,7 +997,12 @@ describe("Isomorphic Handler", function () {
|
|
|
954
997
|
pageType: "not-found",
|
|
955
998
|
data: { text: "foobar", host },
|
|
956
999
|
}),
|
|
957
|
-
enableExternalStories: false
|
|
1000
|
+
enableExternalStories: false,
|
|
1001
|
+
getClient: (hostname) => ({
|
|
1002
|
+
getConfig: () => Promise.resolve({ "publisher-id": 42 }),
|
|
1003
|
+
getStoryByExternalId: (externalId) =>
|
|
1004
|
+
Promise.resolve(null),
|
|
1005
|
+
}),
|
|
958
1006
|
}
|
|
959
1007
|
);
|
|
960
1008
|
|