@ayush0x44/notifystack 1.0.2 → 1.0.4
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 +78 -47
- package/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,67 +1,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 📦 @ayush0x44/notifystack
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
The official Node.js SDK for **NotifyStack** — a scalable, production-grade notification SaaS platform.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@ayush0x44/notifystack)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
## 🚀
|
|
9
|
-
|
|
10
|
-
- **Zero Dependencies**: Lightweight and fast (uses native `fetch`).
|
|
11
|
-
- **Unified API**: One interface for all channels (Email, SMS, Push, In-App).
|
|
12
|
-
- **Auto-Retry**: Built-in exponential backoff for network flakes.
|
|
13
|
-
- **Idempotency**: Safe retries without duplicate notifications.
|
|
14
|
-
- **Batching**: Send up to 100 notifications in a single call.
|
|
15
|
-
|
|
16
|
-
## 📦 Installation
|
|
8
|
+
## 🚀 Installation
|
|
17
9
|
|
|
18
10
|
```bash
|
|
19
11
|
npm install @ayush0x44/notifystack
|
|
20
12
|
```
|
|
21
13
|
|
|
22
|
-
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🔥 Features
|
|
17
|
+
- **Zero-Config:** Automatically points to the production `api.notifystack.shop` domain.
|
|
18
|
+
- **Smart Retries:** Automatic exponential backoff for failed requests.
|
|
19
|
+
- **Idempotency:** Native support for `x-idempotency-key` to prevent duplicate sends.
|
|
20
|
+
- **Multi-Channel:** Full support for Email, SMS, and Push notifications from a single client.
|
|
21
|
+
- **Health Checks:** Built-in methods to verify API connectivity.
|
|
22
|
+
|
|
23
|
+
---
|
|
23
24
|
|
|
25
|
+
## 🛠️ Usage
|
|
26
|
+
|
|
27
|
+
### ⚙️ 1. Initialization
|
|
24
28
|
```javascript
|
|
25
29
|
const { NotifySDK } = require("@ayush0x44/notifystack");
|
|
26
30
|
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
31
|
+
// Create your client (Zero-Config: no baseUrl required!)
|
|
32
|
+
const sdk = new NotifySDK("ntf_live_xxxx_your_api_key");
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 🎯 2. Event-Based Notification (Recommended)
|
|
36
|
+
Map your backend events to visual templates created in the NotifyStack Dashboard.
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
await sdk.track("USER_WELCOME", {
|
|
40
|
+
email: "user@example.com",
|
|
41
|
+
name: "Ayush",
|
|
42
|
+
plan: "Pro"
|
|
30
43
|
});
|
|
44
|
+
```
|
|
31
45
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
await notify.track("ORDER_PLACED", {
|
|
35
|
-
email: "customer@example.com",
|
|
36
|
-
orderId: "ORD-123"
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// 2. Send a direct Email
|
|
40
|
-
await notify.send({
|
|
41
|
-
to: "hello@world.com",
|
|
42
|
-
subject: "Welcome!",
|
|
43
|
-
body: "Thanks for joining our platform."
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// 3. Send an SMS
|
|
47
|
-
await notify.sendSms({
|
|
48
|
-
to: "+1234567890",
|
|
49
|
-
body: "Your verification code is 1234"
|
|
50
|
-
});
|
|
51
|
-
}
|
|
46
|
+
### ✉️ 3. Direct Email
|
|
47
|
+
Send raw email content without a template.
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
```javascript
|
|
50
|
+
await sdk.send({
|
|
51
|
+
to: "user@example.com",
|
|
52
|
+
subject: "Security Alert",
|
|
53
|
+
body: "Wait! Was this you logging in?"
|
|
54
|
+
});
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
### 📱 4. Direct SMS
|
|
58
|
+
Send SMS via Twilio (requires configuration in your NotifyStack dashboard).
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
await sdk.sendSms({
|
|
62
|
+
to: "+1234567890",
|
|
63
|
+
body: "Your verification code is: 123456"
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 🏥 5. Health Check
|
|
68
|
+
Verify your connection to the NotifyStack cloud.
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
const status = await sdk.health();
|
|
72
|
+
console.log(status.ok); // true
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🛡️ Error Handling
|
|
78
|
+
NotifyStack uses a custom error class for precise debugging.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const { NotifyError } = require("@ayush0x44/notifystack");
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await sdk.send({ ... });
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof NotifyError) {
|
|
87
|
+
console.error(`Status ${e.status}:`, e.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
57
91
|
|
|
58
|
-
|
|
59
|
-
| :--- | :--- | :--- | :--- |
|
|
60
|
-
| `baseUrl` | `string` | `http://localhost:3000` | The URL of your NotifyStack API |
|
|
61
|
-
| `maxRetries` | `number` | `3` | Max attempts for failed requests |
|
|
62
|
-
| `timeoutMs` | `number` | `10000` | Request timeout duration |
|
|
63
|
-
| `debug` | `boolean` | `false` | Enable verbose logging |
|
|
92
|
+
---
|
|
64
93
|
|
|
65
|
-
##
|
|
94
|
+
## 🔗 Resources
|
|
95
|
+
- **Live Dashboard:** [notifystack.shop](https://notifystack.shop)
|
|
96
|
+
- **API Documentation:** [notifystack.shop/docs](https://notifystack.shop/docs)
|
|
66
97
|
|
|
67
|
-
MIT ©
|
|
98
|
+
MIT © **Ayush**
|
package/index.js
CHANGED
|
@@ -15,7 +15,7 @@ class NotifySDK {
|
|
|
15
15
|
/**
|
|
16
16
|
* @param {string} apiKey - Your NotifyStack API key (ntf_live_xxx)
|
|
17
17
|
* @param {object} [options]
|
|
18
|
-
* @param {string} [options.baseUrl="
|
|
18
|
+
* @param {string} [options.baseUrl="https://api.notifystack.shop"] - API base URL
|
|
19
19
|
* @param {number} [options.maxRetries=3] - Max retry attempts
|
|
20
20
|
* @param {number} [options.timeoutMs=10000] - Request timeout in ms
|
|
21
21
|
* @param {boolean} [options.debug=false] - Enable verbose logging
|
|
@@ -25,7 +25,7 @@ class NotifySDK {
|
|
|
25
25
|
throw new Error("Invalid API key. Must start with 'ntf_live_'");
|
|
26
26
|
}
|
|
27
27
|
this.apiKey = apiKey;
|
|
28
|
-
this.baseUrl = (options.baseUrl || "
|
|
28
|
+
this.baseUrl = (options.baseUrl || "https://api.notifystack.shop").replace(/\/$/, "");
|
|
29
29
|
this.maxRetries = options.maxRetries ?? 3;
|
|
30
30
|
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
31
31
|
this.debug = options.debug || false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ayush0x44/notifystack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "The official Node.js SDK for NotifyStack — a scalable, production-ready notification SaaS platform.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=18.0.0"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|