@subscribeflow/sdk 1.0.25 → 1.0.26

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 +134 -78
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,43 +1,64 @@
1
+ <p align="center">
2
+ <a href="https://subscribeflow.net">
3
+ <img src="https://docs.subscribeflow.net/assets/sdk-hero.svg" alt="SubscribeFlow" width="100%">
4
+ </a>
5
+ </p>
6
+
1
7
  # @subscribeflow/sdk
2
8
 
3
- Official TypeScript SDK for the SubscribeFlow API.
9
+ Official TypeScript SDK for SubscribeFlow — full type safety, tree-shakeable, zero dependencies. Manage email subscriptions, campaigns, and GDPR-compliant preference centers.
10
+
11
+ [![npm Version](https://img.shields.io/npm/v/@subscribeflow/sdk)](https://www.npmjs.com/package/@subscribeflow/sdk)
12
+ [![npm Downloads](https://img.shields.io/npm/dm/@subscribeflow/sdk)](https://www.npmjs.com/package/@subscribeflow/sdk)
13
+ [![Node Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://www.npmjs.com/package/@subscribeflow/sdk)
14
+ [![License](https://img.shields.io/npm/l/@subscribeflow/sdk)](https://www.npmjs.com/package/@subscribeflow/sdk)
15
+ [![Works with Claude](https://img.shields.io/badge/Works%20with-Claude-blueviolet)](https://docs.subscribeflow.net/sdk/mcp)
16
+
17
+ [Dashboard](https://subscribeflow.net) | [Documentation](https://docs.subscribeflow.net) | [API Reference](https://docs.subscribeflow.net/api/reference) | [MCP Integration](https://docs.subscribeflow.net/sdk/mcp)
18
+
19
+ ---
4
20
 
5
21
  ## Installation
6
22
 
7
- ### Von GitHub (Empfohlen)
23
+ ### From npm (Recommended)
24
+
25
+ Install the SDK using your preferred package manager:
8
26
 
9
27
  ```bash
10
28
  # npm
11
- npm install git+https://github.com/talent-factory/subscribe-flow.git#subdirectory=sdk/typescript
29
+ npm install @subscribeflow/sdk
12
30
 
13
31
  # yarn
14
- yarn add git+https://github.com/talent-factory/subscribe-flow.git#subdirectory=sdk/typescript
32
+ yarn add @subscribeflow/sdk
15
33
 
16
34
  # bun
17
- bun add github:talent-factory/subscribe-flow#subdirectory=sdk/typescript
35
+ bun add @subscribeflow/sdk
18
36
  ```
19
37
 
20
- In `package.json`:
38
+ Or add it directly to your `package.json`:
39
+
21
40
  ```json
22
41
  {
23
42
  "dependencies": {
24
- "@subscribeflow/sdk": "git+https://github.com/talent-factory/subscribe-flow.git#subdirectory=sdk/typescript"
43
+ "@subscribeflow/sdk": "^1.0.0"
25
44
  }
26
45
  }
27
46
  ```
28
47
 
29
- ### Lokale Entwicklung
48
+ ### Local Development
49
+
50
+ If you are developing the SDK alongside your application, you can link it locally instead of installing from the registry.
30
51
 
31
- Für parallele Entwicklung von SDK und Anwendung gibt es mehrere Optionen:
52
+ #### Option 1: `file:` Protocol (Simplest)
32
53
 
33
- #### Option 1: `file:` Protokoll (Einfachste)
54
+ Point your dependency directly at the local SDK directory:
34
55
 
35
56
  ```bash
36
57
  # npm/yarn/pnpm
37
- npm install /pfad/zu/subscribeflow/sdk/typescript
58
+ npm install /path/to/subscribeflow/sdk/typescript
38
59
 
39
60
  # bun
40
- bun add /pfad/zu/subscribeflow/sdk/typescript
61
+ bun add /path/to/subscribeflow/sdk/typescript
41
62
  ```
42
63
 
43
64
  In `package.json`:
@@ -51,21 +72,23 @@ In `package.json`:
51
72
 
52
73
  #### Option 2: `npm link` / `bun link` (Symlink)
53
74
 
75
+ Create a global symlink so changes to the SDK are reflected immediately without reinstalling:
76
+
54
77
  ```bash
55
- # Im SDK-Verzeichnis
56
- cd /pfad/zu/subscribeflow/sdk/typescript
57
- npm link # oder: bun link
78
+ # In the SDK directory
79
+ cd /path/to/subscribeflow/sdk/typescript
80
+ npm link # or: bun link
58
81
 
59
- # In deinem Projekt
60
- cd /pfad/zu/deinem/projekt
61
- npm link @subscribeflow/sdk # oder: bun link @subscribeflow/sdk
82
+ # In your project
83
+ cd /path/to/your/project
84
+ npm link @subscribeflow/sdk # or: bun link @subscribeflow/sdk
62
85
  ```
63
86
 
64
- **Vorteil:** Änderungen am SDK sind sofort verfügbar ohne Neuinstallation.
87
+ **Advantage:** Any change you make to the SDK source is immediately available in your project without reinstalling.
65
88
 
66
89
  #### Option 3: Workspace (Monorepo)
67
90
 
68
- Für Projekte im selben Repository:
91
+ For projects within the same repository, use workspaces:
69
92
 
70
93
  ```json
71
94
  // package.json (root)
@@ -74,14 +97,16 @@ Für Projekte im selben Repository:
74
97
  }
75
98
  ```
76
99
 
77
- ### Best Practice für lokale Entwicklung
100
+ ### Best Practices for Local Development
78
101
 
79
- 1. **Während der Entwicklung:** `npm link` oder `file:` verwenden
80
- 2. **Vor dem Commit:** Auf GitHub-URL umstellen
81
- 3. **CI/CD:** GitHub-URL nutzen
102
+ 1. **During development:** Use `npm link` or `file:` for fast iteration
103
+ 2. **Before committing:** Switch back to the npm registry version
104
+ 3. **CI/CD:** Always use the npm registry
82
105
 
83
106
  ## Quick Start
84
107
 
108
+ The following example shows how to initialize the client and create your first subscriber. You need an API key, which you can generate from your SubscribeFlow admin dashboard.
109
+
85
110
  ```typescript
86
111
  import { SubscribeFlowClient } from '@subscribeflow/sdk';
87
112
 
@@ -90,7 +115,7 @@ const client = new SubscribeFlowClient({
90
115
  baseUrl: 'https://api.subscribeflow.net', // optional, this is the default
91
116
  });
92
117
 
93
- // Create a subscriber
118
+ // Create a subscriber with tags and metadata
94
119
  const subscriber = await client.subscribers.create({
95
120
  email: 'user@example.com',
96
121
  tags: ['newsletter', 'product-updates'],
@@ -104,51 +129,60 @@ console.log('Created subscriber:', subscriber.id);
104
129
 
105
130
  ### Subscribers
106
131
 
132
+ Subscribers are the core entity in SubscribeFlow. Each subscriber represents a person identified by their email address. You can list, create, update, and delete subscribers, as well as manage their tag subscriptions and metadata.
133
+
107
134
  ```typescript
108
- // List subscribers
135
+ // List subscribers with optional filters
136
+ // Returns paginated results with items, total count, and cursor for pagination
109
137
  const { items, total, cursor } = await client.subscribers.list({
110
138
  limit: 50,
111
139
  status: 'active',
112
140
  });
113
141
 
114
- // Get a subscriber
142
+ // Get a single subscriber by ID
115
143
  const subscriber = await client.subscribers.get('subscriber-id');
116
144
 
117
- // Update a subscriber
145
+ // Update subscriber metadata
146
+ // Only the fields you pass will be changed; everything else stays the same
118
147
  const updated = await client.subscribers.update('subscriber-id', {
119
148
  metadata: { plan: 'premium' },
120
149
  });
121
150
 
122
- // Delete a subscriber
151
+ // Permanently delete a subscriber and all associated data
123
152
  await client.subscribers.delete('subscriber-id');
124
153
  ```
125
154
 
126
155
  ### Tags
127
156
 
157
+ Tags represent topics or categories that subscribers can opt into. They are the building block of SubscribeFlow's granular preference management. Unlike traditional mailing lists, subscribers can actively discover and subscribe to tags they are interested in.
158
+
128
159
  ```typescript
129
- // Create a tag
160
+ // Create a new tag with a human-readable name and a URL-safe slug
130
161
  const tag = await client.tags.create({
131
162
  name: 'Product Updates',
132
163
  slug: 'product-updates',
133
164
  description: 'Get notified about new features and improvements',
134
165
  });
135
166
 
136
- // List tags
167
+ // List all tags in your organization
137
168
  const { items } = await client.tags.list();
138
169
 
139
- // Update a tag
170
+ // Update a tag's description or other properties
140
171
  await client.tags.update('tag-id', {
141
172
  description: 'Updated description',
142
173
  });
143
174
 
144
- // Delete a tag
175
+ // Delete a tag (subscribers will be automatically unsubscribed)
145
176
  await client.tags.delete('tag-id');
146
177
  ```
147
178
 
148
179
  ### Templates
149
180
 
181
+ Templates define the content and layout of your emails. SubscribeFlow uses MJML for responsive email rendering and supports Mustache-style variables for dynamic content.
182
+
150
183
  ```typescript
151
- // Create an email template
184
+ // Create a new email template with MJML content
185
+ // Variables like {{company}} will be replaced when sending
152
186
  const template = await client.templates.create({
153
187
  name: 'Welcome Email',
154
188
  subject: 'Welcome to {{company}}!',
@@ -156,19 +190,19 @@ const template = await client.templates.create({
156
190
  category: 'transactional',
157
191
  });
158
192
 
159
- // List templates
193
+ // List templates, optionally filtered by category
160
194
  const { items } = await client.templates.list({ category: 'transactional' });
161
195
 
162
- // Get a template by slug
196
+ // Look up a template by its slug (useful for send operations)
163
197
  const tmpl = await client.templates.getBySlug('welcome-email');
164
198
 
165
- // Preview a template
199
+ // Preview how a template will look with specific variable values
166
200
  const preview = await client.templates.preview('template-id', {
167
201
  company: 'Acme Inc',
168
202
  });
169
203
  console.log(preview.html);
170
204
 
171
- // Update a template
205
+ // Update a template's subject or content
172
206
  await client.templates.update('template-id', { subject: 'New Subject' });
173
207
 
174
208
  // Delete a template
@@ -177,131 +211,143 @@ await client.templates.delete('template-id');
177
211
 
178
212
  ### Email Send
179
213
 
214
+ Send individual transactional emails using a template. Each send requires a template slug and recipient. The optional `idempotency_key` prevents duplicate sends if the same request is retried.
215
+
180
216
  ```typescript
181
- // Send a transactional email
217
+ // Send a transactional email to a single recipient
182
218
  const result = await client.emails.send({
183
219
  template_slug: 'welcome-email',
184
220
  to: 'user@example.com',
185
221
  variables: { company: 'Acme Inc' },
186
- idempotency_key: 'unique-key-123',
222
+ idempotency_key: 'unique-key-123', // prevents duplicate sends on retry
187
223
  });
188
224
  console.log('Email queued:', result.id);
189
225
  ```
190
226
 
191
227
  ### Campaigns
192
228
 
229
+ Campaigns let you send emails to groups of subscribers based on tag filters. Create a draft, preview the recipient count, and then send it. Running campaigns can be cancelled.
230
+
193
231
  ```typescript
194
- // Create a campaign
232
+ // Create a campaign draft targeting subscribers with specific tags
195
233
  const campaign = await client.campaigns.create({
196
234
  name: 'February Newsletter',
197
235
  template_id: 'template-uuid',
198
236
  tag_filter: { include_tags: ['newsletter'], match: 'any' },
199
237
  });
200
238
 
201
- // List campaigns
239
+ // List campaigns filtered by status
202
240
  const campaigns = await client.campaigns.list({ status: 'draft' });
203
241
 
204
- // Preview recipient count
242
+ // Preview how many subscribers will receive this campaign
205
243
  const count = await client.campaigns.countRecipients('campaign-id');
206
244
  console.log(`Will send to ${count.count} subscribers`);
207
245
 
208
- // Send the campaign
246
+ // Send the campaign (moves from draft to sending)
209
247
  const sendResult = await client.campaigns.send('campaign-id');
210
248
 
211
- // Cancel a running campaign
249
+ // Cancel a running campaign (emails already sent cannot be recalled)
212
250
  await client.campaigns.cancel('campaign-id');
213
251
  ```
214
252
 
215
253
  ### Email Triggers
216
254
 
255
+ Triggers automatically send emails in response to events. For example, you can send a welcome email whenever a new subscriber is created. Triggers can be activated or deactivated without deleting them.
256
+
217
257
  ```typescript
218
- // Create an event-based trigger
258
+ // Create a trigger that fires when a subscriber is created
219
259
  const trigger = await client.triggers.create({
220
260
  event_type: 'subscriber.created',
221
261
  template_id: 'welcome-template-uuid',
222
262
  description: 'Send welcome email on signup',
223
263
  });
224
264
 
225
- // List triggers
265
+ // List all triggers
226
266
  const triggers = await client.triggers.list();
227
267
 
228
- // Update a trigger
268
+ // Deactivate a trigger without deleting it
229
269
  await client.triggers.update('trigger-id', { is_active: false });
230
270
 
231
- // Delete a trigger
271
+ // Permanently delete a trigger
232
272
  await client.triggers.delete('trigger-id');
233
273
  ```
234
274
 
235
275
  ### Webhooks
236
276
 
277
+ Webhooks let your application receive real-time notifications when events occur in SubscribeFlow. Each webhook endpoint receives signed HTTP POST requests that you can verify using the signing secret.
278
+
237
279
  ```typescript
238
- // Create a webhook endpoint
280
+ // Register a new webhook endpoint for specific event types
239
281
  const webhook = await client.webhooks.create({
240
282
  url: 'https://your-app.com/webhooks/subscribeflow',
241
283
  events: ['subscriber.created', 'tag.subscribed'],
242
284
  description: 'Main webhook endpoint',
243
285
  });
244
286
 
245
- // The signing secret is only returned on creation
287
+ // Important: the signing secret is only returned on creation — store it securely
246
288
  console.log('Signing secret:', webhook.signing_secret);
247
289
 
248
- // List webhook endpoints
290
+ // List all registered webhook endpoints
249
291
  const { items } = await client.webhooks.list();
250
292
 
251
- // Update a webhook
293
+ // Update the events a webhook listens to
252
294
  await client.webhooks.update('webhook-id', {
253
295
  events: ['subscriber.created', 'subscriber.deleted'],
254
296
  });
255
297
 
256
- // Test a webhook
298
+ // Test a webhook by sending a sample payload to your endpoint
257
299
  const result = await client.webhooks.test('webhook-id', 'subscriber.created');
258
300
  if (result.success) {
259
301
  console.log('Webhook is working!');
260
302
  }
261
303
 
262
- // Rotate signing secret
304
+ // Rotate the signing secret (invalidates the old one immediately)
263
305
  const rotated = await client.webhooks.rotateSecret('webhook-id');
264
306
  console.log('New secret:', rotated.signing_secret);
265
307
 
266
- // View delivery history
308
+ // View delivery history to debug failed deliveries
267
309
  const deliveries = await client.webhooks.listDeliveries('webhook-id');
268
310
 
269
- // Get delivery statistics
311
+ // Get aggregate delivery statistics
270
312
  const stats = await client.webhooks.getDeliveryStats('webhook-id');
271
313
  console.log(`Success rate: ${stats.success_rate}%`);
272
314
 
273
- // Retry a failed delivery
315
+ // Retry a specific failed delivery
274
316
  await client.webhooks.retryDelivery('webhook-id', 'delivery-id');
275
317
 
276
- // Delete a webhook
318
+ // Remove a webhook endpoint
277
319
  await client.webhooks.delete('webhook-id');
278
320
  ```
279
321
 
280
322
  ### Preference Center
281
323
 
324
+ The Preference Center allows subscribers to manage their own email preferences. Generate a secure token for a subscriber, then use it to access their preferences. This powers the self-service UI where subscribers can subscribe to new tags, unsubscribe, export their data, or delete their account (GDPR compliance).
325
+
282
326
  ```typescript
283
- // Generate a preference center token
327
+ // Generate a time-limited preference center token for a subscriber
284
328
  const tokenResponse = await client.subscribers.generatePreferenceToken('subscriber-id');
285
329
 
286
- // Access the preference center with the token
330
+ // Create a preference center client using the token
287
331
  const prefCenter = client.preferenceCenter(tokenResponse.token);
288
332
 
289
- // Get subscriber preferences and available tags
333
+ // Retrieve the subscriber's current preferences and all available tags
290
334
  const info = await prefCenter.getInfo();
291
335
 
292
- // Subscribe/unsubscribe from tags
336
+ // Subscribe or unsubscribe from individual tags
293
337
  await prefCenter.subscribeTag('tag-id');
294
338
  await prefCenter.unsubscribeTag('tag-id');
295
339
 
296
- // Export all data (DSGVO)
340
+ // Export all subscriber data as JSON (GDPR Art. 20 — Right to Data Portability)
297
341
  const exportData = await prefCenter.exportData();
298
342
 
299
- // Delete account (DSGVO)
343
+ // Permanently delete the subscriber account (GDPR Art. 17 — Right to Erasure)
300
344
  await prefCenter.deleteAccount();
301
345
  ```
302
346
 
303
347
  ## Error Handling
304
348
 
349
+ All API errors are thrown as `SubscribeFlowError` instances with structured error details. You can use `instanceof` checks to handle specific error types.
350
+
305
351
  ```typescript
306
352
  import { SubscribeFlowClient, SubscribeFlowError } from '@subscribeflow/sdk';
307
353
 
@@ -310,18 +356,20 @@ try {
310
356
  } catch (error) {
311
357
  if (error instanceof SubscribeFlowError) {
312
358
  console.error('API Error:', error.message);
313
- console.error('Status:', error.status);
314
- console.error('Type:', error.type);
315
- console.error('Detail:', error.detail);
359
+ console.error('Status:', error.status); // HTTP status code (e.g. 404)
360
+ console.error('Type:', error.type); // Machine-readable error type
361
+ console.error('Detail:', error.detail); // Human-readable description
316
362
  }
317
363
  }
318
364
  ```
319
365
 
320
366
  ## Configuration
321
367
 
368
+ The client accepts configuration options when initialized. Only the `apiKey` is required.
369
+
322
370
  ```typescript
323
371
  const client = new SubscribeFlowClient({
324
- // Required: Your API key
372
+ // Required: Your API key (starts with sf_live_ or sf_test_)
325
373
  apiKey: 'sf_live_xxx',
326
374
 
327
375
  // Optional: API base URL (default: https://api.subscribeflow.net)
@@ -329,9 +377,9 @@ const client = new SubscribeFlowClient({
329
377
  });
330
378
  ```
331
379
 
332
- ### Lokale API-Instanz
380
+ ### Local API Instance
333
381
 
334
- Für Entwicklung gegen eine lokale SubscribeFlow-Instanz:
382
+ When developing against a local SubscribeFlow backend, point the client to your local server:
335
383
 
336
384
  ```typescript
337
385
  const client = new SubscribeFlowClient({
@@ -342,22 +390,22 @@ const client = new SubscribeFlowClient({
342
390
 
343
391
  ## TypeScript Support
344
392
 
345
- This SDK is written in TypeScript and provides full type definitions out of the box.
393
+ This SDK is written in TypeScript and provides full type definitions out of the box. You can import component schemas directly for use in your own type declarations.
346
394
 
347
395
  ```typescript
348
396
  import type { paths, components } from '@subscribeflow/sdk';
349
397
 
350
- // Use component schemas
398
+ // Use component schemas for your own types
351
399
  type Subscriber = components['schemas']['SubscriberResponse'];
352
400
  type Tag = components['schemas']['TagResponse'];
353
401
 
354
- // Type-safe API operations
402
+ // All API operations are fully type-safe
355
403
  const subscriber: Subscriber = await client.subscribers.get('id');
356
404
  ```
357
405
 
358
406
  ## Regenerating Types
359
407
 
360
- If the API changes, you can regenerate the TypeScript types:
408
+ If the API changes, you can regenerate the TypeScript types from the OpenAPI schema:
361
409
 
362
410
  ```bash
363
411
  # Make sure the backend is running
@@ -368,11 +416,19 @@ curl http://localhost:8000/openapi.json -o openapi.json
368
416
  bunx openapi-typescript openapi.json -o src/api-types.ts
369
417
  ```
370
418
 
419
+ ## MCP Server (Claude Integration)
420
+
421
+ The MCP server for Claude Desktop and Claude Code is available via the Python SDK. Install `subscribeflow[mcp]` to use natural-language commands with your SubscribeFlow account.
422
+
423
+ See the [MCP Integration Guide](https://docs.subscribeflow.net/sdk/mcp) for setup instructions.
424
+
371
425
  ## Links
372
426
 
373
- - [API Documentation](https://docs.subscribeflow.net/reference/api)
374
- - [Getting Started Guide](https://docs.subscribeflow.net/getting-started)
375
- - [Webhook Integration](https://docs.subscribeflow.net/guides/webhooks)
427
+ - [Dashboard](https://subscribeflow.net)
428
+ - [Documentation](https://docs.subscribeflow.net)
429
+ - [API Reference](https://docs.subscribeflow.net/api/reference)
430
+ - [MCP Integration](https://docs.subscribeflow.net/sdk/mcp)
431
+ - [Feedback](https://subscribeflow.net/feedback)
376
432
 
377
433
  ## License
378
434
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subscribeflow/sdk",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "TypeScript SDK for SubscribeFlow API - Email subscription management",
5
5
  "author": "SubscribeFlow Team",
6
6
  "license": "MIT",