mbnotify-app 1.0.4 โ†’ 1.0.5

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.
Files changed (2) hide show
  1. package/README.md +291 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+
2
+ ---
3
+
4
+ # ๐Ÿš€ mbnotify Ecosystem
5
+
6
+ A **real-time push notification system** for web & mobile apps powered by MQTT.
7
+
8
+ This ecosystem consists of two packages:
9
+
10
+ * ๐Ÿ“ฆ **mbnotify** โ†’ Send notifications (Backend / Server)
11
+ * ๐Ÿ“ฑ **mbnotify-app** โ†’ Receive notifications (Expo / React Native)
12
+
13
+ ---
14
+
15
+ # ๐Ÿ“ฆ 1. mbnotify (Server / Sender)
16
+
17
+ Send push notifications to devices instantly.
18
+
19
+ ## ๐Ÿ“ฅ Installation
20
+
21
+ ```bash
22
+ npm install mbnotify
23
+ ```
24
+
25
+ ## โšก Usage
26
+
27
+ ```js
28
+ import { sendNotification } from "mbnotify";
29
+
30
+ await sendNotification({
31
+ appName: "myapp",
32
+ token: "dev_xxxxxxxxxxxxx",
33
+
34
+ title: "Order Shipped ๐Ÿšš",
35
+ body: "Your order has been shipped!",
36
+
37
+ icon: "https://cdn-icons-png.flaticon.com/512/1827/1827392.png",
38
+ image: "https://images.unsplash.com/photo-1586528116311-ad8dd3c8310d?w=1200",
39
+
40
+ url: "https://google.com",
41
+
42
+ data: {
43
+ orderId: "12345"
44
+ }
45
+ });
46
+
47
+ console.log("โœ… Notification sent");
48
+ ```
49
+
50
+ ---
51
+
52
+ ## ๐Ÿงพ Payload Options
53
+
54
+ | Field | Type | Description |
55
+ | ------- | ------ | -------------------- |
56
+ | appName | string | App identifier |
57
+ | token | string | Device token |
58
+ | title | string | Notification title |
59
+ | body | string | Notification message |
60
+ | icon | string | Small icon URL |
61
+ | image | string | Large image URL |
62
+ | url | string | Deep link / redirect |
63
+ | data | object | Custom payload |
64
+
65
+ ---
66
+
67
+ ## ๐ŸŽฏ Features
68
+
69
+ * โšก Real-time delivery
70
+ * ๐ŸŒ Works globally via MQTT
71
+ * ๐Ÿ“ฆ Lightweight API
72
+ * ๐Ÿ”— Supports deep linking
73
+ * ๐Ÿง  Custom data payloads
74
+
75
+ ---
76
+
77
+ # ๐Ÿ“ฑ 2. mbnotify-app (Client / Receiver)
78
+
79
+ Receive notifications inside your **Expo / React Native app**.
80
+
81
+ ---
82
+
83
+ ## ๐Ÿ“ฅ Installation
84
+
85
+ ```bash
86
+ npm install mbnotify-app
87
+ ```
88
+
89
+ Also install Expo notifications:
90
+
91
+ ```bash
92
+ npx expo install expo-notifications
93
+ ```
94
+
95
+ ---
96
+
97
+ ## โš™๏ธ Setup
98
+
99
+ ### โœ… Required Fix (VERY IMPORTANT)
100
+
101
+ React Native doesn't support some Node modules by default:
102
+
103
+ ```js
104
+ import { Buffer } from "buffer";
105
+ import process from "process";
106
+
107
+ global.Buffer = Buffer;
108
+ global.process = process;
109
+ ```
110
+
111
+ ---
112
+
113
+ ## ๐Ÿš€ Basic Usage
114
+
115
+ ```js
116
+ import { useEffect, useState } from "react";
117
+ import { Text, View } from "react-native";
118
+ import * as Notifications from "expo-notifications";
119
+
120
+ import { requestPermission, getToken } from "mbnotify-app";
121
+
122
+ // Show notifications in foreground
123
+ Notifications.setNotificationHandler({
124
+ handleNotification: async () => ({
125
+ shouldShowAlert: true,
126
+ shouldPlaySound: true,
127
+ shouldSetBadge: false,
128
+ }),
129
+ });
130
+
131
+ export default function App() {
132
+
133
+ const [token, setToken] = useState(null);
134
+ const [status, setStatus] = useState("Initializing...");
135
+
136
+ useEffect(() => {
137
+
138
+ async function init() {
139
+
140
+ try {
141
+ setStatus("Requesting permission...");
142
+
143
+ const granted = await requestPermission();
144
+
145
+ if (!granted) {
146
+ setStatus("โŒ Permission denied");
147
+ return;
148
+ }
149
+
150
+ setStatus("Connecting...");
151
+
152
+ const deviceToken = await getToken("myapp");
153
+
154
+ setToken(deviceToken);
155
+ setStatus("โœ… Connected");
156
+
157
+ console.log("๐Ÿ“ฑ Device token:", deviceToken);
158
+
159
+ } catch (err) {
160
+ console.error(err);
161
+ setStatus("โŒ Error initializing");
162
+ }
163
+
164
+ }
165
+
166
+ init();
167
+
168
+ }, []);
169
+
170
+ return (
171
+ <View>
172
+ <Text>{status}</Text>
173
+ {token && <Text>{token}</Text>}
174
+ </View>
175
+ );
176
+ }
177
+ ```
178
+
179
+ ---
180
+
181
+ ## ๐Ÿ”‘ Functions
182
+
183
+ ### `requestPermission()`
184
+
185
+ ```js
186
+ const granted = await requestPermission();
187
+ ```
188
+
189
+ * Requests notification permission
190
+ * Returns `true` / `false`
191
+
192
+ ---
193
+
194
+ ### `getToken(appName)`
195
+
196
+ ```js
197
+ const token = await getToken("myapp");
198
+ ```
199
+
200
+ * Connects to MQTT
201
+ * Returns a **unique device token**
202
+
203
+ ---
204
+
205
+ ## ๐Ÿ“ฒ Flow Overview
206
+
207
+ ```text
208
+ [mbnotify-app] โ†’ Generates Token
209
+ โ†“
210
+ [Your Server] โ†’ Stores Token
211
+ โ†“
212
+ [mbnotify] โ†’ Sends Notification
213
+ โ†“
214
+ [Device] โ†’ Receives Notification ๐Ÿš€
215
+ ```
216
+
217
+ ---
218
+
219
+ ## ๐Ÿ”ฅ Features
220
+
221
+ * ๐Ÿ“ก Real-time notifications (MQTT)
222
+ * ๐Ÿ“ฑ Expo compatible
223
+ * ๐Ÿ”” Foreground + Background support
224
+ * ๐Ÿ” Unique device tokens
225
+ * โšก Fast & lightweight
226
+
227
+ ---
228
+
229
+ ## โš ๏ธ Common Issues
230
+
231
+ ### โŒ MQTT Errors in React Native
232
+
233
+ Fix:
234
+
235
+ ```js
236
+ global.Buffer = require("buffer").Buffer;
237
+ global.process = require("process");
238
+ ```
239
+
240
+ ---
241
+
242
+ ### โŒ Notifications not showing
243
+
244
+ Make sure:
245
+
246
+ * Permission is granted
247
+ * `Notifications.setNotificationHandler` is configured
248
+ * App is not restricted by OS battery settings
249
+
250
+ ---
251
+
252
+ ## ๐Ÿ’ก Best Practices
253
+
254
+ * Store tokens securely in DB
255
+ * Use meaningful `appName`
256
+ * Avoid sending too many notifications
257
+ * Use `data` for deep linking/navigation
258
+
259
+ ---
260
+
261
+ ## ๐Ÿงช Example Use Case
262
+
263
+ * ๐Ÿ›’ E-commerce โ†’ Order updates
264
+ * ๐Ÿ’ฌ Chat app โ†’ New messages
265
+ * ๐Ÿ“ฆ Delivery โ†’ Status tracking
266
+ * ๐Ÿ“Š SaaS โ†’ Alerts & updates
267
+
268
+ ---
269
+
270
+ ## ๐Ÿ‘จโ€๐Ÿ’ป Author
271
+
272
+ **Manoj Gowda B R**
273
+ Full Stack Developer (MERN)
274
+
275
+ ---
276
+
277
+ ## ๐ŸŒŸ Support
278
+
279
+ If you like this project:
280
+
281
+ โญ Star the repo
282
+ ๐Ÿ› Report issues
283
+ ๐Ÿš€ Contribute improvements
284
+
285
+ ---
286
+
287
+ ## ๐Ÿ“œ License
288
+
289
+ MIT License
290
+
291
+ ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mbnotify-app",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "React Native (Expo) client for mbnotify MQTT push notifications",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",