@quintype/framework 7.18.7 → 7.18.8-webengage.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.18.7",
3
+ "version": "7.18.8-webengage.0",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -14,7 +14,7 @@
14
14
  "coverage": "nyc --all npm test",
15
15
  "coverage-html": "nyc --all --reporter=html npm test",
16
16
  "docs": "rimraf docs && jsdoc -c jsdoc.json",
17
- "sync-files-to": "npx onchange --verbose --wait --await-write-finish 'client/**/*' 'server/**/*' 'isomorphic/**/*' -- ./bin-dev-scripts/sync-to.sh "
17
+ "sync-files-to": "npx onchange --verbose --await-write-finish=2000 'client/**/*' 'server/**/*' 'isomorphic/**/*' -- ./bin-dev-scripts/sync-to.sh "
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -0,0 +1,38 @@
1
+ const get = require("lodash/get");
2
+ const request = require("request-promise");
3
+
4
+ exports.webengageApi = async function webengageApi(req, res, next, { webengageApiKey, webengageLicenseCode }) {
5
+ const eventName = get(req, ["body", "v1", "event", "name"], "");
6
+ let eventData = {};
7
+
8
+ switch (eventName) {
9
+ case "story-publish":
10
+ const { "author-name": author, headline } = req.body;
11
+ eventData = { author, headline };
12
+ break;
13
+ case "push-notification-triggered":
14
+ const { title, message } = req.body;
15
+ eventData = { title, message };
16
+ break;
17
+ default:
18
+ break;
19
+ }
20
+ const url = `https://api.webengage.com/v2/accounts/${webengageLicenseCode}/business/save-event`;
21
+ try {
22
+ await request({
23
+ uri: url,
24
+ method: "POST",
25
+ headers: {
26
+ Authorization: `Bearer ${webengageApiKey}`,
27
+ "content-type": "application/json",
28
+ },
29
+ body: { eventName: eventName, eventData: { eventData, user_type: "malibu_user" } },
30
+ json: true,
31
+ });
32
+ res.status(200).send("webengage event triggered successfully");
33
+ return;
34
+ } catch (error) {
35
+ res.status(500).send("webengage event failed");
36
+ return;
37
+ }
38
+ };
package/server/routes.js CHANGED
@@ -23,6 +23,7 @@ const { redirectStory } = require("./handlers/story-redirect");
23
23
  const { simpleJsonHandler } = require("./handlers/simple-json-handler");
24
24
  const { makePickComponentSync } = require("../isomorphic/impl/make-pick-component-sync");
25
25
  const { registerFCMTopic } = require("./handlers/fcm-registration-handler");
26
+ const { webengageApi } = require("./handlers/webengage");
26
27
  const rp = require("request-promise");
27
28
  const bodyParser = require("body-parser");
28
29
  const get = require("lodash/get");
@@ -332,6 +333,9 @@ exports.isomorphicRoutes = function isomorphicRoutes(
332
333
  sMaxAge = 900,
333
334
  appLoadingPlaceholder = "",
334
335
  fcmServerKey = "",
336
+ enableWebengage = false,
337
+ webengageLicenseCode,
338
+ webengageApiKey,
335
339
  }
336
340
  ) {
337
341
  const withConfig = withConfigPartial(getClient, logError, publisherConfig, configWrapper);
@@ -426,6 +430,10 @@ exports.isomorphicRoutes = function isomorphicRoutes(
426
430
 
427
431
  app.post("/register-fcm-topic", bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServerKey }));
428
432
 
433
+ if (enableWebengage) {
434
+ app.post("/webengage-api", bodyParser.json(), withConfig(webengageApi, { webengageLicenseCode, webengageApiKey }));
435
+ }
436
+
429
437
  if (manifestFn) {
430
438
  app.get("/manifest.json", withConfig(handleManifest, { manifestFn, logError }));
431
439
  }