@churndown/sdk 0.0.1

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.
@@ -0,0 +1,26 @@
1
+ interface ChurndownConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface IdentifyParams {
6
+ userId: string;
7
+ email: string;
8
+ name?: string;
9
+ image?: string;
10
+ properties?: Record<string, unknown>;
11
+ }
12
+ interface TrackParams {
13
+ userId: string;
14
+ event: string;
15
+ properties?: Record<string, unknown>;
16
+ }
17
+ declare class Churndown {
18
+ private apiKey;
19
+ private baseUrl;
20
+ constructor(apiKey: string, config?: Omit<ChurndownConfig, "apiKey">);
21
+ identify(params: IdentifyParams): Promise<void>;
22
+ track(userId: string, event: string, properties?: Record<string, unknown>): Promise<void>;
23
+ private post;
24
+ }
25
+
26
+ export { Churndown, type ChurndownConfig, type IdentifyParams, type TrackParams, Churndown as default };
@@ -0,0 +1,26 @@
1
+ interface ChurndownConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface IdentifyParams {
6
+ userId: string;
7
+ email: string;
8
+ name?: string;
9
+ image?: string;
10
+ properties?: Record<string, unknown>;
11
+ }
12
+ interface TrackParams {
13
+ userId: string;
14
+ event: string;
15
+ properties?: Record<string, unknown>;
16
+ }
17
+ declare class Churndown {
18
+ private apiKey;
19
+ private baseUrl;
20
+ constructor(apiKey: string, config?: Omit<ChurndownConfig, "apiKey">);
21
+ identify(params: IdentifyParams): Promise<void>;
22
+ track(userId: string, event: string, properties?: Record<string, unknown>): Promise<void>;
23
+ private post;
24
+ }
25
+
26
+ export { Churndown, type ChurndownConfig, type IdentifyParams, type TrackParams, Churndown as default };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Churndown: () => Churndown,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var DEFAULT_BASE_URL = "https://api.churndown.sh";
28
+ var Churndown = class {
29
+ apiKey;
30
+ baseUrl;
31
+ constructor(apiKey, config) {
32
+ if (!apiKey) throw new Error("Churndown: API key is required");
33
+ this.apiKey = apiKey;
34
+ this.baseUrl = config?.baseUrl ?? DEFAULT_BASE_URL;
35
+ }
36
+ async identify(params) {
37
+ await this.post("/v1/identify", params);
38
+ }
39
+ async track(userId, event, properties) {
40
+ await this.post("/v1/track", { userId, event, properties });
41
+ }
42
+ async post(path, body) {
43
+ const res = await fetch(`${this.baseUrl}${path}`, {
44
+ method: "POST",
45
+ headers: {
46
+ "Authorization": `Bearer ${this.apiKey}`,
47
+ "Content-Type": "application/json"
48
+ },
49
+ body: JSON.stringify(body)
50
+ });
51
+ if (!res.ok) {
52
+ const text = await res.text().catch(() => "Unknown error");
53
+ throw new Error(`Churndown API error (${res.status}): ${text}`);
54
+ }
55
+ return res.json().catch(() => null);
56
+ }
57
+ };
58
+ var index_default = Churndown;
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Churndown
62
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,37 @@
1
+ // src/index.ts
2
+ var DEFAULT_BASE_URL = "https://api.churndown.sh";
3
+ var Churndown = class {
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(apiKey, config) {
7
+ if (!apiKey) throw new Error("Churndown: API key is required");
8
+ this.apiKey = apiKey;
9
+ this.baseUrl = config?.baseUrl ?? DEFAULT_BASE_URL;
10
+ }
11
+ async identify(params) {
12
+ await this.post("/v1/identify", params);
13
+ }
14
+ async track(userId, event, properties) {
15
+ await this.post("/v1/track", { userId, event, properties });
16
+ }
17
+ async post(path, body) {
18
+ const res = await fetch(`${this.baseUrl}${path}`, {
19
+ method: "POST",
20
+ headers: {
21
+ "Authorization": `Bearer ${this.apiKey}`,
22
+ "Content-Type": "application/json"
23
+ },
24
+ body: JSON.stringify(body)
25
+ });
26
+ if (!res.ok) {
27
+ const text = await res.text().catch(() => "Unknown error");
28
+ throw new Error(`Churndown API error (${res.status}): ${text}`);
29
+ }
30
+ return res.json().catch(() => null);
31
+ }
32
+ };
33
+ var index_default = Churndown;
34
+ export {
35
+ Churndown,
36
+ index_default as default
37
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@churndown/sdk",
3
+ "version": "0.0.1",
4
+ "description": "Official Churndown SDK — identify users and track key actions",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsup src/index.ts --format cjs,esm --dts",
19
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "latest",
23
+ "typescript": "^5"
24
+ },
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/churndown/churndown"
29
+ },
30
+ "keywords": [
31
+ "churndown",
32
+ "churn",
33
+ "analytics",
34
+ "retention"
35
+ ]
36
+ }