@logopulse/sdk 1.0.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 ADDED
@@ -0,0 +1,182 @@
1
+ # @logopulse/sdk
2
+
3
+ **Generic TypeScript/JavaScript SDK for tracking customer analytics events for any B2B SaaS platform.**
4
+
5
+ Track the pulse of every customer - no matter what entities or events your SaaS tracks.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @logopulse/sdk
11
+ # or
12
+ yarn add @logopulse/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createLogoPulse } from '@logopulse/sdk';
19
+
20
+ // Initialize once (singleton)
21
+ const analytics = createLogoPulse({
22
+ apiUrl: 'https://api.logopulse.io/production',
23
+ apiKey: 'your-api-key-here',
24
+ orgId: 'your-company-id',
25
+ timeout: 5000, // Optional (default: 5000ms)
26
+ });
27
+
28
+ // Track any event type - LogoPulse auto-discovers entity types!
29
+ await analytics.track('batch.created', accountId, { batchId: 'batch-123' });
30
+ await analytics.track('order.processed', accountId, { orderId: 'order-456', total: 250.50 });
31
+ await analytics.track('payment.received', accountId, { amount: 250.50 });
32
+ await analytics.track('user.login', accountId, { email: 'user@company.com' });
33
+
34
+ // Track custom entity types - no setup required!
35
+ await analytics.track('tip.received', accountId, { tipId: 'tip-789', amount: 5.00 });
36
+ await analytics.track('payout.completed', accountId, { payoutId: 'payout-123' });
37
+ await analytics.track('export.generated', accountId, { format: 'csv', rows: 1500 });
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Initialization
43
+
44
+ ```typescript
45
+ import { createLogoPulse } from '@logopulse/sdk';
46
+
47
+ const analytics = createLogoPulse({
48
+ apiUrl: 'https://api.logopulse.io/production',
49
+ apiKey: 'your-api-key',
50
+ orgId: 'your-company', // Your SaaS company identifier
51
+ timeout: 5000, // Optional (default: 5000ms)
52
+ });
53
+ ```
54
+
55
+ ### Track Events
56
+
57
+ The SDK has **one method**: `track(eventType, accountId, data, options)`
58
+
59
+ ```typescript
60
+ /**
61
+ * Track an analytics event
62
+ * @param eventType - Event name in "entity.action" format (e.g., "batch.created")
63
+ * @param accountId - Your customer's account ID
64
+ * @param data - Custom event data (optional)
65
+ * @param options - Additional metadata (optional)
66
+ */
67
+ await analytics.track(
68
+ 'batch.created',
69
+ 'customer-account-123',
70
+ {
71
+ batchId: 'batch-abc-123',
72
+ productName: 'Widget',
73
+ quantity: 100,
74
+ expiryDate: '2025-12-31'
75
+ },
76
+ {
77
+ userId: 'user-456', // Optional: User who triggered event
78
+ traceId: 'trace-789', // Optional: Distributed tracing ID
79
+ source: 'inventory-service', // Optional: Service name
80
+ }
81
+ );
82
+ ```
83
+
84
+ ## Event Types
85
+
86
+ LogoPulse uses the `entity.action` format (e.g., `batch.created`, `order.processed`).
87
+
88
+ **Common entity types:**
89
+ - `batch`, `order`, `payment`, `user`, `document`, `warehouse`, `shipment`
90
+ - `tip`, `payout`, `export`, `import`, `report`, `integration`
91
+ - **Any custom entity you want to track!**
92
+
93
+ **Common actions:**
94
+ - `created`, `updated`, `deleted`, `processed`, `completed`
95
+ - `uploaded`, `generated`, `connected`, `disconnected`, `synced`
96
+
97
+ **Examples:**
98
+
99
+ ```typescript
100
+ // E-commerce
101
+ await analytics.track('order.created', accountId, { orderId, total });
102
+ await analytics.track('payment.received', accountId, { amount });
103
+ await analytics.track('shipment.delivered', accountId, { shipmentId });
104
+
105
+ // Inventory management
106
+ await analytics.track('batch.created', accountId, { batchId, quantity });
107
+ await analytics.track('stock.synced', accountId, { productCount, warehouseCount });
108
+
109
+ // Food delivery
110
+ await analytics.track('tip.received', accountId, { tipId, amount });
111
+ await analytics.track('payout.completed', accountId, { payoutId, driverId });
112
+ await analytics.track('delivery.completed', accountId, { deliveryId, duration });
113
+
114
+ // Document management
115
+ await analytics.track('document.uploaded', accountId, { documentId, fileSize });
116
+ await analytics.track('report.generated', accountId, { reportType, rows });
117
+
118
+ // User lifecycle
119
+ await analytics.track('user.signup', accountId, { email, name });
120
+ await analytics.track('user.login', accountId, { userId });
121
+ await analytics.track('subscription.activated', accountId, { plan, mrr });
122
+ await analytics.track('subscription.cancelled', accountId);
123
+
124
+ // Integrations
125
+ await analytics.track('integration.connected', accountId, { integrationName: 'Stripe' });
126
+ await analytics.track('integration.disconnected', accountId, { integrationName: 'Shopify' });
127
+ ```
128
+
129
+ ## Integration Example
130
+
131
+ ```typescript
132
+ // Initialize once in your service entry point
133
+ import { createLogoPulse } from '@logopulse/sdk';
134
+
135
+ createLogoPulse({
136
+ apiUrl: process.env.LOGOPULSE_API_URL,
137
+ apiKey: process.env.LOGOPULSE_API_KEY,
138
+ orgId: process.env.LOGOPULSE_ORG_ID,
139
+ });
140
+
141
+ // Use in your service methods
142
+ import { getLogoPulse } from '@logopulse/sdk';
143
+
144
+ export class BatchService {
145
+ async createBatch(accountId: string, data: CreateBatchRequest): Promise<Batch> {
146
+ const batch = await db.batches.create(data);
147
+
148
+ // Track analytics (non-blocking, errors logged but not thrown)
149
+ getLogoPulse()
150
+ .track('batch.created', accountId, {
151
+ batchId: batch.id,
152
+ productName: batch.productName,
153
+ quantity: batch.quantity
154
+ })
155
+ .catch(err => console.error('Analytics error:', err));
156
+
157
+ return batch;
158
+ }
159
+ }
160
+ ```
161
+
162
+ ## Error Handling
163
+
164
+ The SDK automatically catches and logs errors to prevent analytics from breaking your main application flow. Failed tracking calls are logged but do not throw exceptions.
165
+
166
+ ```typescript
167
+ // This will log errors but not throw
168
+ await analytics.trackBatchCreated(accountId, batchId);
169
+ // Your code continues even if tracking fails
170
+ ```
171
+
172
+ ## Environment Variables
173
+
174
+ Set `SERVICE_NAME` environment variable to automatically tag events with their source:
175
+
176
+ ```bash
177
+ export SERVICE_NAME=tracelot-inventory
178
+ ```
179
+
180
+ ## License
181
+
182
+ MIT
@@ -0,0 +1,38 @@
1
+ export interface LogoPulseConfig {
2
+ apiUrl: string;
3
+ apiKey: string;
4
+ orgId: string;
5
+ timeout?: number;
6
+ }
7
+ export interface AnalyticsEvent {
8
+ eventType: string;
9
+ eventVersion?: string;
10
+ timestamp?: string;
11
+ orgId: string;
12
+ accountId: string;
13
+ data?: Record<string, any>;
14
+ source?: string;
15
+ userId?: string;
16
+ traceId?: string;
17
+ }
18
+ /**
19
+ * LogoPulse SDK
20
+ * Track client analytics events
21
+ */
22
+ export declare class LogoPulse {
23
+ private client;
24
+ private config;
25
+ constructor(config: LogoPulseConfig);
26
+ /**
27
+ * Track an analytics event
28
+ */
29
+ track(eventType: string, accountId: string, data?: Record<string, any>, options?: {
30
+ timestamp?: string;
31
+ userId?: string;
32
+ traceId?: string;
33
+ source?: string;
34
+ }): Promise<void>;
35
+ }
36
+ export declare function createLogoPulse(config: LogoPulseConfig): LogoPulse;
37
+ export declare function getLogoPulse(): LogoPulse;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAkB;gBAEpB,MAAM,EAAE,eAAe;IAanC;;OAEG;IACG,KAAK,CACT,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GACA,OAAO,CAAC,IAAI,CAAC;CAqBjB;AAOD,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAGlE;AAED,wBAAgB,YAAY,IAAI,SAAS,CAKxC"}
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LogoPulse = void 0;
7
+ exports.createLogoPulse = createLogoPulse;
8
+ exports.getLogoPulse = getLogoPulse;
9
+ const axios_1 = __importDefault(require("axios"));
10
+ /**
11
+ * LogoPulse SDK
12
+ * Track client analytics events
13
+ */
14
+ class LogoPulse {
15
+ constructor(config) {
16
+ this.config = config;
17
+ this.client = axios_1.default.create({
18
+ baseURL: config.apiUrl,
19
+ timeout: config.timeout || 5000,
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ 'X-Api-Key': config.apiKey,
23
+ },
24
+ });
25
+ }
26
+ /**
27
+ * Track an analytics event
28
+ */
29
+ async track(eventType, accountId, data, options) {
30
+ try {
31
+ const event = {
32
+ eventType,
33
+ eventVersion: '1.0',
34
+ timestamp: options?.timestamp || new Date().toISOString(),
35
+ orgId: this.config.orgId,
36
+ accountId,
37
+ data: data || {},
38
+ source: options?.source || process.env.SERVICE_NAME || 'unknown',
39
+ userId: options?.userId,
40
+ traceId: options?.traceId,
41
+ };
42
+ await this.client.post('/v1/events', event);
43
+ }
44
+ catch (error) {
45
+ // Log error but don't throw - analytics shouldn't break main flow
46
+ console.error(`LogoPulse tracking error (${eventType}):`, error.message);
47
+ }
48
+ }
49
+ }
50
+ exports.LogoPulse = LogoPulse;
51
+ /**
52
+ * Create a singleton instance
53
+ */
54
+ let instance = null;
55
+ function createLogoPulse(config) {
56
+ instance = new LogoPulse(config);
57
+ return instance;
58
+ }
59
+ function getLogoPulse() {
60
+ if (!instance) {
61
+ throw new Error('LogoPulse not initialized. Call createLogoPulse() first.');
62
+ }
63
+ return instance;
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAmFA,0CAGC;AAED,oCAKC;AA7FD,kDAA6C;AAqB7C;;;GAGG;AACH,MAAa,SAAS;IAIpB,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,MAAM,CAAC,MAAM;YACtB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI;YAC/B,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,MAAM,CAAC,MAAM;aAC3B;SACF,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CACT,SAAiB,EACjB,SAAiB,EACjB,IAA0B,EAC1B,OAKC;QAED,IAAI,CAAC;YACH,MAAM,KAAK,GAAmB;gBAC5B,SAAS;gBACT,YAAY,EAAE,KAAK;gBACnB,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACzD,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;gBACxB,SAAS;gBACT,IAAI,EAAE,IAAI,IAAI,EAAE;gBAChB,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,SAAS;gBAChE,MAAM,EAAE,OAAO,EAAE,MAAM;gBACvB,OAAO,EAAE,OAAO,EAAE,OAAO;aAC1B,CAAC;YAEF,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,kEAAkE;YAClE,OAAO,CAAC,KAAK,CAAC,6BAA6B,SAAS,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CAEF;AAnDD,8BAmDC;AAED;;GAEG;AACH,IAAI,QAAQ,GAAqB,IAAI,CAAC;AAEtC,SAAgB,eAAe,CAAC,MAAuB;IACrD,QAAQ,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAgB,YAAY;IAC1B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@logopulse/sdk",
3
+ "version": "1.0.0",
4
+ "description": "Track the pulse of every customer - SDK for B2B SaaS customer health analytics",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "watch": "tsc -w",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tracelot/logopulse.git",
18
+ "directory": "sdk"
19
+ },
20
+ "keywords": [
21
+ "analytics",
22
+ "tracking",
23
+ "customer-health",
24
+ "b2b-saas",
25
+ "churn-prediction",
26
+ "logopulse"
27
+ ],
28
+ "author": "Tracelot",
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "axios": "^1.7.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.14.10",
35
+ "typescript": "^5.5.3"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md"
40
+ ]
41
+ }