@quintype/framework 7.33.6-fcm-fix-1.4 → 7.33.6-fix-story-route.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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function initializeFCM
|
|
1
|
+
export function initializeFCM(firebaseConfig) {
|
|
2
2
|
Promise.all([
|
|
3
|
-
import(/* webpackChunkName: "firebase-app" */
|
|
4
|
-
import(/* webpackChunkName: "firebase-messaging" */
|
|
3
|
+
import(/* webpackChunkName: "firebase-app" */ "firebase/app"),
|
|
4
|
+
import(/* webpackChunkName: "firebase-messaging" */ "firebase/messaging"),
|
|
5
5
|
])
|
|
6
6
|
.then(([firebase, m]) => {
|
|
7
7
|
const app = firebase.initializeApp({
|
|
@@ -10,30 +10,26 @@ export function initializeFCM (firebaseConfig) {
|
|
|
10
10
|
apiKey: firebaseConfig.apiKey,
|
|
11
11
|
storageBucket: firebaseConfig.storageBucket,
|
|
12
12
|
authDomain: firebaseConfig.authDomain,
|
|
13
|
-
appId: firebaseConfig.appId
|
|
14
|
-
})
|
|
15
|
-
const messaging = m.getMessaging(app)
|
|
16
|
-
return
|
|
17
|
-
? m.getToken(messaging, {
|
|
18
|
-
vapidKey: firebaseConfig.vapidKey
|
|
19
|
-
})
|
|
20
|
-
: m.getToken(messaging)
|
|
13
|
+
appId: firebaseConfig.appId,
|
|
14
|
+
});
|
|
15
|
+
const messaging = m.getMessaging(app);
|
|
16
|
+
return m.getToken(messaging);
|
|
21
17
|
// No need to refresh token https://github.com/firebase/firebase-js-sdk/issues/4132
|
|
22
18
|
})
|
|
23
|
-
.then(token => {
|
|
24
|
-
return registerFCMTopic(token)
|
|
25
|
-
})
|
|
26
|
-
.catch(err => {
|
|
27
|
-
console.error(err)
|
|
19
|
+
.then((token) => {
|
|
20
|
+
return registerFCMTopic(token);
|
|
28
21
|
})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
console.error(err);
|
|
24
|
+
});
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
function registerFCMTopic
|
|
32
|
-
return fetch(
|
|
33
|
-
method:
|
|
27
|
+
function registerFCMTopic(token) {
|
|
28
|
+
return fetch("/register-fcm-topic", {
|
|
29
|
+
method: "post",
|
|
34
30
|
headers: {
|
|
35
|
-
|
|
31
|
+
"Content-Type": "application/json",
|
|
36
32
|
},
|
|
37
|
-
body: JSON.stringify({ token: token })
|
|
38
|
-
})
|
|
33
|
+
body: JSON.stringify({ token: token }),
|
|
34
|
+
});
|
|
39
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.33.6-
|
|
3
|
+
"version": "7.33.6-fix-story-route.0",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"ejs": "^3.1.6",
|
|
47
47
|
"express": "^4.17.1",
|
|
48
48
|
"firebase": "^9.6.10",
|
|
49
|
-
"firebase-admin": "^13.1.0",
|
|
50
49
|
"get-youtube-id": "^1.0.1",
|
|
51
50
|
"http-proxy": "^1.18.1",
|
|
52
51
|
"js-yaml": "^4.1.0",
|
|
@@ -1,56 +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
|
-
|
|
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(
|
|
15
|
-
return
|
|
12
|
+
res.status(400).send("No Token Found");
|
|
13
|
+
return;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
const
|
|
19
|
-
.then(serviceAccount => {
|
|
20
|
-
console.log('service account----fdsdf', serviceAccount)
|
|
21
|
-
return serviceAccount
|
|
22
|
-
})
|
|
23
|
-
.catch(error => {
|
|
24
|
-
res.status(400).send(`No Service Account Json: ${error}`)
|
|
25
|
-
return
|
|
26
|
-
})
|
|
16
|
+
const serverKey = typeof fcmServerKey === "function" ? await fcmServerKey(config) : fcmServerKey;
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Authorization: `Bearer ${oauthToken}`,
|
|
50
|
-
'content-type': 'application/json',
|
|
51
|
-
access_token_auth: true
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.then(() => res.status(200).send('Registration Done Successfully'))
|
|
55
|
-
.catch(error => res.status(500).send(`FCM Subscription Failed: ${error}`))
|
|
56
|
-
}
|
|
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
|
+
};
|
|
@@ -51,7 +51,9 @@ function loadDataForIsomorphicRoute(
|
|
|
51
51
|
const redirectToLowercaseSlugsValue =
|
|
52
52
|
typeof redirectToLowercaseSlugs === "function" ? redirectToLowercaseSlugs(config) : redirectToLowercaseSlugs;
|
|
53
53
|
for (const match of matchAllRoutes(url.pathname, routes)) {
|
|
54
|
-
const
|
|
54
|
+
const storyPath = (match.pageType === "story-page" && !match && !match.params && !match.params.storySlug) ? { storySlug: url.pathname } : {};
|
|
55
|
+
const params = Object.assign({}, url.query, otherParams, match.params, storyPath);
|
|
56
|
+
|
|
55
57
|
/* On story pages, if the slug contains any capital letters (latin), we want to
|
|
56
58
|
* redirect the browser to the URL having all lowercase letters. We need to be
|
|
57
59
|
* wary of any asset routes that might make its way here and get wrongly redirected.
|
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(
|