@quintype/framework 7.3.3-node16-with-amp-custom-labels.2 → 7.3.3-saam-tv-issue.2

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
@@ -145,30 +145,23 @@ startApp(renderApplication, CUSTOM_REDUCERS, {
145
145
 
146
146
  Steps to Integrate FCM in your project
147
147
 
148
- 1. app/client/app.js While executing startApp in your project send the firebaseConfig via opts. `firebaseConfig` can either be an object or a function that returns the firebase config object
148
+ 1. While executing startApp in your project set enableFCM to true.
149
149
 
150
- Example:
150
+ An Example
151
151
 
152
- ```js
152
+ ```
153
153
  startApp(renderApplication,
154
154
  CUSTOM_REDUCERS,
155
155
  {
156
156
  enableServiceWorker: process.env.NODE_ENV === "production",
157
- firebaseConfig: {
158
- messagingSenderId: --YOUR KEY-- ,
159
- projectId: --YOUR KEY--,
160
- apiKey: --YOUR KEY--,
161
- storageBucket: --YOUR KEY--,
162
- authDomain: --YOUR KEY--,
163
- appId: --YOUR KEY--,
164
- }
157
+ fcmMessagingSenderId: (page) => <MessageSenderId> || fcmMessagingSenderId: <MessageSenderId> {(function|string)}
165
158
  ...
166
159
  })
167
160
  ```
168
161
 
169
162
  2. app/server/app.js should have the fcm configuration as below:
170
163
 
171
- ```js
164
+ ```
172
165
  isomorphicRoutes(app, {
173
166
  ...
174
167
  fcmServerKey: (config) => <ServerKey> || fcmServerKey: <ServerKey> {(function|string)}
@@ -181,45 +174,28 @@ isomorphicRoutes(app, {
181
174
 
182
175
  Example of the script:
183
176
 
184
- ```js
185
- importScripts("https://www.gstatic.com/firebasejs/9.6.10/firebase-app-compat.js");
186
- importScripts("https://www.gstatic.com/firebasejs/9.6.10/firebase-messaging-compat.js");
187
-
188
- firebase.initializeApp({
189
- messagingSenderId: --YOUR KEY-- ,
190
- projectId: --YOUR KEY--,
191
- apiKey: --YOUR KEY--,
192
- storageBucket: --YOUR KEY--,
193
- authDomain: --YOUR KEY--,
194
- appId: --YOUR KEY--,
195
- });
196
- self.addEventListener('notificationclick', (event) => {
197
-
198
- const url = event.notification.data.url;
199
- if(url) {
200
- clients.openWindow(url);
201
- }
202
- clients.openWindow(-- YOUR Sketches Host --);
203
- }, false);
204
-
205
- const messaging = firebase.messaging();
206
-
207
- messaging.onBackgroundMessage(function(payload) {
208
- const data = payload["data"];
209
- const notificationTitle = data.title || ""
210
- const notificationOptions = {
211
- body: data.body,
212
- icon: data["hero_image_s3_url"],
213
- image: data["hero_image_s3_url"],
214
- data: {
215
- url: data["click_action"],
216
- }
217
- };
218
-
219
- self.registration.showNotification(notificationTitle,
220
- notificationOptions);
221
- });
222
-
177
+ ```
178
+ importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js");
179
+ importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js");
180
+ firebase.initializeApp({
181
+ messagingSenderId: <your message sender Id>
182
+ });
183
+ const messaging = firebase.messaging();
184
+ function messageHandler(payload) {
185
+ const data = payload["data"];
186
+
187
+ var notificationTitle = data.title;
188
+ var notificationOptions = {
189
+ body: data.body,
190
+ icon: data["hero_image_s3_url"],
191
+ image: data["hero_image_s3_url"],
192
+ data: data
193
+ };
194
+
195
+ return self.registration.showNotification(notificationTitle,
196
+ notificationOptions);
197
+ }
198
+ messaging.setBackgroundMessageHandler(messageHandler);
223
199
  ```
224
200
 
225
201
  4. Make sure that the page data should have config with key fcmMessageSenderId refer doStartApp function in app/client/start.js.
@@ -1,26 +1,39 @@
1
- export function initializeFCM(firebaseConfig) {
1
+ export function initializeFCM(messageSenderId) {
2
+ if (!messageSenderId) {
3
+ console.log("messageSenderId is required");
4
+ return false;
5
+ }
2
6
  Promise.all([
3
7
  import(/* webpackChunkName: "firebase-app" */ "firebase/app"),
4
8
  import(/* webpackChunkName: "firebase-messaging" */ "firebase/messaging"),
5
- ])
6
- .then(([firebase, m]) => {
7
- const app = firebase.initializeApp({
8
- messagingSenderId: firebaseConfig.messagingSenderId.toString(),
9
- projectId: firebaseConfig.projectId,
10
- apiKey: firebaseConfig.apiKey,
11
- storageBucket: firebaseConfig.storageBucket,
12
- authDomain: firebaseConfig.authDomain,
13
- appId: firebaseConfig.appId,
9
+ ]).then(([firebase, m]) => {
10
+ try {
11
+ firebase.initializeApp({
12
+ messagingSenderId: messageSenderId.toString(),
14
13
  });
15
- const messaging = m.getMessaging(app);
16
- return m.getToken(messaging);
17
- // No need to refresh token https://github.com/firebase/firebase-js-sdk/issues/4132
18
- })
14
+ const messaging = firebase.messaging();
15
+ messaging.requestPermission().then(() => {
16
+ updateToken(firebase)
17
+ .then(() => {
18
+ messaging.onTokenRefresh(() => updateToken(firebase));
19
+ })
20
+ .catch(console.error);
21
+ });
22
+ } catch (error) {
23
+ console.error(error);
24
+ }
25
+ });
26
+ }
27
+
28
+ function updateToken(firebaseInstance) {
29
+ return firebaseInstance
30
+ .messaging()
31
+ .getToken()
19
32
  .then((token) => {
20
33
  return registerFCMTopic(token);
21
34
  })
22
35
  .catch((err) => {
23
- console.error(err);
36
+ throw new Error(err);
24
37
  });
25
38
  }
26
39
 
package/client/start.js CHANGED
@@ -282,14 +282,10 @@ export function startApp(renderApplication, reducers, opts) {
282
282
 
283
283
  store.dispatch({ type: NAVIGATE_TO_PAGE, page, currentPath: path });
284
284
 
285
- if (opts.firebaseConfig) {
286
- const fcm = typeof opts.firebaseConfig === "function" ? opts.firebaseConfig(page) : opts.firebaseConfig;
287
- if (fcm) {
288
- const mssgSenderId = fcm.messagingSenderId;
289
- const projectId = fcm.projectId;
290
- const apiKey = fcm.apiKey;
291
- if (mssgSenderId && projectId && apiKey) initializeFCM(fcm);
292
- }
285
+ if (opts.fcmMessagingSenderId) {
286
+ const mssgSenderId =
287
+ typeof opts.fcmMessagingSenderId === "function" ? opts.fcmMessagingSenderId(page) : opts.fcmMessagingSenderId;
288
+ mssgSenderId && initializeFCM(mssgSenderId);
293
289
  }
294
290
 
295
291
  const { config: { "theme-attributes": pageThemeAttributes = {} } = {} } = page;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.3.3-node16-with-amp-custom-labels.2",
3
+ "version": "7.3.3-saam-tv-issue.2",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,19 +27,18 @@
27
27
  "homepage": "https://github.com/quintype/quintype-node-framework#readme",
28
28
  "dependencies": {
29
29
  "@ampproject/toolbox-optimizer": "2.8.3",
30
- "@quintype/amp": "2.4.20-amp-date-translation.4",
30
+ "@quintype/amp": "^2.4.21-saam-tv-issue.1",
31
31
  "@quintype/backend": "^2.3.1",
32
32
  "@quintype/components": "^3.0.0",
33
33
  "@quintype/prerender-node": "^3.2.24",
34
34
  "@quintype/seo": "^1.39.0",
35
35
  "atob": "^2.1.2",
36
- "babel-plugin-react-css-modules": "^5.2.6",
37
36
  "chalk": "^4.1.2",
38
37
  "cluster": "^0.7.7",
39
38
  "compression": "^1.7.4",
40
39
  "ejs": "^3.1.6",
41
40
  "express": "^4.17.1",
42
- "firebase": "^9.6.10",
41
+ "firebase": "^6.0.2",
43
42
  "get-youtube-id": "^1.0.1",
44
43
  "grpc": "^1.21.1",
45
44
  "http-proxy": "^1.18.1",
@@ -63,6 +62,7 @@
63
62
  "@loadable/server": "^5.15.1",
64
63
  "@quintype/build": "^3.13.1",
65
64
  "babel-plugin-quintype-assets": "^1.1.1",
65
+ "babel-plugin-react-css-modules": "^5.2.6",
66
66
  "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
67
67
  "babel-plugin-transform-object-rest-spread": "^6.26.0",
68
68
  "babel-preset-es2015": "^6.24.1",