@quintype/framework 7.18.2-webengage.2 → 7.18.2-webengage.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/routes.js +31 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.18.2-webengage.2",
3
+ "version": "7.18.2-webengage.4",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
package/server/routes.js CHANGED
@@ -28,6 +28,7 @@ const bodyParser = require("body-parser");
28
28
  const get = require("lodash/get");
29
29
  const { URL } = require("url");
30
30
  const prerender = require("@quintype/prerender-node");
31
+ const request = require("request-promise");
31
32
 
32
33
  /**
33
34
  * *upstreamQuintypeRoutes* connects various routes directly to the upstream API server.
@@ -311,7 +312,6 @@ exports.isomorphicRoutes = function isomorphicRoutes(
311
312
  handleNotFound = true,
312
313
  redirectRootLevelStories = false,
313
314
  mobileApiEnabled = true,
314
- feEnabled = true,
315
315
  mobileConfigFields = {},
316
316
  templateOptions = false,
317
317
  lightPages = false,
@@ -333,6 +333,9 @@ exports.isomorphicRoutes = function isomorphicRoutes(
333
333
  sMaxAge = 900,
334
334
  appLoadingPlaceholder = "",
335
335
  fcmServerKey = "",
336
+ enableWebengage = false,
337
+ webengageLicenseCode,
338
+ webengageApiKey,
336
339
  }
337
340
  ) {
338
341
  const withConfig = withConfigPartial(getClient, logError, publisherConfig, configWrapper);
@@ -427,10 +430,33 @@ exports.isomorphicRoutes = function isomorphicRoutes(
427
430
 
428
431
  app.post("/register-fcm-topic", bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServerKey }));
429
432
 
430
- app.post("/webengage-api", bodyParser.json(), (req, res) => {
431
- console.log("hit /webengage-api", req.body);
432
- res.json({ status: "webengage-notified", data: req.body });
433
- });
433
+ if (enableWebengage) {
434
+ app.post("/webengage-api", bodyParser.json(), async (req, res) => {
435
+ const eventName = req.body.v1.event.name;
436
+ const { headline, subheadline, slug } = req.body;
437
+ console.log("hit /webengage-api", webengageLicenseCode, webengageApiKey, headline, subheadline, slug, eventName);
438
+ const url = `https://api.webengage.com/v2/accounts/${webengageLicenseCode}/business/save-event`;
439
+ try {
440
+ await request({
441
+ uri: url,
442
+ method: "POST",
443
+ headers: {
444
+ Authorization: `Bearer ${webengageApiKey}`,
445
+ "content-type": "application/json",
446
+ },
447
+ body: { eventName: "Story Created", eventData: { app: "malibu" } },
448
+ json: true,
449
+ });
450
+ console.log("inside the try block before return", eventName);
451
+ res.status(200).send("webengage event triggered successfully");
452
+ return;
453
+ } catch (error) {
454
+ console.log("The error is -->", error);
455
+ res.status(500).send("webengage event Failed");
456
+ return;
457
+ }
458
+ });
459
+ }
434
460
 
435
461
  if (manifestFn) {
436
462
  app.get("/manifest.json", withConfig(handleManifest, { manifestFn, logError }));