@pocketping/sdk-node 1.5.0 → 1.7.0
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 +58 -0
- package/dist/index.cjs +2720 -2249
- package/dist/index.d.cts +433 -334
- package/dist/index.d.ts +433 -334
- package/dist/index.js +2708 -2244
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Node.js SDK for PocketPing - real-time customer chat with mobile notifications.
|
|
4
4
|
|
|
5
|
+
> **Tip:** Use the CLI for guided bridge setup: `npx @pocketping/cli init`
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -143,6 +145,62 @@ const clientIp = pp.getClientIp(request.headers);
|
|
|
143
145
|
// Checks: CF-Connecting-IP, X-Real-IP, X-Forwarded-For
|
|
144
146
|
```
|
|
145
147
|
|
|
148
|
+
## User-Agent Filtering
|
|
149
|
+
|
|
150
|
+
Block bots and automated requests from creating chat sessions:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const pp = new PocketPing({
|
|
154
|
+
uaFilter: {
|
|
155
|
+
enabled: true,
|
|
156
|
+
mode: 'blocklist', // 'blocklist' | 'allowlist' | 'both'
|
|
157
|
+
useDefaultBots: true, // Include ~50 default bot patterns
|
|
158
|
+
blocklist: ['my-custom-scraper', '/spam-\\d+/'], // Custom patterns
|
|
159
|
+
allowlist: ['my-monitoring-bot'], // Always allow these
|
|
160
|
+
logBlocked: true,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Filter Modes
|
|
166
|
+
|
|
167
|
+
| Mode | Behavior |
|
|
168
|
+
|------|----------|
|
|
169
|
+
| `blocklist` | Block matching UAs, allow all others |
|
|
170
|
+
| `allowlist` | Only allow matching UAs, block all others |
|
|
171
|
+
| `both` | Allowlist takes precedence, then blocklist is applied |
|
|
172
|
+
|
|
173
|
+
### Pattern Matching
|
|
174
|
+
|
|
175
|
+
- **Substring**: `googlebot` matches any UA containing "googlebot" (case-insensitive)
|
|
176
|
+
- **Regex**: `/bot-\d+/` - wrap pattern in `/` for regex matching
|
|
177
|
+
|
|
178
|
+
### Default Bot Patterns (~50)
|
|
179
|
+
|
|
180
|
+
When `useDefaultBots: true`, these are blocked automatically:
|
|
181
|
+
- Search crawlers: GoogleBot, BingBot, DuckDuckBot, etc.
|
|
182
|
+
- SEO tools: SEMrush, Ahrefs, Screaming Frog
|
|
183
|
+
- HTTP libraries: curl, wget, Python-requests, axios
|
|
184
|
+
- AI crawlers: GPTBot, ChatGPT-User, Anthropic-AI
|
|
185
|
+
|
|
186
|
+
### Manual UA Check
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { checkUaFilter, isBot, DEFAULT_BOT_PATTERNS } from '@pocketping/sdk-node';
|
|
190
|
+
|
|
191
|
+
// Quick bot check
|
|
192
|
+
if (isBot(req.headers['user-agent'])) {
|
|
193
|
+
return res.status(403).json({ error: 'Bots not allowed' });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Full filter check
|
|
197
|
+
const result = checkUaFilter(req.headers['user-agent'], {
|
|
198
|
+
enabled: true,
|
|
199
|
+
useDefaultBots: true,
|
|
200
|
+
});
|
|
201
|
+
// result: { allowed: boolean, reason: string, matchedPattern?: string }
|
|
202
|
+
```
|
|
203
|
+
|
|
146
204
|
## Built-in Bridges
|
|
147
205
|
|
|
148
206
|
The SDK includes built-in bridges for Telegram, Discord, and Slack. No external libraries required - all communication uses HTTP APIs directly.
|