@churndown/sdk 0.0.2 → 0.0.3

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 +127 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @churndown/sdk
2
+
3
+ Official SDK for [Churndown](https://churndown.sh) — predict which users are about to churn so you can intervene.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @churndown/sdk
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```typescript
14
+ import Churndown from "@churndown/sdk"
15
+
16
+ const churndown = new Churndown("cd_YOUR_API_KEY")
17
+
18
+ // Identify a user (call on sign up and every login)
19
+ await churndown.identify({
20
+ userId: "user_123",
21
+ email: "sam@example.com",
22
+ name: "Sam Shore",
23
+ })
24
+
25
+ // Track a key action
26
+ await churndown.track("user_123", "send-message")
27
+ ```
28
+
29
+ That's it — two calls and you're done.
30
+
31
+ ## API
32
+
33
+ ### `new Churndown(apiKey, config?)`
34
+
35
+ Create a new client instance.
36
+
37
+ | Parameter | Type | Required | Description |
38
+ |-----------|------|----------|-------------|
39
+ | `apiKey` | `string` | Yes | Your API key (starts with `cd_`) |
40
+ | `config.baseUrl` | `string` | No | Override the API URL. Defaults to `https://churndown.sh/api` |
41
+
42
+ ### `churndown.identify(params)`
43
+
44
+ Identify a user. Call this when a user signs up or logs in. Safe to call multiple times — it creates the user on the first call and updates on subsequent calls.
45
+
46
+ | Parameter | Type | Required | Description |
47
+ |-----------|------|----------|-------------|
48
+ | `userId` | `string` | Yes | Your internal user ID |
49
+ | `email` | `string` | Yes | User's email address |
50
+ | `name` | `string` | No | User's display name |
51
+ | `image` | `string` | No | URL to user's avatar |
52
+ | `properties` | `Record<string, unknown>` | No | Any additional user data |
53
+
54
+ ```typescript
55
+ await churndown.identify({
56
+ userId: "user_123",
57
+ email: "sam@example.com",
58
+ name: "Sam Shore",
59
+ image: "https://example.com/avatar.jpg",
60
+ properties: {
61
+ plan: "pro",
62
+ company: "Acme Inc",
63
+ },
64
+ })
65
+ ```
66
+
67
+ ### `churndown.track(userId, event, properties?)`
68
+
69
+ Track a key action. Call this each time a user performs the action that signals they're active.
70
+
71
+ | Parameter | Type | Required | Description |
72
+ |-----------|------|----------|-------------|
73
+ | `userId` | `string` | Yes | The user's ID (same as in `identify`) |
74
+ | `event` | `string` | Yes | Event name |
75
+ | `properties` | `Record<string, unknown>` | No | Any additional event data |
76
+
77
+ ```typescript
78
+ await churndown.track("user_123", "send-message", {
79
+ channel: "general",
80
+ messageLength: 142,
81
+ })
82
+ ```
83
+
84
+ ## Frameworks
85
+
86
+ Works everywhere — server-side, client-side, edge functions, serverless. The SDK is just a thin `fetch` wrapper with no dependencies.
87
+
88
+ ### Next.js (App Router)
89
+
90
+ ```typescript
91
+ // app/api/auth/callback/route.ts
92
+ import Churndown from "@churndown/sdk"
93
+
94
+ const churndown = new Churndown(process.env.CHURNDOWN_API_KEY!)
95
+
96
+ export async function GET(request: Request) {
97
+ const user = await getUser(request)
98
+
99
+ await churndown.identify({
100
+ userId: user.id,
101
+ email: user.email,
102
+ name: user.name,
103
+ })
104
+
105
+ // ...
106
+ }
107
+ ```
108
+
109
+ ### Express
110
+
111
+ ```typescript
112
+ import Churndown from "@churndown/sdk"
113
+
114
+ const churndown = new Churndown(process.env.CHURNDOWN_API_KEY!)
115
+
116
+ app.post("/api/messages", async (req, res) => {
117
+ // ... create message ...
118
+
119
+ await churndown.track(req.user.id, "send-message")
120
+
121
+ res.json({ ok: true })
122
+ })
123
+ ```
124
+
125
+ ## License
126
+
127
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churndown/sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Official Churndown SDK — identify users and track key actions",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "README.md"
16
17
  ],
17
18
  "scripts": {
18
19
  "build": "tsup src/index.ts --format cjs,esm --dts",