notiformer 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.
- package/README.md +236 -62
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# notiformer
|
|
2
2
|
|
|
3
|
-
Real-time
|
|
3
|
+
Real-time push notifications and feature gates for your code.
|
|
4
4
|
|
|
5
|
-
Get notified
|
|
5
|
+
Know the moment something important happens in your app — a new sale, an error, a spike in costs. Get notified on your phone via the **Notiformer app** (iOS & Android), or in your inbox.
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> **Works everywhere.** Use in Node.js, Express, Next.js API routes, serverless functions, Python, Go, or any HTTP client.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -21,69 +21,142 @@ npm install notiformer
|
|
|
21
21
|
```ts
|
|
22
22
|
import { Notiformer } from 'notiformer';
|
|
23
23
|
|
|
24
|
-
// Get your API key at https://app.notiformer.com/projects
|
|
25
24
|
const n = new Notiformer({
|
|
26
|
-
apiKey: '
|
|
25
|
+
apiKey: 'ntf_live_...', // from app.notiformer.com/projects
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
await n.event({
|
|
30
|
-
channel: 'payments',
|
|
31
|
-
event: 'payment_success',
|
|
32
|
-
description: '$49.00 — john@example.com',
|
|
33
|
-
icon: '💳',
|
|
34
|
-
|
|
29
|
+
channel: 'payments', // groups related events — auto-created on first use
|
|
30
|
+
event: 'payment_success', // machine-readable event name
|
|
31
|
+
description: '$49.00 — john@example.com', // optional human-readable detail
|
|
32
|
+
icon: '💳', // optional emoji shown in the feed and notification
|
|
33
|
+
tags: { userId: 'usr_123', plan: 'pro' }, // optional key-value metadata
|
|
34
|
+
value: '$49.00', // optional value highlighted in the feed
|
|
35
|
+
notify: true, // true → push notification | false → silent log only
|
|
36
|
+
recipients: ['you@company.com'], // optional — notify specific people only (see below)
|
|
35
37
|
});
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
>
|
|
40
|
+
> **Tip:** Use `apiKey: 'ntf_live_test'` to get started without a real key. The SDK will print setup instructions in your console and skip all API calls.
|
|
39
41
|
|
|
40
42
|
---
|
|
41
43
|
|
|
42
44
|
## Get your API key
|
|
43
45
|
|
|
44
|
-
1. Go to [app.notiformer.com
|
|
45
|
-
2. Create
|
|
46
|
-
3. Copy the API key
|
|
47
|
-
4. Replace `'ntf_live_test'` in your code
|
|
46
|
+
1. Go to [app.notiformer.com](https://app.notiformer.com) and create an account (free)
|
|
47
|
+
2. Create a project
|
|
48
|
+
3. Copy the API key from the project overview
|
|
49
|
+
4. Replace `'ntf_live_test'` in your code with your real key
|
|
48
50
|
|
|
49
51
|
---
|
|
50
52
|
|
|
51
|
-
##
|
|
53
|
+
## `event()` — Send an event
|
|
52
54
|
|
|
53
55
|
```ts
|
|
54
56
|
await n.event({
|
|
55
|
-
channel:
|
|
56
|
-
event:
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
channel: 'payments', // required — string, lowercase, a-z 0-9 - _
|
|
58
|
+
event: 'payment_success', // required — machine-readable event name
|
|
59
|
+
|
|
60
|
+
description: '$49.00 — john@example.com', // optional
|
|
61
|
+
icon: '💳', // optional — emoji
|
|
62
|
+
tags: { plan: 'pro', userId: '123' }, // optional — displayed in the event feed
|
|
63
|
+
value: '$49.00', // optional — highlighted value in the feed
|
|
64
|
+
notify: true, // optional — default: true
|
|
65
|
+
recipients: ['alice@company.com'], // optional — see "Targeting specific people"
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `notify`
|
|
70
|
+
|
|
71
|
+
| Value | Behaviour |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `true` (default) | Sends push notification to subscribed members |
|
|
74
|
+
| `false` | Stores the event silently for analytics — no notification sent |
|
|
75
|
+
|
|
76
|
+
### Return value
|
|
59
77
|
|
|
60
|
-
|
|
61
|
-
|
|
78
|
+
```ts
|
|
79
|
+
const result = await n.event({ ... });
|
|
80
|
+
// result is null if the call failed (never throws by default)
|
|
81
|
+
// result.rateLimited === true if you exceeded 60 events/minute (event is stored, notification skipped)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`event()` **never throws by default.** A failed notification will never crash your app. If you prefer it to throw, pass `throwOnError: true` in the config.
|
|
85
|
+
|
|
86
|
+
---
|
|
62
87
|
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
## Targeting specific people — `recipients`
|
|
89
|
+
|
|
90
|
+
By default, when `notify: true`, all members of the project who are subscribed to that channel receive a notification.
|
|
91
|
+
|
|
92
|
+
You can override this and target specific people by email:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
await n.event({
|
|
96
|
+
channel: 'payments',
|
|
97
|
+
event: 'large_order',
|
|
98
|
+
description: '$2,400 — enterprise@client.com',
|
|
99
|
+
notify: true,
|
|
100
|
+
recipients: ['cto@company.com', 'billing@company.com'], // only these two are notified
|
|
65
101
|
});
|
|
66
102
|
```
|
|
67
103
|
|
|
68
|
-
|
|
104
|
+
**How it works:**
|
|
105
|
+
- If a recipient has a Notiformer account linked to that email and has installed the app, they receive a **push notification**
|
|
106
|
+
- Email notifications are **coming soon** — recipients will receive emails once this feature launches
|
|
107
|
+
- If you don't specify `recipients`, all project members subscribed to the channel are notified
|
|
108
|
+
|
|
109
|
+
**Plan limits for `recipients`:**
|
|
110
|
+
|
|
111
|
+
| Plan | Max recipients per event |
|
|
112
|
+
|---|---|
|
|
113
|
+
| Free | 1 |
|
|
114
|
+
| Starter | 3 |
|
|
115
|
+
| Pro | 10 |
|
|
116
|
+
| Business | 30 |
|
|
117
|
+
|
|
118
|
+
> Members are managed from the project dashboard at [app.notiformer.com](https://app.notiformer.com/projects).
|
|
69
119
|
|
|
70
120
|
---
|
|
71
121
|
|
|
72
|
-
## Feature
|
|
122
|
+
## `gate()` — Feature gates
|
|
73
123
|
|
|
74
|
-
Toggle features remotely from
|
|
124
|
+
Toggle features in your code remotely from the Notiformer dashboard — no redeploy needed.
|
|
75
125
|
|
|
76
126
|
```ts
|
|
77
127
|
const isEnabled = await n.gate('new-checkout-flow');
|
|
78
128
|
|
|
79
129
|
if (isEnabled) {
|
|
80
|
-
//
|
|
130
|
+
// new behaviour
|
|
81
131
|
} else {
|
|
82
|
-
//
|
|
132
|
+
// old behaviour
|
|
83
133
|
}
|
|
84
134
|
```
|
|
85
135
|
|
|
86
|
-
Gates are cached for 30 seconds by default to
|
|
136
|
+
Gates are **cached locally for 30 seconds** by default to avoid hammering the API on every request.
|
|
137
|
+
|
|
138
|
+
### Options
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const isEnabled = await n.gate('my-gate', {
|
|
142
|
+
fallback: false, // optional — returned if the gate can't be fetched (default: false)
|
|
143
|
+
cacheTtl: 60, // optional — cache duration in seconds (default: 30)
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Full gate result
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const result = await n.gateDetails('my-gate');
|
|
151
|
+
// { key: 'my-gate', enabled: true, cached: false, fetchedAt: '2025-...' }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Clear the cache
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
n.clearGateCache('my-gate'); // clear a specific gate
|
|
158
|
+
n.clearGateCache(); // clear all gates
|
|
159
|
+
```
|
|
87
160
|
|
|
88
161
|
---
|
|
89
162
|
|
|
@@ -91,12 +164,11 @@ Gates are cached for 30 seconds by default to minimise API calls.
|
|
|
91
164
|
|
|
92
165
|
```ts
|
|
93
166
|
const n = new Notiformer({
|
|
94
|
-
apiKey:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.error(err.message);
|
|
167
|
+
apiKey: 'ntf_live_...', // required — from app.notiformer.com/projects
|
|
168
|
+
silent: false, // optional — true = no API calls (great for local dev)
|
|
169
|
+
throwOnError: false, // optional — true = throws instead of returning null
|
|
170
|
+
onError: (err) => { // optional — called when any call fails
|
|
171
|
+
Sentry.captureException(err);
|
|
100
172
|
},
|
|
101
173
|
});
|
|
102
174
|
```
|
|
@@ -106,65 +178,165 @@ const n = new Notiformer({
|
|
|
106
178
|
```ts
|
|
107
179
|
const n = new Notiformer({
|
|
108
180
|
apiKey: process.env.NOTIFORMER_API_KEY!,
|
|
109
|
-
silent: process.env.NODE_ENV !== 'production',
|
|
181
|
+
silent: process.env.NODE_ENV !== 'production', // no calls in dev/test
|
|
110
182
|
});
|
|
111
183
|
```
|
|
112
184
|
|
|
113
185
|
---
|
|
114
186
|
|
|
187
|
+
## Rate limits & quotas
|
|
188
|
+
|
|
189
|
+
| Limit | Value |
|
|
190
|
+
|---|---|
|
|
191
|
+
| Events per minute (per project) | 60 |
|
|
192
|
+
| Events per month (Free plan) | 500 |
|
|
193
|
+
| Events per month (Starter) | 20,000 |
|
|
194
|
+
| Events per month (Pro) | 75,000 |
|
|
195
|
+
| Events per month (Business) | 300,000 |
|
|
196
|
+
|
|
197
|
+
If you exceed **60 events/minute**: the event is stored and visible in your feed, but no notification is sent. The API response includes `rateLimited: true`.
|
|
198
|
+
|
|
199
|
+
If you exceed your **monthly quota**: the event is rejected with HTTP 429. Upgrade your plan at [app.notiformer.com/settings](https://app.notiformer.com/settings).
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
115
203
|
## Common patterns
|
|
116
204
|
|
|
205
|
+
### Alert on payment success
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
await n.event({
|
|
209
|
+
channel: 'payments',
|
|
210
|
+
event: 'payment_success',
|
|
211
|
+
description: `${amount} — ${user.email}`,
|
|
212
|
+
icon: '💳',
|
|
213
|
+
value: amount,
|
|
214
|
+
notify: true,
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
117
218
|
### Alert on unhandled errors
|
|
118
219
|
|
|
119
220
|
```ts
|
|
221
|
+
// Express error middleware
|
|
120
222
|
app.use(async (err, req, res, next) => {
|
|
121
223
|
await n.event({
|
|
122
|
-
channel:
|
|
123
|
-
event:
|
|
224
|
+
channel: 'errors',
|
|
225
|
+
event: 'unhandled_error',
|
|
124
226
|
description: err.message,
|
|
125
|
-
icon:
|
|
126
|
-
tags:
|
|
127
|
-
notify:
|
|
227
|
+
icon: '🔴',
|
|
228
|
+
tags: { path: req.path, method: req.method },
|
|
229
|
+
notify: true,
|
|
128
230
|
});
|
|
129
231
|
res.status(500).json({ error: 'Internal server error' });
|
|
130
232
|
});
|
|
131
233
|
```
|
|
132
234
|
|
|
133
|
-
###
|
|
235
|
+
### Silent analytics (no notification)
|
|
134
236
|
|
|
135
237
|
```ts
|
|
136
238
|
await n.event({
|
|
137
|
-
channel: '
|
|
138
|
-
event:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
value: amount,
|
|
142
|
-
notify: true,
|
|
239
|
+
channel: 'analytics',
|
|
240
|
+
event: 'page_view',
|
|
241
|
+
tags: { path: req.path, userId: session.userId },
|
|
242
|
+
notify: false, // stored in feed, no push notification sent
|
|
143
243
|
});
|
|
144
244
|
```
|
|
145
245
|
|
|
146
|
-
### Feature gate
|
|
246
|
+
### Feature gate in an API route
|
|
147
247
|
|
|
148
248
|
```ts
|
|
149
|
-
|
|
249
|
+
// Next.js API route
|
|
250
|
+
export async function POST(req: Request) {
|
|
150
251
|
const useNewFlow = await n.gate('new-checkout-flow');
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
252
|
+
|
|
253
|
+
if (useNewFlow) {
|
|
254
|
+
return newCheckoutHandler(req);
|
|
255
|
+
}
|
|
256
|
+
return legacyCheckoutHandler(req);
|
|
257
|
+
}
|
|
155
258
|
```
|
|
156
259
|
|
|
157
|
-
###
|
|
260
|
+
### Notify a specific person
|
|
158
261
|
|
|
159
262
|
```ts
|
|
263
|
+
// Only notify the CTO for large orders
|
|
160
264
|
await n.event({
|
|
161
|
-
channel:
|
|
162
|
-
event:
|
|
163
|
-
|
|
164
|
-
|
|
265
|
+
channel: 'sales',
|
|
266
|
+
event: 'enterprise_signup',
|
|
267
|
+
description: `${company} — ${mrr}/mo`,
|
|
268
|
+
icon: '🏢',
|
|
269
|
+
value: mrr,
|
|
270
|
+
notify: true,
|
|
271
|
+
recipients: ['cto@yourcompany.com'], // only they get the push
|
|
165
272
|
});
|
|
166
273
|
```
|
|
167
274
|
|
|
275
|
+
### Using with Python (REST API)
|
|
276
|
+
|
|
277
|
+
Notiformer works from any language via the REST API:
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
import requests
|
|
281
|
+
|
|
282
|
+
requests.post(
|
|
283
|
+
'https://api.notiformer.com/v1/events',
|
|
284
|
+
headers={ 'Authorization': f'Bearer {NF_KEY}' },
|
|
285
|
+
json={
|
|
286
|
+
'channel': 'ai-costs',
|
|
287
|
+
'event': 'cost_spike',
|
|
288
|
+
'description': '🤖 $180 spent in 10 min',
|
|
289
|
+
'notify': True,
|
|
290
|
+
'recipients': ['cto@company.com'], # optional
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Receiving notifications
|
|
298
|
+
|
|
299
|
+
Push notifications are delivered via the **Notiformer app**, available for iOS and Android.
|
|
300
|
+
|
|
301
|
+
1. Download the Notiformer app from the App Store or Google Play
|
|
302
|
+
2. Sign in with your Notiformer account
|
|
303
|
+
3. You'll automatically receive push notifications for projects you own or are a member of
|
|
304
|
+
4. Manage which channels you're subscribed to from the app settings
|
|
305
|
+
|
|
306
|
+
> **Email notifications** are in development and coming soon. Sign up at [notiformer.com](https://notiformer.com) to be notified when they launch.
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## REST API
|
|
311
|
+
|
|
312
|
+
The same `event()` call maps to this endpoint:
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
POST https://api.notiformer.com/v1/events
|
|
316
|
+
Authorization: Bearer ntf_live_...
|
|
317
|
+
Content-Type: application/json
|
|
318
|
+
|
|
319
|
+
{
|
|
320
|
+
"channel": "payments",
|
|
321
|
+
"event": "payment_success",
|
|
322
|
+
"description": "$49.00 — john@example.com",
|
|
323
|
+
"icon": "💳",
|
|
324
|
+
"tags": { "plan": "pro" },
|
|
325
|
+
"value": "$49.00",
|
|
326
|
+
"notify": true,
|
|
327
|
+
"recipients": ["you@company.com"]
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Response:
|
|
332
|
+
```json
|
|
333
|
+
{
|
|
334
|
+
"id": "evt_abc123",
|
|
335
|
+
"createdAt": "2025-01-15T10:30:00.000Z",
|
|
336
|
+
"rateLimited": false
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
168
340
|
---
|
|
169
341
|
|
|
170
342
|
## Requirements
|
|
@@ -176,5 +348,7 @@ await n.event({
|
|
|
176
348
|
|
|
177
349
|
## Links
|
|
178
350
|
|
|
179
|
-
- Dashboard
|
|
180
|
-
- Docs
|
|
351
|
+
- **Dashboard:** [app.notiformer.com](https://app.notiformer.com)
|
|
352
|
+
- **Docs:** [docs.notiformer.com](https://docs.notiformer.com)
|
|
353
|
+
- **Status:** [status.notiformer.com](https://status.notiformer.com)
|
|
354
|
+
- **Pricing:** [notiformer.com/#pricing](https://notiformer.com/#pricing)
|
package/dist/index.js
CHANGED
|
@@ -164,7 +164,7 @@ class Notiformer {
|
|
|
164
164
|
headers: {
|
|
165
165
|
"Content-Type": "application/json",
|
|
166
166
|
Authorization: `Bearer ${this.apiKey}`,
|
|
167
|
-
"X-SDK-Version": "1.0.
|
|
167
|
+
"X-SDK-Version": "1.0.5",
|
|
168
168
|
...((_a = init.headers) !== null && _a !== void 0 ? _a : {}),
|
|
169
169
|
},
|
|
170
170
|
});
|