@janiscommerce/app-push-notification 0.0.5 → 0.0.6

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.0.6] - 2025-07-13
6
+
7
+ ### Added
8
+
9
+ - cancelNotificationSuscription method
10
+
5
11
  ## [0.0.5] - 2025-06-17
6
12
 
7
13
  ### Added
package/README.md CHANGED
@@ -92,7 +92,7 @@ To use a custom sound on Android, you must:
92
92
  </tr>
93
93
  <tr>
94
94
  <td>cancelNotifications</td>
95
- <td>This util is responsible for making the request to unsubscribe from all notification events. If no arguments are received, the request will be made with the previously registered events.</td>
95
+ <td>This util is responsible for making the request to unsubscribe from all notification events. If no arguments are received, the request will be made with the previously registered events. <em>⚠️ Deprecated: Use cancelNotificationsSubscription instead.</em></td>
96
96
  </tr>
97
97
  <tr>
98
98
  <td>updateSuscription</td>
package/lib/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import NotificationProvider from './NotificationProvider';
2
2
  import {usePushNotification} from './NotificationContext';
3
3
  import {setupBackgroundMessageHandler} from './utils';
4
+ import cancelNotificationsSubscription from './utils/api/cancelNotificationsSubscription';
4
5
 
5
- export {usePushNotification, setupBackgroundMessageHandler};
6
+ export {
7
+ usePushNotification,
8
+ setupBackgroundMessageHandler,
9
+ cancelNotificationsSubscription,
10
+ };
6
11
  export default NotificationProvider;
@@ -100,6 +100,7 @@ const usePushNotification = (
100
100
  * @description This util is responsible for making the request to unsubscribe from all notification events. If no arguments are received, the request will be made with the previously registered events.
101
101
  * @param {Array<string>} events is the list of events to which I want to unsubscribe the device
102
102
  * @returns {Promise}
103
+ * @deprecated Use cancelNotificationsSubscription from the main export instead
103
104
  *
104
105
  * @example
105
106
  *
@@ -109,6 +110,10 @@ const usePushNotification = (
109
110
  */
110
111
 
111
112
  const cancelNotifications = async (cancelEvents) => {
113
+ console.warn(
114
+ '⚠️ cancelNotifications is deprecated. Use cancelNotificationsSubscription instead.',
115
+ );
116
+
112
117
  const eventsAreValid = cancelEvents && isArray(cancelEvents);
113
118
  const eventsToCancel = eventsAreValid ? cancelEvents : pushEvents;
114
119
  try {
@@ -0,0 +1,39 @@
1
+ import RequestInstance from '@janiscommerce/app-request';
2
+
3
+ /**
4
+ * Cancels push notification subscriptions for specified events
5
+ * @param {Object} params - The parameters object
6
+ * @param {string[]} [params.events=[]] - Array of event names to unsubscribe from
7
+ * @param {string} params.env - Environment identifier (required)
8
+ * @returns {Promise<Object>} Promise that resolves with the API response
9
+ * @throws {Error} When environment is not provided or API request fails
10
+ * @example
11
+ * // Cancel subscription for specific events
12
+ * await cancelNotificationsSubscription({
13
+ * events: ['user.login', 'order.created'],
14
+ * env: 'janisdev'
15
+ * });
16
+ */
17
+
18
+ const cancelNotificationsSubscription = async (params = {}) => {
19
+ try {
20
+ const {events = [], env = ''} = params;
21
+
22
+ if (!env) throw new Error('invalid environment');
23
+
24
+ const Request = new RequestInstance({JANIS_ENV: String(env)});
25
+
26
+ return await Request.post({
27
+ service: 'notification',
28
+ namespace: 'unsubscribe',
29
+ pathParams: ['push'],
30
+ body: {
31
+ events,
32
+ },
33
+ });
34
+ } catch (error) {
35
+ return Promise.reject(error);
36
+ }
37
+ };
38
+
39
+ export default cancelNotificationsSubscription;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janiscommerce/app-push-notification",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "commonjs",
5
5
  "description": "This package will take care of performing the main actions for registration to receive notifications in the foreground and background.",
6
6
  "main": "lib/index.js",