@quintype/framework 7.33.6-fcm-fix-2.6 → 7.33.6-fcm-fix-2.8

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.
@@ -14,14 +14,9 @@ export function initializeFCM (firebaseConfig) {
14
14
  appId: firebaseConfig.appId
15
15
  })
16
16
  const messaging = m.getMessaging(app)
17
- console.log('messaging----', messaging)
18
17
  await requestPermission(m, firebaseConfig, messaging)
19
- return { m, messaging }
20
- })
21
- .then(({ m, messaging }) => {
22
- console.log('abc---------', abc)
23
18
  m.onMessage(messaging, ({ notification }) => {
24
- console.log('notificaation-----', notification)
19
+ console.log('notificaation----- client', notification)
25
20
  new Notification(notification.title, {
26
21
  body: notification.body,
27
22
  icon: notification.icon
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.33.6-fcm-fix-2.6",
3
+ "version": "7.33.6-fcm-fix-2.8",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -45,7 +45,8 @@
45
45
  "compression": "^1.7.4",
46
46
  "ejs": "^3.1.6",
47
47
  "express": "^4.17.1",
48
- "firebase": "^9.23.0",
48
+ "firebase": "^10.6.0",
49
+ "firebase-admin": "^13.1.0",
49
50
  "get-youtube-id": "^1.0.1",
50
51
  "http-proxy": "^1.18.1",
51
52
  "js-yaml": "^4.1.0",
@@ -1,7 +1,6 @@
1
1
  const { get } = require('lodash')
2
2
  const request = require('request-promise')
3
- const { initializeApp } = require('firebase/app')
4
- const { getMessaging } = require('firebase/messaging')
3
+ const admin = require('firebase-admin')
5
4
 
6
5
  exports.registerFCMTopic = async function registerFCM (
7
6
  req,
@@ -16,22 +15,41 @@ exports.registerFCMTopic = async function registerFCM (
16
15
  return
17
16
  }
18
17
 
19
- const firebaseConfig = {
20
- apiKey: 'AIzaSyDh-FPToRoj1b_XvL6hWnZ84jlb_AaWG1U',
21
- authDomain: 'quintypeqa-d3e3f.firebaseapp.com',
22
- projectId: 'quintypeqa-d3e3f',
23
- storageBucket: 'quintypeqa-d3e3f.firebasestorage.app',
24
- messagingSenderId: '919899876354',
25
- appId: '1:919899876354:web:2ac17705ee7fc8364f4b1b',
26
- measurementId: 'G-V72DFHSJVX'
18
+ const fcmServiceAccountJson = {
19
+ type: 'service_account',
20
+ project_id: 'quintypeqa-d3e3f',
21
+ // private_key_id: 'a1473bd141e2db350a48dbd3a53811ec165ef117',
22
+ private_key:
23
+ '-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCzSqFIBu5ZVRnc\nRS8oBvPEDe75W80LMPsWAc+KhnSMdZr8Hwv3V2TlRECz1ty+NuiOsXoIZvTk+K6h\ntgBJnKXFFcah6O3huuUqnORZVxK4vjCyW7YP3dULsny4Xk22XruV9ktcfpfN5ruI\nyZfo7V0P0NZwr++tKTHhO/XL8io3qsUWbPwSIE5Z+8aQQIrRLr0j/zo5lKuwQDPN\nAA9BvxTSG1iPDg8r08/R5oteGjXbE5I5hfFsNImJFsGQaO4Q39EpSZxFmNlTdd3t\n+aO4J4EJFWe7W54uO+0d0xm4M7/xkIXgWnxlK2Qb0KUff7psF9ybA9a9AiXQlgKh\nE+2EZQvTAgMBAAECggEAPavrJEp2DDZwqcsGeH9DtGmSjSWdtz7G73/58s1jI7mE\ncTsAs7jVFOPQWcwLrEZY4lR8BI3dqTE9aJShLrD6eHuQErt7sAzIrUrAZVbFMtUB\nDSjszDJjCR4BNq4Bjzywy9mnfI5zCzlVwqyNW2riewE78hEioW6tIKuuVdPb37+B\n+uSprLdh/rtlC3xHJoPCIlOy6J5JbQRQwb3A88ZRgmJmPGG/CsRpz+CVU1Bsfnp+\nk2N8enhMo2NaYWq8oHjY3IdTPXWpzEIMnlsICmLAi5RbzwqSDgyUHey+gAAPVpIg\nb1qjlG8ywv0l00lCgxEspRLGI/+yiu4J5+N8CrLVcQKBgQC4lWf1BVMSvbBIc9j1\n3qJRagjq80GAjVYxnN3g36W46MDU3kPKKw2UtFmlJkcJi2DGdJBthmBVRsrPy4X0\n8dbHpISjXb4KAruhjgaAuWDk2ii9v86Nc3g6hW0tJC9dHbE9u5G0oYQsQ95a1BwY\nRU/rlvZjzLTnBBrSnzCiZ5SF6QKBgQD4qQ3JuQ+0B29edoLrh02DG4v65T1UjG0j\nxG08qcOg+KDnV7aYk/GjfF5+/hUEjgg0U3oiCv/4HulGK4hobl0LrvGasriC9T6j\nQZlUD2F5QnVAHeMzOOaJQ8wFk2it1rS4G+/kMvTkNxyDo0Lz8hHWtlxh89un26hd\nJgqKcXyiWwKBgCl4R7bgz10yiNx+SoxSzJ0F+aLvrBO5rVfQKnlPRehZQpmQpiJR\nsedq7YkRJHycd82eeqRgwFvoX8B3tUzm2J5Z9ALQGNYe7xDI2+UnwQEpkmWvJjTZ\ncHWVbIXrz0hYV23LKl0uvIdFaDt31CgPynjfndOmNi6A2ZXgdgjGxLOhAoGAIGcH\nIO44maEOZiTTUpXDB/6i8wLERyw1XJ/QDEOi9mrvrLXFWYSNzFv8hFffrURE1Wy7\nUYxVZqPAiiBKGjGndkpJuXroiEgk7Wky7b1DWmXKmZxLavVTNTfcci2PSnfb/NHH\nJNlvB/4WfSDdLKSypmQFDc6VJP5+pgS7Aude8lkCgYBM/EU9353WcWTjqMfcNDm7\nbsyDPyWibzRR29WxZWJQ9aLiVYyXTA1/dVvSkf5AluGXuMzvBuvvT0p4kj8taKI2\ny8jPHgbeWxh/cu2bg/mBxPoRTREVB7qSpJDrn/aNkL4aSXxvKI5R4ZDGppBAJMte\nkl1I6HpeDAeOTEKTdWcBvg==\n-----END PRIVATE KEY-----\n',
27
24
  }
28
- const app = initializeApp(firebaseConfig)
29
- console.log('initialze app')
30
- getMessaging().subscribeToTopic(token, "all")
31
- .then((response) => {
32
- console.log("successfully subscribe topic", response)
25
+
26
+ admin.initializeApp({
27
+ credential: admin.credential.cert(fcmServiceAccountJson)
28
+ })
29
+
30
+ console.log('admin------', admin)
31
+ const oauthToken = await admin.credential
32
+ .cert(fcmServiceAccountJson)
33
+ .getAccessToken()
34
+ .then(tokenObj => {
35
+ console.log('OAuth2 Access Token:', tokenObj)
36
+ if (tokenObj && tokenObj.access_token) {
37
+ return tokenObj.access_token
38
+ }
39
+ })
40
+ .catch(error => res.status(400).send(`Oauth Token is not available: ${error}`))
41
+
42
+ const url = `https://iid.googleapis.com/iid/v1/${token}/rel/topics/all`
43
+
44
+ await request({
45
+ uri: url,
46
+ method: 'POST',
47
+ headers: {
48
+ Authorization: `Bearer ${oauthToken}`,
49
+ 'content-type': 'application/json',
50
+ access_token_auth: true
51
+ }
33
52
  })
34
- .catch((error) => {
35
- console.log('Error subscribing to topic:', error);
36
- });
53
+ .then(() => res.status(200).send('Registration Done Successfully'))
54
+ .catch(error => res.status(500).send(`FCM Subscription Failed: ${error}`))
37
55
  }