@quintype/framework 7.4.0-react-18.0 → 7.4.0-update-build.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
@@ -145,23 +145,30 @@ startApp(renderApplication, CUSTOM_REDUCERS, {
145
145
 
146
146
  Steps to Integrate FCM in your project
147
147
 
148
- 1. While executing startApp in your project set enableFCM to true.
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
149
149
 
150
- An Example
150
+ Example:
151
151
 
152
- ```
152
+ ```js
153
153
  startApp(renderApplication,
154
154
  CUSTOM_REDUCERS,
155
155
  {
156
156
  enableServiceWorker: process.env.NODE_ENV === "production",
157
- fcmMessagingSenderId: (page) => <MessageSenderId> || fcmMessagingSenderId: <MessageSenderId> {(function|string)}
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
+ }
158
165
  ...
159
166
  })
160
167
  ```
161
168
 
162
169
  2. app/server/app.js should have the fcm configuration as below:
163
170
 
164
- ```
171
+ ```js
165
172
  isomorphicRoutes(app, {
166
173
  ...
167
174
  fcmServerKey: (config) => <ServerKey> || fcmServerKey: <ServerKey> {(function|string)}
@@ -174,28 +181,45 @@ isomorphicRoutes(app, {
174
181
 
175
182
  Example of the script:
176
183
 
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);
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
+
199
223
  ```
200
224
 
201
225
  4. Make sure that the page data should have config with key fcmMessageSenderId refer doStartApp function in app/client/start.js.
@@ -1,39 +1,26 @@
1
- export function initializeFCM(messageSenderId) {
2
- if (!messageSenderId) {
3
- console.log("messageSenderId is required");
4
- return false;
5
- }
1
+ export function initializeFCM(firebaseConfig) {
6
2
  Promise.all([
7
3
  import(/* webpackChunkName: "firebase-app" */ "firebase/app"),
8
4
  import(/* webpackChunkName: "firebase-messaging" */ "firebase/messaging"),
9
- ]).then(([firebase, m]) => {
10
- try {
11
- firebase.initializeApp({
12
- messagingSenderId: messageSenderId.toString(),
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,
13
14
  });
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()
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
+ })
32
19
  .then((token) => {
33
20
  return registerFCMTopic(token);
34
21
  })
35
22
  .catch((err) => {
36
- throw new Error(err);
23
+ console.error(err);
37
24
  });
38
25
  }
39
26
 
package/client/start.js CHANGED
@@ -11,7 +11,7 @@ import { BreakingNews, CLIENT_SIDE_RENDERED, NAVIGATE_TO_PAGE, PAGE_LOADING } fr
11
11
  import { createBrowserHistory } from "history";
12
12
  import get from "lodash/get";
13
13
  import React from "react";
14
- import { createRoot, hydrateRoot } from "react-dom/client";
14
+ import ReactDOM from "react-dom";
15
15
  import { Provider } from "react-redux";
16
16
  import { IsomorphicComponent } from "../isomorphic/component";
17
17
  import { makePickComponentSync } from "../isomorphic/impl/make-pick-component-sync";
@@ -181,21 +181,10 @@ export function maybeSetUrl(path, title) {
181
181
  export function renderComponent(clazz, container, store, props = {}, callback) {
182
182
  const component = React.createElement(Provider, { store }, React.createElement(clazz, props || {}));
183
183
 
184
- function AppWithCallbackAfterRender() {
185
- useEffect(() => {
186
- callback();
187
- });
188
-
189
- return component;
190
- }
191
-
192
- let root = createRoot(document.getElementById(container));
193
-
194
184
  if (props.hydrate) {
195
- root = hydrateRoot(document.getElementById(container));
185
+ return ReactDOM.hydrate(component, document.getElementById(container), callback);
196
186
  }
197
-
198
- return root.render(<AppWithCallbackAfterRender />);
187
+ return ReactDOM.render(component, document.getElementById(container), callback);
199
188
  }
200
189
 
201
190
  /**
@@ -293,10 +282,14 @@ export function startApp(renderApplication, reducers, opts) {
293
282
 
294
283
  store.dispatch({ type: NAVIGATE_TO_PAGE, page, currentPath: path });
295
284
 
296
- if (opts.fcmMessagingSenderId) {
297
- const mssgSenderId =
298
- typeof opts.fcmMessagingSenderId === "function" ? opts.fcmMessagingSenderId(page) : opts.fcmMessagingSenderId;
299
- mssgSenderId && initializeFCM(mssgSenderId);
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
+ }
300
293
  }
301
294
 
302
295
  const { config: { "theme-attributes": pageThemeAttributes = {} } = {} } = page;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.4.0-react-18.0",
3
+ "version": "7.4.0-update-build.0",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,18 +27,19 @@
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.19",
30
+ "@quintype/amp": "^2.4.20",
31
31
  "@quintype/backend": "^2.3.1",
32
32
  "@quintype/components": "^3.0.0",
33
33
  "@quintype/prerender-node": "^3.2.24",
34
- "@quintype/seo": "^1.38.1",
34
+ "@quintype/seo": "^1.39.0",
35
35
  "atob": "^2.1.2",
36
+ "babel-plugin-react-css-modules": "^5.2.6",
36
37
  "chalk": "^4.1.2",
37
38
  "cluster": "^0.7.7",
38
39
  "compression": "^1.7.4",
39
40
  "ejs": "^3.1.6",
40
41
  "express": "^4.17.1",
41
- "firebase": "^6.0.2",
42
+ "firebase": "^9.6.10",
42
43
  "get-youtube-id": "^1.0.1",
43
44
  "grpc": "^1.21.1",
44
45
  "http-proxy": "^1.18.1",
@@ -46,9 +47,9 @@
46
47
  "lodash": "^4.17.21",
47
48
  "mocha-snapshots": "^4.2.0",
48
49
  "morgan": "^1.10.0",
49
- "path-to-regexp": "^6.2.0",
50
- "react": "^18.0.0",
51
- "react-dom": "^18.0.0",
50
+ "path-to-regexp": "^6.2.1",
51
+ "react": "^16.14.0",
52
+ "react-dom": "^16.14.0",
52
53
  "react-redux": "^7.2.5",
53
54
  "react-router": "^5.2.1",
54
55
  "redux": "^4.1.1",
@@ -60,9 +61,8 @@
60
61
  "@babel/eslint-parser": "^7.15.7",
61
62
  "@loadable/component": "^5.15.0",
62
63
  "@loadable/server": "^5.15.1",
63
- "@quintype/build": "^3.13.1",
64
+ "@quintype/build": "^4.0.0",
64
65
  "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",