@quintype/framework 7.33.6-fcm-fix-1.3 → 7.33.6-fcm-fix-2.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/client/impl/fcm.js
CHANGED
|
@@ -4,6 +4,7 @@ export function initializeFCM (firebaseConfig) {
|
|
|
4
4
|
import(/* webpackChunkName: "firebase-messaging" */ 'firebase/messaging')
|
|
5
5
|
])
|
|
6
6
|
.then(([firebase, m]) => {
|
|
7
|
+
console.log('m-----------', m)
|
|
7
8
|
const app = firebase.initializeApp({
|
|
8
9
|
messagingSenderId: firebaseConfig.messagingSenderId.toString(),
|
|
9
10
|
projectId: firebaseConfig.projectId,
|
|
@@ -12,28 +13,12 @@ export function initializeFCM (firebaseConfig) {
|
|
|
12
13
|
authDomain: firebaseConfig.authDomain,
|
|
13
14
|
appId: firebaseConfig.appId
|
|
14
15
|
})
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
? m.getToken(messaging, {
|
|
18
|
-
vapidKey: firebaseConfig.vapidKey
|
|
19
|
-
})
|
|
20
|
-
: m.getToken(messaging)
|
|
16
|
+
m.getMessaging(app)
|
|
17
|
+
return
|
|
21
18
|
// No need to refresh token https://github.com/firebase/firebase-js-sdk/issues/4132
|
|
22
19
|
})
|
|
23
|
-
.then(token => {
|
|
24
|
-
return registerFCMTopic(token)
|
|
25
|
-
})
|
|
26
20
|
.catch(err => {
|
|
21
|
+
console.log('fcm initialization error---------', err)
|
|
27
22
|
console.error(err)
|
|
28
23
|
})
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
function registerFCMTopic (token) {
|
|
32
|
-
return fetch('/register-fcm-topic', {
|
|
33
|
-
method: 'post',
|
|
34
|
-
headers: {
|
|
35
|
-
'Content-Type': 'application/json'
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify({ token: token })
|
|
38
|
-
})
|
|
39
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.33.6-fcm-fix-
|
|
3
|
+
"version": "7.33.6-fcm-fix-2.0",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -45,8 +45,7 @@
|
|
|
45
45
|
"compression": "^1.7.4",
|
|
46
46
|
"ejs": "^3.1.6",
|
|
47
47
|
"express": "^4.17.1",
|
|
48
|
-
"firebase": "^9.
|
|
49
|
-
"firebase-admin": "^13.1.0",
|
|
48
|
+
"firebase": "^9.23.0",
|
|
50
49
|
"get-youtube-id": "^1.0.1",
|
|
51
50
|
"http-proxy": "^1.18.1",
|
|
52
51
|
"js-yaml": "^4.1.0",
|
|
@@ -1,54 +1,38 @@
|
|
|
1
|
-
const { get } = require(
|
|
2
|
-
const request = require(
|
|
3
|
-
const admin = require('firebase-admin')
|
|
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, fcmServerKey
|
|
8
|
+
{ config, client, publisherConfig, fcmServerKey }
|
|
10
9
|
) {
|
|
11
|
-
const token = get(req, [
|
|
10
|
+
const token = get(req, ["body", "token"], null);
|
|
12
11
|
if (!token) {
|
|
13
|
-
res.status(400).send(
|
|
14
|
-
return
|
|
12
|
+
res.status(400).send("No Token Found");
|
|
13
|
+
return;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const
|
|
18
|
-
.then(serviceAccount => {
|
|
19
|
-
console.log('service account----fdsdf', serviceAccount)
|
|
20
|
-
return serviceAccount
|
|
21
|
-
})
|
|
22
|
-
.catch(error => {
|
|
23
|
-
res.status(400).send(`No Service Account Json: ${error}`)
|
|
24
|
-
return
|
|
25
|
-
})
|
|
16
|
+
const serverKey = typeof fcmServerKey === "function" ? await fcmServerKey(config) : fcmServerKey;
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Authorization: `Bearer ${oauthToken}`,
|
|
49
|
-
'content-type': 'application/json'
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
.then(() => res.status(200).send('Registration Done Successfully'))
|
|
53
|
-
.catch(error => res.status(500).send(`FCM Subscription Failed: ${error}`))
|
|
54
|
-
}
|
|
18
|
+
if (!serverKey) {
|
|
19
|
+
res.status(500).send("Server Key is not available");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const url = `https://iid.googleapis.com/iid/v1/${token}/rel/topics/all`;
|
|
23
|
+
try {
|
|
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;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
res.status(500).send("FCM Subscription Failed");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
};
|
package/server/routes.js
CHANGED
|
@@ -356,8 +356,7 @@ exports.isomorphicRoutes = function isomorphicRoutes (
|
|
|
356
356
|
webengageConfig = {},
|
|
357
357
|
externalIdPattern = '',
|
|
358
358
|
enableExternalStories = false,
|
|
359
|
-
lazyLoadImageMargin
|
|
360
|
-
fcmServiceAccountJson
|
|
359
|
+
lazyLoadImageMargin
|
|
361
360
|
}
|
|
362
361
|
) {
|
|
363
362
|
const withConfig = withConfigPartial(getClient, logError, publisherConfig, configWrapper)
|
|
@@ -470,11 +469,7 @@ exports.isomorphicRoutes = function isomorphicRoutes (
|
|
|
470
469
|
})
|
|
471
470
|
)
|
|
472
471
|
|
|
473
|
-
app.post(
|
|
474
|
-
'/register-fcm-topic',
|
|
475
|
-
bodyParser.json(),
|
|
476
|
-
withConfig(registerFCMTopic, { publisherConfig, fcmServerKey, fcmServiceAccountJson })
|
|
477
|
-
)
|
|
472
|
+
app.post('/register-fcm-topic', bodyParser.json(), withConfig(registerFCMTopic, { publisherConfig, fcmServerKey }))
|
|
478
473
|
|
|
479
474
|
if (webengageConfig.enableWebengage) {
|
|
480
475
|
app.post(
|