@quatrain/messaging-firebase 1.0.13 → 1.1.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.
@@ -1,4 +1,7 @@
1
1
  import { AbstractMessagingAdapter, MessagingParameters, MessagingRecipient, NotificationCapableAdapter, NotificationMessage } from '@quatrain/messaging';
2
+ /**
3
+ * Implementation to send Firebase Cloud Messaging (FCM) notifications using `firebase-admin`.
4
+ */
2
5
  export declare class FirebaseMessagingAdapter extends AbstractMessagingAdapter implements NotificationCapableAdapter {
3
6
  protected _messaging: any;
4
7
  constructor(params?: MessagingParameters);
@@ -12,6 +15,13 @@ export declare class FirebaseMessagingAdapter extends AbstractMessagingAdapter i
12
15
  * @throws Error if recipient has no message token or Firebase send fails
13
16
  */
14
17
  sendNotification(recipient: MessagingRecipient, message: NotificationMessage): Promise<string>;
18
+ /**
19
+ * Dispatches a batch push notification payload to multiple devices simultaneously.
20
+ *
21
+ * @param recipients - Array of target contacts containing their FCM tokens.
22
+ * @param message - The Notification schema.
23
+ * @returns Response summarizing successful and failed deliveries.
24
+ */
15
25
  sendNotifications(recipients: MessagingRecipient[], message: NotificationMessage): Promise<{
16
26
  successCount: number;
17
27
  failureCount: number;
@@ -14,6 +14,9 @@ const messaging_1 = require("@quatrain/messaging");
14
14
  const firebase_admin_1 = require("firebase-admin");
15
15
  const app_1 = require("firebase-admin/app");
16
16
  const messaging_2 = require("firebase-admin/messaging");
17
+ /**
18
+ * Implementation to send Firebase Cloud Messaging (FCM) notifications using `firebase-admin`.
19
+ */
17
20
  class FirebaseMessagingAdapter extends messaging_1.AbstractMessagingAdapter {
18
21
  constructor(params = {}) {
19
22
  super(params);
@@ -71,6 +74,13 @@ class FirebaseMessagingAdapter extends messaging_1.AbstractMessagingAdapter {
71
74
  }
72
75
  });
73
76
  }
77
+ /**
78
+ * Dispatches a batch push notification payload to multiple devices simultaneously.
79
+ *
80
+ * @param recipients - Array of target contacts containing their FCM tokens.
81
+ * @param message - The Notification schema.
82
+ * @returns Response summarizing successful and failed deliveries.
83
+ */
74
84
  sendNotifications(recipients, message) {
75
85
  return __awaiter(this, void 0, void 0, function* () {
76
86
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/messaging-firebase",
3
- "version": "1.0.13",
3
+ "version": "1.1.2",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,11 +19,11 @@
19
19
  },
20
20
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
21
21
  "peerDependencies": {
22
- "@quatrain/core": "^1.1.52"
22
+ "@quatrain/core": "^1.2.9"
23
23
  },
24
24
  "dependencies": {
25
- "@quatrain/core": "^1.1.52",
26
- "@quatrain/messaging": "^1.0.14",
25
+ "@quatrain/core": "^1.2.9",
26
+ "@quatrain/messaging": "^1.1.3",
27
27
  "firebase-admin": "^13.0.1"
28
28
  },
29
29
  "devDependencies": {
@@ -42,5 +42,8 @@
42
42
  "wbuild": "tsc --watch",
43
43
  "test": "jest",
44
44
  "bump-to": "yarn version"
45
+ },
46
+ "typedoc": {
47
+ "entryPoint": "src/index.ts"
45
48
  }
46
49
  }
@@ -10,6 +10,9 @@ import { credential } from 'firebase-admin'
10
10
  import { getApps, initializeApp, ServiceAccount } from 'firebase-admin/app'
11
11
  import { getMessaging, Message } from 'firebase-admin/messaging'
12
12
 
13
+ /**
14
+ * Implementation to send Firebase Cloud Messaging (FCM) notifications using `firebase-admin`.
15
+ */
13
16
  export class FirebaseMessagingAdapter
14
17
  extends AbstractMessagingAdapter
15
18
  implements NotificationCapableAdapter
@@ -84,6 +87,13 @@ export class FirebaseMessagingAdapter
84
87
  }
85
88
  }
86
89
 
90
+ /**
91
+ * Dispatches a batch push notification payload to multiple devices simultaneously.
92
+ *
93
+ * @param recipients - Array of target contacts containing their FCM tokens.
94
+ * @param message - The Notification schema.
95
+ * @returns Response summarizing successful and failed deliveries.
96
+ */
87
97
  async sendNotifications(
88
98
  recipients: MessagingRecipient[],
89
99
  message: NotificationMessage
@@ -2,6 +2,12 @@ import { FirebaseMessagingAdapter } from '../FirebaseMessagingAdapter'
2
2
  import { MessagingRecipient, NotificationMessage } from '@quatrain/messaging'
3
3
 
4
4
  // Mock Firebase Admin SDK
5
+ jest.mock('firebase-admin', () => ({
6
+ credential: {
7
+ cert: jest.fn(() => ({})),
8
+ },
9
+ }))
10
+
5
11
  jest.mock('firebase-admin/app', () => ({
6
12
  getApps: jest.fn(() => []),
7
13
  initializeApp: jest.fn()
@@ -90,7 +96,7 @@ describe('FirebaseMessagingAdapter', () => {
90
96
  })
91
97
  })
92
98
 
93
- describe('sendMulticast', () => {
99
+ describe('sendNotifications', () => {
94
100
  const mockRecipients: MessagingRecipient[] = [
95
101
  {
96
102
  firstname: 'John',
@@ -112,7 +118,7 @@ describe('FirebaseMessagingAdapter', () => {
112
118
  }
113
119
 
114
120
  test('should send multicast notification successfully', async () => {
115
- const result = await adapter.sendMulticast(mockRecipients, mockMessage)
121
+ const result = await adapter.sendNotifications(mockRecipients, mockMessage)
116
122
 
117
123
  expect(result.successCount).toBe(2)
118
124
  expect(result.failureCount).toBe(0)
@@ -130,7 +136,7 @@ describe('FirebaseMessagingAdapter', () => {
130
136
  }
131
137
  ]
132
138
 
133
- const result = await adapter.sendMulticast(recipientsWithMissingTokens, mockMessage)
139
+ const result = await adapter.sendNotifications(recipientsWithMissingTokens, mockMessage)
134
140
  expect(result.successCount).toBe(2)
135
141
  })
136
142
 
@@ -141,7 +147,7 @@ describe('FirebaseMessagingAdapter', () => {
141
147
  }))
142
148
 
143
149
  await expect(
144
- adapter.sendMulticast(recipientsWithoutTokens, mockMessage)
150
+ adapter.sendNotifications(recipientsWithoutTokens, mockMessage)
145
151
  ).rejects.toThrow('No valid message tokens found')
146
152
  })
147
153
  })