@traffical/node 0.5.0 → 0.5.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.
package/README.md CHANGED
@@ -148,6 +148,59 @@ const context: Context = {
148
148
  const decision: DecisionResult = await client.decide(context);
149
149
  ```
150
150
 
151
+ ## Type-Safe Event Tracking
152
+
153
+ Use `@traffical/cli generate-types` to generate TypeScript interfaces for your event schemas. This lets you create a strictly typed `track` wrapper that catches invalid event names and properties at compile time.
154
+
155
+ ### 1. Generate types
156
+
157
+ ```bash
158
+ bunx @traffical/cli generate-types
159
+ ```
160
+
161
+ ### 2. Create a typed wrapper
162
+
163
+ ```typescript
164
+ import type { TrafficalEventProperties } from './traffical.generated';
165
+ import { TrafficalClient } from '@traffical/node';
166
+
167
+ type TypedTrack = <E extends Extract<keyof TrafficalEventProperties, string>>(
168
+ event: E,
169
+ options: {
170
+ decisionId: string;
171
+ unitKey: string;
172
+ properties?: TrafficalEventProperties[E];
173
+ }
174
+ ) => Promise<void>;
175
+
176
+ const client = new TrafficalClient({ apiKey: 'sk_...' });
177
+ export const track = client.track.bind(client) as unknown as TypedTrack;
178
+ ```
179
+
180
+ ### 3. Use it
181
+
182
+ ```typescript
183
+ await track('purchase', {
184
+ decisionId: decision.decisionId,
185
+ unitKey: 'user-123',
186
+ properties: {
187
+ order_total: 99.99,
188
+ payment_method: 'visa',
189
+ },
190
+ }); // ✅
191
+
192
+ await track('purchase', {
193
+ decisionId: decision.decisionId,
194
+ unitKey: 'user-123',
195
+ properties: {
196
+ order_total: 99.99,
197
+ unknown_field: true, // ❌ Type error
198
+ },
199
+ });
200
+ ```
201
+
202
+ ---
203
+
151
204
  ## License
152
205
 
153
206
  MIT
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "0.5.0";
1
+ export declare const SDK_VERSION = "0.5.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Auto-generated from package.json — do not edit manually.
2
- export const SDK_VERSION = "0.5.0";
2
+ export const SDK_VERSION = "0.5.1";
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@traffical/node",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Traffical SDK for Node.js - HTTP client with caching and event tracking",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,8 +23,8 @@
23
23
  "typecheck": "tsc --noEmit"
24
24
  },
25
25
  "dependencies": {
26
- "@traffical/core": "0.6.0",
27
- "@traffical/core-io": "0.5.0"
26
+ "@traffical/core": "0.7.0",
27
+ "@traffical/core-io": "0.5.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/bun": "latest",