@quintype/framework 7.18.10-webhook-data-temp.2 → 7.18.10
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.18.10](https://github.com/quintype/quintype-node-framework/compare/v7.18.9...v7.18.10) (2023-04-05)
|
|
6
|
+
|
|
5
7
|
### [7.18.9](https://github.com/quintype/quintype-node-framework/compare/v7.18.1...v7.18.9) (2023-03-14)
|
|
6
8
|
|
|
7
9
|
### [7.18.8](https://github.com/quintype/quintype-node-framework/compare/v7.18.7...v7.18.8) (2023-02-24)
|
package/package.json
CHANGED
|
@@ -15,6 +15,7 @@ const { customUrlToCacheKey } = require("../caching");
|
|
|
15
15
|
const { addLightPageHeaders } = require("../impl/light-page-impl");
|
|
16
16
|
const { getOneSignalScript } = require("./onesignal-script");
|
|
17
17
|
const { getRedirectUrl } = require("../redirect-url-helper");
|
|
18
|
+
const { Story } = require("../impl/api-client-impl");
|
|
18
19
|
|
|
19
20
|
const ABORT_HANDLER = "__ABORT__";
|
|
20
21
|
function abortHandler() {
|
|
@@ -37,6 +38,7 @@ function loadDataForIsomorphicRoute(
|
|
|
37
38
|
async function loadDataForEachRoute() {
|
|
38
39
|
const redirectToLowercaseSlugsValue =
|
|
39
40
|
typeof redirectToLowercaseSlugs === "function" ? redirectToLowercaseSlugs(config) : redirectToLowercaseSlugs;
|
|
41
|
+
|
|
40
42
|
for (const match of matchAllRoutes(url.pathname, routes)) {
|
|
41
43
|
const params = Object.assign({}, url.query, otherParams, match.params);
|
|
42
44
|
/* On story pages, if the slug contains any capital letters (latin), we want to
|
|
@@ -56,6 +58,7 @@ function loadDataForIsomorphicRoute(
|
|
|
56
58
|
},
|
|
57
59
|
};
|
|
58
60
|
}
|
|
61
|
+
|
|
59
62
|
const result = await loadData(match.pageType, params, config, client, {
|
|
60
63
|
host,
|
|
61
64
|
next: abortHandler,
|
|
@@ -68,6 +71,18 @@ function loadDataForIsomorphicRoute(
|
|
|
68
71
|
|
|
69
72
|
if (result && result.data && result.data[ABORT_HANDLER]) continue;
|
|
70
73
|
|
|
74
|
+
// Multiple url redirection
|
|
75
|
+
const story = result.data.story;
|
|
76
|
+
if (story && story.redirect && `/${story.slug}` !== url.path) {
|
|
77
|
+
console.log("Inside Redirect IF", url.path);
|
|
78
|
+
return {
|
|
79
|
+
httpStatusCode: 301,
|
|
80
|
+
data: {
|
|
81
|
+
location: `/${story.slug}`,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
return result;
|
|
72
87
|
}
|
|
73
88
|
}
|
|
@@ -291,8 +306,18 @@ exports.handleIsomorphicDataLoad = function handleIsomorphicDataLoad(
|
|
|
291
306
|
}
|
|
292
307
|
|
|
293
308
|
function returnJson(result) {
|
|
309
|
+
const statusCode = result.httpStatusCode || 200;
|
|
310
|
+
if (statusCode == 301 && result.data && result.data.location) {
|
|
311
|
+
addCacheHeadersToResult({
|
|
312
|
+
res: res,
|
|
313
|
+
cacheKeys: [customUrlToCacheKey(config["publisher-id"], "redirect")],
|
|
314
|
+
cdnProvider: cdnProvider,
|
|
315
|
+
config: config,
|
|
316
|
+
sMaxAge,
|
|
317
|
+
});
|
|
318
|
+
return res.redirect(301, result.data.location);
|
|
319
|
+
}
|
|
294
320
|
return new Promise(() => {
|
|
295
|
-
const statusCode = result.httpStatusCode || 200;
|
|
296
321
|
res.status(statusCode < 500 ? 200 : 500);
|
|
297
322
|
res.setHeader("Content-Type", "application/json");
|
|
298
323
|
addCacheHeadersToResult({
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const get = require("lodash/get");
|
|
2
2
|
const request = require("request-promise");
|
|
3
|
-
const fs = require("fs");
|
|
4
3
|
|
|
5
4
|
exports.triggerWebengageNotifications = async function triggerWebengageNotifications(
|
|
6
5
|
req,
|
|
@@ -10,7 +9,6 @@ exports.triggerWebengageNotifications = async function triggerWebengageNotificat
|
|
|
10
9
|
) {
|
|
11
10
|
const eventName = get(req, ["body", "v1", "event", "name"], "");
|
|
12
11
|
const url = `https://api.webengage.com/v2/accounts/${licenseCode}/business/save-event`;
|
|
13
|
-
console.log("bold-webhook-schema inside framework is --->", req.body);
|
|
14
12
|
|
|
15
13
|
try {
|
|
16
14
|
await request({
|
|
@@ -98,9 +98,7 @@ describe("Isomorphic Data Load", function () {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it("returns an appVersion on every response", function (done) {
|
|
101
|
-
const app = createApp((pageType, params, config, client) =>
|
|
102
|
-
Promise.resolve({})
|
|
103
|
-
);
|
|
101
|
+
const app = createApp((pageType, params, config, client) => Promise.resolve({ data: { pageType } }));
|
|
104
102
|
|
|
105
103
|
supertest(app)
|
|
106
104
|
.get("/route-data.json?path=%2F")
|
|
@@ -13,6 +13,10 @@ function getClientStub(hostname) {
|
|
|
13
13
|
foo: "bar",
|
|
14
14
|
"sketches-host": "https://www.foo.com",
|
|
15
15
|
}),
|
|
16
|
+
getStoryBySlug: (slug) =>
|
|
17
|
+
Promise.resolve({
|
|
18
|
+
story: { slug: slug, id: "123", redirect: slug === "foo-bar" ? true : false },
|
|
19
|
+
}),
|
|
16
20
|
baseUrl: "https://www.foo.com",
|
|
17
21
|
};
|
|
18
22
|
}
|
|
@@ -51,6 +55,18 @@ function createApp(loadData, routes, opts = {}, app = express()) {
|
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
describe("Isomorphic Handler", function () {
|
|
58
|
+
it("when the story headline is changed, it redirects story to updated story url", (done) => {
|
|
59
|
+
const app = createApp(
|
|
60
|
+
(pageType, params, config, client, { host }) =>
|
|
61
|
+
Promise.resolve({
|
|
62
|
+
pageType,
|
|
63
|
+
data: { text: "foobar", host, location: "/foobar", story: { redirect: true, slug: "foo-bar" } },
|
|
64
|
+
}),
|
|
65
|
+
[{ pageType: "story-page", path: "/foobar", params: { storySlug: "foo-bar" } }]
|
|
66
|
+
);
|
|
67
|
+
supertest(app).get("/foobar").expect("Location", "/foo-bar").expect(301, done);
|
|
68
|
+
});
|
|
69
|
+
|
|
54
70
|
it("Renders the page if the route matches", function (done) {
|
|
55
71
|
const app = createApp(
|
|
56
72
|
(pageType, params, config, client, { host }) =>
|