@quintype/framework 7.33.6-fcm-fix-2.18 → 7.33.6-jw-player.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/README.md CHANGED
@@ -171,7 +171,7 @@ startApp(renderApplication,
171
171
  ```js
172
172
  isomorphicRoutes(app, {
173
173
  ...
174
- fcmServiceCreds: (config) => <ServiceCreds> || fcmServiceCreds: <ServiceCreds> {(function|object)}
174
+ fcmServerKey: (config) => <ServerKey> || fcmServerKey: <ServerKey> {(function|string)}
175
175
  ...
176
176
  });
177
177
 
@@ -20,7 +20,7 @@ export function initializeFCM(firebaseConfig) {
20
20
  return registerFCMTopic(token);
21
21
  })
22
22
  .catch((err) => {
23
- console.error(`Fcm initialization error: ${err}`);
23
+ console.error(err);
24
24
  });
25
25
  }
26
26
 
package/client/start.js CHANGED
@@ -17,6 +17,7 @@ import { IsomorphicComponent } from "../isomorphic/component";
17
17
  import { makePickComponentSync } from "../isomorphic/impl/make-pick-component-sync";
18
18
  import { createQtStore } from "../store/create-store";
19
19
  import { registerPageView, registerStoryShare, setMemberId, startAnalytics } from "./analytics";
20
+ import { initializeFCM } from "./impl/fcm";
20
21
  import {
21
22
  checkForServiceWorkerUpdates,
22
23
  registerServiceWorker,
@@ -300,6 +301,16 @@ export function startApp(renderApplication, reducers, opts) {
300
301
 
301
302
  store.dispatch({ type: NAVIGATE_TO_PAGE, page, currentPath: path });
302
303
 
304
+ if (opts.firebaseConfig) {
305
+ const fcm = typeof opts.firebaseConfig === "function" ? opts.firebaseConfig(page) : opts.firebaseConfig;
306
+ if (fcm) {
307
+ const mssgSenderId = fcm.messagingSenderId;
308
+ const projectId = fcm.projectId;
309
+ const apiKey = fcm.apiKey;
310
+ if (mssgSenderId && projectId && apiKey) initializeFCM(fcm);
311
+ }
312
+ }
313
+
303
314
  const { config: { "theme-attributes": pageThemeAttributes = {} } = {} } = page;
304
315
  const version = pageThemeAttributes["cache-burst"] || app.getAppVersion();
305
316
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.33.6-fcm-fix-2.18",
3
+ "version": "7.33.6-jw-player.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
  "@grpc/grpc-js": "^1.12.5",
35
35
  "@jsdoc/salty": "^0.2.9",
36
- "@quintype/amp": "^2.20.0",
36
+ "@quintype/amp": "^2.20.1-jw-player.0",
37
37
  "@quintype/backend": "^2.7.0",
38
38
  "@quintype/components": "^3.5.0",
39
39
  "@quintype/prerender-node": "^3.2.26",
@@ -45,8 +45,7 @@
45
45
  "compression": "^1.7.4",
46
46
  "ejs": "^3.1.6",
47
47
  "express": "^4.17.1",
48
- "firebase": "^10.6.0",
49
- "firebase-admin": "^13.1.0",
48
+ "firebase": "^9.6.10",
50
49
  "get-youtube-id": "^1.0.1",
51
50
  "http-proxy": "^1.18.1",
52
51
  "js-yaml": "^4.1.0",
@@ -1,33 +1,38 @@
1
- const { get } = require('lodash')
2
- const admin = require('firebase-admin')
3
- const logger = require('../logger')
1
+ const { get } = require("lodash");
2
+ const request = require("request-promise");
4
3
 
5
- exports.registerFCMTopic = async function registerFCM (
4
+ exports.registerFCMTopic = async function registerFCM(
6
5
  req,
7
6
  res,
8
7
  next,
9
- { config, client, publisherConfig, fcmServiceCreds }
8
+ { config, client, publisherConfig, fcmServerKey }
10
9
  ) {
11
-
12
- const token = get(req, ['body', 'token'], null)
10
+ const token = get(req, ["body", "token"], null);
13
11
  if (!token) {
14
- res.status(400).send('No Token Found')
15
- return
12
+ res.status(400).send("No Token Found");
13
+ return;
16
14
  }
17
15
 
18
- const serviceAccount = typeof fcmServiceCreds === 'function' ? await fcmServiceCreds(config) : fcmServiceCreds
16
+ const serverKey = typeof fcmServerKey === "function" ? await fcmServerKey(config) : fcmServerKey;
19
17
 
20
- if (!admin.apps.length) {
21
- admin.initializeApp({ credential: admin.credential.cert(serviceAccount) })
18
+ if (!serverKey) {
19
+ res.status(500).send("Server Key is not available");
20
+ return;
22
21
  }
23
-
22
+ const url = `https://iid.googleapis.com/iid/v1/${token}/rel/topics/all`;
24
23
  try {
25
- await admin.messaging().subscribeToTopic(token, 'all')
26
- res.status(200).send('Topic Registered Successfully')
27
- return
24
+ await request({
25
+ uri: url,
26
+ method: "POST",
27
+ headers: {
28
+ Authorization: `key=${serverKey}`,
29
+ "content-type": "application/json",
30
+ },
31
+ });
32
+ res.status(200).send("Registration Done Suceessfuly");
33
+ return;
28
34
  } catch (error) {
29
- res.status(500).send(`FCM Subscription Failed: ${error}`)
30
- logger.error(`Fcm register to topic error: ${error}`)
31
- return
35
+ res.status(500).send("FCM Subscription Failed");
36
+ return;
32
37
  }
33
- }
38
+ };
package/server/routes.js CHANGED
@@ -304,7 +304,7 @@ function getWithConfig (app, route, handler, opts = {}) {
304
304
  * @param {boolean|function} shouldEncodeAmpUri If set to true, then for every story-page request the slug will be encoded, in case of a vernacular slug this should be set to false. Receives path as param (default: true)
305
305
  * @param {number} sMaxAge Overrides the s-maxage value, the default value is set to 900 seconds. We can set `isomorphicRoutesSmaxage: 900` under `publisher` in publisher.yml config file that comes from BlackKnight or pass sMaxAge as a param.
306
306
  * @param {number} maxAge Overrides the max-age value, the default value is set to 15 seconds. We can set `isomorphicRoutesMaxage: 15` under `publisher` in publisher.yml config file that comes from BlackKnight or pass maxAge as a param.
307
- * @param {(object|function)} fcmServiceCreds FCM service creds is used for registering FCM Topic.
307
+ * @param {(string|function)} fcmServerKey FCM serverKey is used for registering FCM Topic.
308
308
  * @param {string} appLoadingPlaceholder This string gets injected into the app container when the page is loaded via service worker. Can be used to show skeleton layouts, animations or other progress indicators before it is replaced by the page content.
309
309
  * @param {boolean|function} enableExternalStories If set to true, then for every request an external story api call is made and renders the story-page if the story is found. (default: false)
310
310
  * @param {string|function} externalIdPattern This string specifies the external id pattern the in the url. Mention `EXTERNAL_ID` to specify the position of external id in the url. Ex: "/parent-section/child-section/EXTERNAL_ID"
@@ -352,7 +352,7 @@ exports.isomorphicRoutes = function isomorphicRoutes (
352
352
  sMaxAge = 900,
353
353
  maxAge = 15,
354
354
  appLoadingPlaceholder = '',
355
- fcmServiceCreds = {},
355
+ fcmServerKey = '',
356
356
  webengageConfig = {},
357
357
  externalIdPattern = '',
358
358
  enableExternalStories = false,
@@ -469,7 +469,7 @@ exports.isomorphicRoutes = function isomorphicRoutes (
469
469
  })
470
470
  )
471
471
 
472
- app.post('/register-fcm-topic', bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServiceCreds }))
472
+ app.post('/register-fcm-topic', bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServerKey }))
473
473
 
474
474
  if (webengageConfig.enableWebengage) {
475
475
  app.post(