@drip-sdk/node 1.0.10 → 1.1.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 +154 -592
- package/dist/core.cjs +3 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +762 -0
- package/dist/core.d.ts +760 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/express.cjs +2 -2
- package/dist/express.cjs.map +1 -1
- package/dist/express.d.cts +3 -3
- package/dist/express.d.ts +3 -3
- package/dist/express.js +2 -2
- package/dist/express.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +746 -54
- package/dist/index.d.ts +746 -54
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/langchain.cjs +3 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +290 -0
- package/dist/langchain.d.ts +290 -0
- package/dist/langchain.js +3 -0
- package/dist/langchain.js.map +1 -0
- package/dist/middleware.cjs +2 -2
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.cts +3 -3
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.js +2 -2
- package/dist/middleware.js.map +1 -1
- package/dist/next.cjs +2 -2
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +3 -3
- package/dist/next.d.ts +3 -3
- package/dist/next.js +2 -2
- package/dist/next.js.map +1 -1
- package/dist/{types-D8mMON4v.d.ts → types-B2qwDadD.d.ts} +1 -1
- package/dist/{types-92iVqLtE.d.cts → types-Bo8SiUdl.d.cts} +1 -1
- package/package.json +23 -1
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drip SDK Core - Essential API for pilots and new integrations
|
|
3
|
+
*
|
|
4
|
+
* This SDK focuses on two core concepts:
|
|
5
|
+
* - **Usage tracking**: trackUsage() for recording usage without billing
|
|
6
|
+
* - **Execution logging**: recordRun() and related methods for tracking runs/events
|
|
7
|
+
*
|
|
8
|
+
* For billing, webhooks, cost estimation, and advanced features:
|
|
9
|
+
* `import { Drip } from '@drip-sdk/node'`
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for the Drip SDK client.
|
|
15
|
+
*
|
|
16
|
+
* All fields are optional - the SDK will read from environment variables:
|
|
17
|
+
* - `DRIP_API_KEY` - Your Drip API key
|
|
18
|
+
* - `DRIP_BASE_URL` - Override API base URL (optional)
|
|
19
|
+
*/
|
|
20
|
+
interface DripConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Your Drip API key. Obtain this from the Drip dashboard.
|
|
23
|
+
* Falls back to `DRIP_API_KEY` environment variable if not provided.
|
|
24
|
+
*
|
|
25
|
+
* Supports both key types:
|
|
26
|
+
* - **Secret keys** (`sk_live_...` / `sk_test_...`): Full access to all endpoints
|
|
27
|
+
* - **Public keys** (`pk_live_...` / `pk_test_...`): Safe for client-side use.
|
|
28
|
+
* Can access usage tracking, customers, runs, and events.
|
|
29
|
+
*
|
|
30
|
+
* @example "sk_live_abc123..." or "pk_live_abc123..."
|
|
31
|
+
*/
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Base URL for the Drip API. Defaults to production API.
|
|
35
|
+
* Falls back to `DRIP_BASE_URL` environment variable if not provided.
|
|
36
|
+
* @default "https://drip-app-hlunj.ondigitalocean.app/v1"
|
|
37
|
+
*/
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Request timeout in milliseconds.
|
|
41
|
+
* @default 30000
|
|
42
|
+
*/
|
|
43
|
+
timeout?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parameters for creating a new customer.
|
|
47
|
+
*/
|
|
48
|
+
interface CreateCustomerParams {
|
|
49
|
+
/**
|
|
50
|
+
* Your internal customer/user ID for reconciliation.
|
|
51
|
+
* @example "user_12345"
|
|
52
|
+
*/
|
|
53
|
+
externalCustomerId?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The customer's Drip Smart Account address (derived from their EOA).
|
|
56
|
+
* @example "0x1234567890abcdef..."
|
|
57
|
+
*/
|
|
58
|
+
onchainAddress: string;
|
|
59
|
+
/**
|
|
60
|
+
* Additional metadata to store with the customer.
|
|
61
|
+
*/
|
|
62
|
+
metadata?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A Drip customer record.
|
|
66
|
+
*/
|
|
67
|
+
interface Customer {
|
|
68
|
+
/** Unique customer ID in Drip */
|
|
69
|
+
id: string;
|
|
70
|
+
/** Your business ID (optional - may not be returned by all endpoints) */
|
|
71
|
+
businessId?: string;
|
|
72
|
+
/** Your external customer ID (if provided) */
|
|
73
|
+
externalCustomerId: string | null;
|
|
74
|
+
/** Customer's on-chain address */
|
|
75
|
+
onchainAddress: string;
|
|
76
|
+
/** Custom metadata */
|
|
77
|
+
metadata: Record<string, unknown> | null;
|
|
78
|
+
/** ISO timestamp of creation */
|
|
79
|
+
createdAt: string;
|
|
80
|
+
/** ISO timestamp of last update */
|
|
81
|
+
updatedAt: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for listing customers.
|
|
85
|
+
*/
|
|
86
|
+
interface ListCustomersOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Maximum number of customers to return (1-100).
|
|
89
|
+
* @default 100
|
|
90
|
+
*/
|
|
91
|
+
limit?: number;
|
|
92
|
+
/**
|
|
93
|
+
* Filter by customer status.
|
|
94
|
+
*/
|
|
95
|
+
status?: 'ACTIVE' | 'LOW_BALANCE' | 'PAUSED';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Response from listing customers.
|
|
99
|
+
*/
|
|
100
|
+
interface ListCustomersResponse {
|
|
101
|
+
/** Array of customers */
|
|
102
|
+
data: Customer[];
|
|
103
|
+
/** Total count returned */
|
|
104
|
+
count: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parameters for tracking usage without billing.
|
|
108
|
+
*/
|
|
109
|
+
interface TrackUsageParams {
|
|
110
|
+
/**
|
|
111
|
+
* The Drip customer ID to track usage for.
|
|
112
|
+
*/
|
|
113
|
+
customerId: string;
|
|
114
|
+
/**
|
|
115
|
+
* The meter/usage type (e.g., 'api_calls', 'tokens').
|
|
116
|
+
*/
|
|
117
|
+
meter: string;
|
|
118
|
+
/**
|
|
119
|
+
* The quantity of usage to record.
|
|
120
|
+
*/
|
|
121
|
+
quantity: number;
|
|
122
|
+
/**
|
|
123
|
+
* Unique key to prevent duplicate records.
|
|
124
|
+
* Auto-generated if not provided, ensuring every call is individually trackable.
|
|
125
|
+
*/
|
|
126
|
+
idempotencyKey?: string;
|
|
127
|
+
/**
|
|
128
|
+
* Human-readable unit label (e.g., 'tokens', 'requests').
|
|
129
|
+
*/
|
|
130
|
+
units?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Human-readable description of this usage event.
|
|
133
|
+
*/
|
|
134
|
+
description?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Additional metadata to attach to this usage event.
|
|
137
|
+
*/
|
|
138
|
+
metadata?: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Result of tracking usage (no billing).
|
|
142
|
+
*/
|
|
143
|
+
interface TrackUsageResult {
|
|
144
|
+
/** Whether the usage was recorded */
|
|
145
|
+
success: boolean;
|
|
146
|
+
/** The usage event ID */
|
|
147
|
+
usageEventId: string;
|
|
148
|
+
/** Customer ID */
|
|
149
|
+
customerId: string;
|
|
150
|
+
/** Usage type that was recorded */
|
|
151
|
+
usageType: string;
|
|
152
|
+
/** Quantity recorded */
|
|
153
|
+
quantity: number;
|
|
154
|
+
/** Whether this customer is internal-only */
|
|
155
|
+
isInternal: boolean;
|
|
156
|
+
/** Confirmation message */
|
|
157
|
+
message: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Parameters for starting a new run.
|
|
161
|
+
*/
|
|
162
|
+
interface StartRunParams {
|
|
163
|
+
/** Customer ID this run belongs to */
|
|
164
|
+
customerId: string;
|
|
165
|
+
/** Workflow ID this run executes */
|
|
166
|
+
workflowId: string;
|
|
167
|
+
/** Your external run ID for correlation */
|
|
168
|
+
externalRunId?: string;
|
|
169
|
+
/** Correlation ID for distributed tracing */
|
|
170
|
+
correlationId?: string;
|
|
171
|
+
/** Parent run ID for nested runs */
|
|
172
|
+
parentRunId?: string;
|
|
173
|
+
/** Additional metadata */
|
|
174
|
+
metadata?: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Possible run statuses.
|
|
178
|
+
*/
|
|
179
|
+
type RunStatus = 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'TIMEOUT';
|
|
180
|
+
/**
|
|
181
|
+
* Result of starting a run.
|
|
182
|
+
*/
|
|
183
|
+
interface RunResult {
|
|
184
|
+
id: string;
|
|
185
|
+
customerId: string;
|
|
186
|
+
workflowId: string;
|
|
187
|
+
workflowName: string;
|
|
188
|
+
status: RunStatus;
|
|
189
|
+
correlationId: string | null;
|
|
190
|
+
createdAt: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Parameters for ending/updating a run.
|
|
194
|
+
*/
|
|
195
|
+
interface EndRunParams {
|
|
196
|
+
/** New status for the run */
|
|
197
|
+
status: 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'TIMEOUT';
|
|
198
|
+
/** Error message if failed */
|
|
199
|
+
errorMessage?: string;
|
|
200
|
+
/** Error code for categorization */
|
|
201
|
+
errorCode?: string;
|
|
202
|
+
/** Additional metadata */
|
|
203
|
+
metadata?: Record<string, unknown>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Result of ending a run.
|
|
207
|
+
*/
|
|
208
|
+
interface EndRunResult {
|
|
209
|
+
id: string;
|
|
210
|
+
status: RunStatus;
|
|
211
|
+
endedAt: string | null;
|
|
212
|
+
durationMs: number | null;
|
|
213
|
+
eventCount: number;
|
|
214
|
+
totalCostUnits: string | null;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Parameters for emitting an event to a run.
|
|
218
|
+
*/
|
|
219
|
+
interface EmitEventParams {
|
|
220
|
+
/** Run ID to attach this event to */
|
|
221
|
+
runId: string;
|
|
222
|
+
/** Event type (e.g., "request.start", "llm.call") */
|
|
223
|
+
eventType: string;
|
|
224
|
+
/** Quantity of units consumed */
|
|
225
|
+
quantity?: number;
|
|
226
|
+
/** Human-readable unit label */
|
|
227
|
+
units?: string;
|
|
228
|
+
/** Human-readable description */
|
|
229
|
+
description?: string;
|
|
230
|
+
/** Cost in abstract units */
|
|
231
|
+
costUnits?: number;
|
|
232
|
+
/** Currency for cost */
|
|
233
|
+
costCurrency?: string;
|
|
234
|
+
/** Correlation ID for tracing */
|
|
235
|
+
correlationId?: string;
|
|
236
|
+
/** Parent event ID for trace tree */
|
|
237
|
+
parentEventId?: string;
|
|
238
|
+
/** OpenTelemetry-style span ID */
|
|
239
|
+
spanId?: string;
|
|
240
|
+
/** Idempotency key */
|
|
241
|
+
idempotencyKey?: string;
|
|
242
|
+
/** Additional metadata */
|
|
243
|
+
metadata?: Record<string, unknown>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Result of emitting an event.
|
|
247
|
+
*/
|
|
248
|
+
interface EventResult {
|
|
249
|
+
id: string;
|
|
250
|
+
runId: string;
|
|
251
|
+
eventType: string;
|
|
252
|
+
quantity: number;
|
|
253
|
+
costUnits: number | null;
|
|
254
|
+
isDuplicate: boolean;
|
|
255
|
+
timestamp: string;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* A single event to record in a run.
|
|
259
|
+
*/
|
|
260
|
+
interface RecordRunEvent {
|
|
261
|
+
/** Event type (e.g., "request.start", "llm.call", "request.end") */
|
|
262
|
+
eventType: string;
|
|
263
|
+
/** Quantity of units consumed */
|
|
264
|
+
quantity?: number;
|
|
265
|
+
/** Human-readable unit label */
|
|
266
|
+
units?: string;
|
|
267
|
+
/** Human-readable description */
|
|
268
|
+
description?: string;
|
|
269
|
+
/** Cost in abstract units */
|
|
270
|
+
costUnits?: number;
|
|
271
|
+
/** Additional metadata */
|
|
272
|
+
metadata?: Record<string, unknown>;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Parameters for recording a complete run in one call.
|
|
276
|
+
*/
|
|
277
|
+
interface RecordRunParams {
|
|
278
|
+
/** Customer ID this run belongs to */
|
|
279
|
+
customerId: string;
|
|
280
|
+
/**
|
|
281
|
+
* Workflow/request type identifier. Examples:
|
|
282
|
+
* - "rpc-request" for RPC providers
|
|
283
|
+
* - "api-request" for API providers
|
|
284
|
+
* - "agent-run" for AI agents
|
|
285
|
+
*
|
|
286
|
+
* Auto-creates if it doesn't exist.
|
|
287
|
+
*/
|
|
288
|
+
workflow: string;
|
|
289
|
+
/** Events that occurred during the run */
|
|
290
|
+
events: RecordRunEvent[];
|
|
291
|
+
/** Final status of the run */
|
|
292
|
+
status: 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'TIMEOUT';
|
|
293
|
+
/** Error message if status is FAILED */
|
|
294
|
+
errorMessage?: string;
|
|
295
|
+
/** Error code if status is FAILED */
|
|
296
|
+
errorCode?: string;
|
|
297
|
+
/** Your external run ID for correlation */
|
|
298
|
+
externalRunId?: string;
|
|
299
|
+
/** Correlation ID for distributed tracing */
|
|
300
|
+
correlationId?: string;
|
|
301
|
+
/** Additional metadata */
|
|
302
|
+
metadata?: Record<string, unknown>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Result of recording a run.
|
|
306
|
+
*/
|
|
307
|
+
interface RecordRunResult {
|
|
308
|
+
/** The created run */
|
|
309
|
+
run: {
|
|
310
|
+
id: string;
|
|
311
|
+
workflowId: string;
|
|
312
|
+
workflowName: string;
|
|
313
|
+
status: RunStatus;
|
|
314
|
+
durationMs: number | null;
|
|
315
|
+
};
|
|
316
|
+
/** Summary of events created */
|
|
317
|
+
events: {
|
|
318
|
+
created: number;
|
|
319
|
+
duplicates: number;
|
|
320
|
+
};
|
|
321
|
+
/** Total cost computed */
|
|
322
|
+
totalCostUnits: string | null;
|
|
323
|
+
/** Human-readable summary */
|
|
324
|
+
summary: string;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Full run timeline response from GET /runs/:id/timeline.
|
|
328
|
+
*/
|
|
329
|
+
interface RunTimeline {
|
|
330
|
+
runId: string;
|
|
331
|
+
workflowId: string | null;
|
|
332
|
+
customerId: string;
|
|
333
|
+
status: RunStatus;
|
|
334
|
+
startedAt: string | null;
|
|
335
|
+
endedAt: string | null;
|
|
336
|
+
durationMs: number | null;
|
|
337
|
+
events: Array<{
|
|
338
|
+
id: string;
|
|
339
|
+
eventType: string;
|
|
340
|
+
actionName: string | null;
|
|
341
|
+
outcome: 'SUCCESS' | 'FAILED' | 'PENDING' | 'TIMEOUT' | 'RETRYING';
|
|
342
|
+
explanation: string | null;
|
|
343
|
+
description: string | null;
|
|
344
|
+
timestamp: string;
|
|
345
|
+
durationMs: number | null;
|
|
346
|
+
parentEventId: string | null;
|
|
347
|
+
retryOfEventId: string | null;
|
|
348
|
+
attemptNumber: number;
|
|
349
|
+
retriedByEventId: string | null;
|
|
350
|
+
costUsdc: string | null;
|
|
351
|
+
isRetry: boolean;
|
|
352
|
+
retryChain: {
|
|
353
|
+
totalAttempts: number;
|
|
354
|
+
finalOutcome: string;
|
|
355
|
+
events: string[];
|
|
356
|
+
} | null;
|
|
357
|
+
metadata: {
|
|
358
|
+
usageType: string;
|
|
359
|
+
quantity: number;
|
|
360
|
+
units: string | null;
|
|
361
|
+
} | null;
|
|
362
|
+
}>;
|
|
363
|
+
anomalies: Array<{
|
|
364
|
+
id: string;
|
|
365
|
+
type: string;
|
|
366
|
+
severity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
367
|
+
title: string;
|
|
368
|
+
explanation: string;
|
|
369
|
+
relatedEventIds: string[];
|
|
370
|
+
detectedAt: string;
|
|
371
|
+
status: 'OPEN' | 'INVESTIGATING' | 'RESOLVED' | 'FALSE_POSITIVE' | 'IGNORED';
|
|
372
|
+
}>;
|
|
373
|
+
summary: {
|
|
374
|
+
totalEvents: number;
|
|
375
|
+
byType: Record<string, number>;
|
|
376
|
+
byOutcome: Record<string, number>;
|
|
377
|
+
retriedEvents: number;
|
|
378
|
+
failedEvents: number;
|
|
379
|
+
totalCostUsdc: string | null;
|
|
380
|
+
};
|
|
381
|
+
hasMore: boolean;
|
|
382
|
+
nextCursor: string | null;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Run details response from GET /runs/:id.
|
|
386
|
+
*/
|
|
387
|
+
interface RunDetails {
|
|
388
|
+
id: string;
|
|
389
|
+
customerId: string;
|
|
390
|
+
customerName: string | null;
|
|
391
|
+
workflowId: string;
|
|
392
|
+
workflowName: string;
|
|
393
|
+
status: RunStatus;
|
|
394
|
+
startedAt: string | null;
|
|
395
|
+
endedAt: string | null;
|
|
396
|
+
durationMs: number | null;
|
|
397
|
+
errorMessage: string | null;
|
|
398
|
+
errorCode: string | null;
|
|
399
|
+
correlationId: string | null;
|
|
400
|
+
metadata: Record<string, unknown> | null;
|
|
401
|
+
totals: {
|
|
402
|
+
eventCount: number;
|
|
403
|
+
totalQuantity: string;
|
|
404
|
+
totalCostUnits: string;
|
|
405
|
+
};
|
|
406
|
+
_links: {
|
|
407
|
+
timeline: string;
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Error thrown by Drip SDK operations.
|
|
412
|
+
*/
|
|
413
|
+
declare class DripError extends Error {
|
|
414
|
+
statusCode: number;
|
|
415
|
+
code?: string | undefined;
|
|
416
|
+
constructor(message: string, statusCode: number, code?: string | undefined);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Drip SDK Core - Essential API for pilots and new integrations.
|
|
420
|
+
*
|
|
421
|
+
* Two core concepts:
|
|
422
|
+
* - **Usage tracking**: `trackUsage()` - record usage without billing
|
|
423
|
+
* - **Execution logging**: `recordRun()` - track request/run lifecycle with events
|
|
424
|
+
*
|
|
425
|
+
* For billing (`charge()`), webhooks, and advanced features:
|
|
426
|
+
* ```typescript
|
|
427
|
+
* import { Drip } from '@drip-sdk/node';
|
|
428
|
+
* ```
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* import { Drip } from '@drip-sdk/node/core';
|
|
433
|
+
*
|
|
434
|
+
* const drip = new Drip({ apiKey: process.env.DRIP_API_KEY! });
|
|
435
|
+
*
|
|
436
|
+
* // Verify connection
|
|
437
|
+
* const health = await drip.ping();
|
|
438
|
+
* console.log(`API healthy: ${health.ok}`);
|
|
439
|
+
*
|
|
440
|
+
* // Track usage (no billing)
|
|
441
|
+
* await drip.trackUsage({
|
|
442
|
+
* customerId: 'cust_123',
|
|
443
|
+
* meter: 'api_calls',
|
|
444
|
+
* quantity: 1,
|
|
445
|
+
* });
|
|
446
|
+
*
|
|
447
|
+
* // Record a complete request/run with events
|
|
448
|
+
* const result = await drip.recordRun({
|
|
449
|
+
* customerId: 'cust_123',
|
|
450
|
+
* workflow: 'rpc-request', // or 'api-request', 'agent-run'
|
|
451
|
+
* events: [
|
|
452
|
+
* { eventType: 'request.start' },
|
|
453
|
+
* { eventType: 'llm.call', quantity: 1500, units: 'tokens' },
|
|
454
|
+
* { eventType: 'request.end' },
|
|
455
|
+
* ],
|
|
456
|
+
* status: 'COMPLETED',
|
|
457
|
+
* });
|
|
458
|
+
*
|
|
459
|
+
* console.log(result.summary);
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
declare class Drip {
|
|
463
|
+
private readonly apiKey;
|
|
464
|
+
private readonly baseUrl;
|
|
465
|
+
private readonly timeout;
|
|
466
|
+
/**
|
|
467
|
+
* The type of API key being used.
|
|
468
|
+
*
|
|
469
|
+
* - `'secret'` — Full access (sk_live_... / sk_test_...)
|
|
470
|
+
* - `'public'` — Client-safe, restricted access (pk_live_... / pk_test_...)
|
|
471
|
+
* - `'unknown'` — Key format not recognized (legacy or custom)
|
|
472
|
+
*/
|
|
473
|
+
readonly keyType: 'secret' | 'public' | 'unknown';
|
|
474
|
+
/**
|
|
475
|
+
* Creates a new Drip SDK client.
|
|
476
|
+
*
|
|
477
|
+
* @param config - Configuration options (all optional, reads from env vars)
|
|
478
|
+
* @throws {Error} If apiKey is not provided and DRIP_API_KEY env var is not set
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* // Option 1: Explicit config
|
|
483
|
+
* const drip = new Drip({ apiKey: 'your-api-key' });
|
|
484
|
+
*
|
|
485
|
+
* // Option 2: Auto-config from environment (recommended)
|
|
486
|
+
* // Set DRIP_API_KEY env var, then:
|
|
487
|
+
* const drip = new Drip();
|
|
488
|
+
*
|
|
489
|
+
* // Option 3: Use pre-initialized singleton
|
|
490
|
+
* import { drip } from '@drip-sdk/node';
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
constructor(config?: DripConfig);
|
|
494
|
+
/**
|
|
495
|
+
* Makes an authenticated request to the Drip API.
|
|
496
|
+
* @internal
|
|
497
|
+
*/
|
|
498
|
+
private request;
|
|
499
|
+
/**
|
|
500
|
+
* Pings the Drip API to check connectivity and measure latency.
|
|
501
|
+
*
|
|
502
|
+
* Use this to verify:
|
|
503
|
+
* - API key is valid
|
|
504
|
+
* - Base URL is correct
|
|
505
|
+
* - Network connectivity works
|
|
506
|
+
*
|
|
507
|
+
* @returns Health status with latency information
|
|
508
|
+
* @throws {DripError} If the request fails or times out
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const health = await drip.ping();
|
|
513
|
+
* if (health.ok) {
|
|
514
|
+
* console.log(`API healthy, latency: ${health.latencyMs}ms`);
|
|
515
|
+
* } else {
|
|
516
|
+
* console.error(`API unhealthy: ${health.status}`);
|
|
517
|
+
* }
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
ping(): Promise<{
|
|
521
|
+
ok: boolean;
|
|
522
|
+
status: string;
|
|
523
|
+
latencyMs: number;
|
|
524
|
+
timestamp: number;
|
|
525
|
+
}>;
|
|
526
|
+
/**
|
|
527
|
+
* Creates a new customer in your Drip account.
|
|
528
|
+
*
|
|
529
|
+
* @param params - Customer creation parameters
|
|
530
|
+
* @returns The created customer
|
|
531
|
+
* @throws {DripError} If creation fails (e.g., duplicate customer)
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const customer = await drip.createCustomer({
|
|
536
|
+
* onchainAddress: '0x1234567890abcdef...',
|
|
537
|
+
* externalCustomerId: 'user_123',
|
|
538
|
+
* });
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
createCustomer(params: CreateCustomerParams): Promise<Customer>;
|
|
542
|
+
/**
|
|
543
|
+
* Retrieves a customer by their Drip ID.
|
|
544
|
+
*
|
|
545
|
+
* @param customerId - The Drip customer ID
|
|
546
|
+
* @returns The customer details
|
|
547
|
+
* @throws {DripError} If customer not found (404)
|
|
548
|
+
*/
|
|
549
|
+
getCustomer(customerId: string): Promise<Customer>;
|
|
550
|
+
/**
|
|
551
|
+
* Lists all customers for your business.
|
|
552
|
+
*
|
|
553
|
+
* @param options - Optional filtering and pagination
|
|
554
|
+
* @returns List of customers
|
|
555
|
+
*/
|
|
556
|
+
listCustomers(options?: ListCustomersOptions): Promise<ListCustomersResponse>;
|
|
557
|
+
/**
|
|
558
|
+
* Records usage for tracking WITHOUT billing.
|
|
559
|
+
*
|
|
560
|
+
* Use this for:
|
|
561
|
+
* - Pilot programs (track before billing)
|
|
562
|
+
* - Internal team usage
|
|
563
|
+
* - Pre-billing tracking before customer setup
|
|
564
|
+
*
|
|
565
|
+
* For actual billing, use `charge()` from the full SDK.
|
|
566
|
+
*
|
|
567
|
+
* @param params - Usage tracking parameters
|
|
568
|
+
* @returns The tracked usage event
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const result = await drip.trackUsage({
|
|
573
|
+
* customerId: 'cust_abc123',
|
|
574
|
+
* meter: 'api_calls',
|
|
575
|
+
* quantity: 100,
|
|
576
|
+
* description: 'API calls during pilot',
|
|
577
|
+
* });
|
|
578
|
+
*
|
|
579
|
+
* console.log(`Tracked: ${result.usageEventId}`);
|
|
580
|
+
* ```
|
|
581
|
+
*/
|
|
582
|
+
trackUsage(params: TrackUsageParams): Promise<TrackUsageResult>;
|
|
583
|
+
private createWorkflow;
|
|
584
|
+
private listWorkflows;
|
|
585
|
+
/**
|
|
586
|
+
* Starts a new run for tracking execution.
|
|
587
|
+
*
|
|
588
|
+
* @param params - Run parameters
|
|
589
|
+
* @returns The started run
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```typescript
|
|
593
|
+
* const run = await drip.startRun({
|
|
594
|
+
* customerId: 'cust_abc123',
|
|
595
|
+
* workflowId: 'wf_xyz789',
|
|
596
|
+
* });
|
|
597
|
+
*
|
|
598
|
+
* // Emit events during execution...
|
|
599
|
+
* await drip.emitEvent({ runId: run.id, eventType: 'llm.call', quantity: 1000 });
|
|
600
|
+
*
|
|
601
|
+
* // End the run
|
|
602
|
+
* await drip.endRun(run.id, { status: 'COMPLETED' });
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
startRun(params: StartRunParams): Promise<RunResult>;
|
|
606
|
+
/**
|
|
607
|
+
* Ends a run with a final status.
|
|
608
|
+
*
|
|
609
|
+
* @param runId - The run ID to end
|
|
610
|
+
* @param params - End parameters including status
|
|
611
|
+
* @returns Updated run info
|
|
612
|
+
*/
|
|
613
|
+
endRun(runId: string, params: EndRunParams): Promise<EndRunResult>;
|
|
614
|
+
/**
|
|
615
|
+
* Gets run details with summary totals.
|
|
616
|
+
*
|
|
617
|
+
* For full event history with retry chains and anomalies, use `getRunTimeline()`.
|
|
618
|
+
*
|
|
619
|
+
* @param runId - The run ID
|
|
620
|
+
* @returns Run details with totals
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```typescript
|
|
624
|
+
* const run = await drip.getRun('run_abc123');
|
|
625
|
+
* console.log(`Status: ${run.status}, Events: ${run.totals.eventCount}`);
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
getRun(runId: string): Promise<RunDetails>;
|
|
629
|
+
/**
|
|
630
|
+
* Gets a run's full timeline with events, anomalies, and analytics.
|
|
631
|
+
*
|
|
632
|
+
* @param runId - The run ID
|
|
633
|
+
* @param options - Pagination and filtering options
|
|
634
|
+
* @returns Full timeline with events, anomalies, and summary
|
|
635
|
+
*
|
|
636
|
+
* @example
|
|
637
|
+
* ```typescript
|
|
638
|
+
* const timeline = await drip.getRunTimeline('run_abc123');
|
|
639
|
+
*
|
|
640
|
+
* console.log(`Status: ${timeline.status}`);
|
|
641
|
+
* console.log(`Events: ${timeline.summary.totalEvents}`);
|
|
642
|
+
*
|
|
643
|
+
* for (const event of timeline.events) {
|
|
644
|
+
* console.log(`${event.eventType}: ${event.outcome}`);
|
|
645
|
+
* }
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
648
|
+
getRunTimeline(runId: string, options?: {
|
|
649
|
+
limit?: number;
|
|
650
|
+
cursor?: string;
|
|
651
|
+
includeAnomalies?: boolean;
|
|
652
|
+
collapseRetries?: boolean;
|
|
653
|
+
}): Promise<RunTimeline>;
|
|
654
|
+
/**
|
|
655
|
+
* Emits an event to a run.
|
|
656
|
+
*
|
|
657
|
+
* @param params - Event parameters
|
|
658
|
+
* @returns The created event
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```typescript
|
|
662
|
+
* await drip.emitEvent({
|
|
663
|
+
* runId: run.id,
|
|
664
|
+
* eventType: 'llm.call',
|
|
665
|
+
* quantity: 1500,
|
|
666
|
+
* units: 'tokens',
|
|
667
|
+
* description: 'GPT-4 completion',
|
|
668
|
+
* });
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
emitEvent(params: EmitEventParams): Promise<EventResult>;
|
|
672
|
+
/**
|
|
673
|
+
* Emits multiple events in a single request.
|
|
674
|
+
*
|
|
675
|
+
* @param events - Array of events to emit
|
|
676
|
+
* @returns Summary of created events
|
|
677
|
+
*/
|
|
678
|
+
emitEventsBatch(events: Array<EmitEventParams>): Promise<{
|
|
679
|
+
success: boolean;
|
|
680
|
+
created: number;
|
|
681
|
+
duplicates: number;
|
|
682
|
+
skipped: number;
|
|
683
|
+
events: Array<{
|
|
684
|
+
id: string;
|
|
685
|
+
eventType: string;
|
|
686
|
+
isDuplicate: boolean;
|
|
687
|
+
skipped?: boolean;
|
|
688
|
+
reason?: string;
|
|
689
|
+
}>;
|
|
690
|
+
}>;
|
|
691
|
+
/**
|
|
692
|
+
* Records a complete request/run in a single call.
|
|
693
|
+
*
|
|
694
|
+
* This is the **hero method** for tracking execution. It combines:
|
|
695
|
+
* - Workflow creation (auto-creates if needed)
|
|
696
|
+
* - Run creation
|
|
697
|
+
* - Event emission
|
|
698
|
+
* - Run completion
|
|
699
|
+
*
|
|
700
|
+
* @param params - Run parameters including events
|
|
701
|
+
* @returns The created run with event summary
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* // RPC provider example
|
|
706
|
+
* const result = await drip.recordRun({
|
|
707
|
+
* customerId: 'cust_123',
|
|
708
|
+
* workflow: 'rpc-request',
|
|
709
|
+
* events: [
|
|
710
|
+
* { eventType: 'request.start' },
|
|
711
|
+
* { eventType: 'eth_call', quantity: 1 },
|
|
712
|
+
* { eventType: 'request.end' },
|
|
713
|
+
* ],
|
|
714
|
+
* status: 'COMPLETED',
|
|
715
|
+
* });
|
|
716
|
+
*
|
|
717
|
+
* // API provider example
|
|
718
|
+
* const result = await drip.recordRun({
|
|
719
|
+
* customerId: 'cust_123',
|
|
720
|
+
* workflow: 'api-request',
|
|
721
|
+
* events: [
|
|
722
|
+
* { eventType: 'request.start' },
|
|
723
|
+
* { eventType: 'llm.call', quantity: 2000, units: 'tokens' },
|
|
724
|
+
* { eventType: 'request.end' },
|
|
725
|
+
* ],
|
|
726
|
+
* status: 'COMPLETED',
|
|
727
|
+
* });
|
|
728
|
+
*
|
|
729
|
+
* console.log(result.summary);
|
|
730
|
+
* // Output: "✓ Rpc Request: 3 events recorded (152ms)"
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
recordRun(params: RecordRunParams): Promise<RecordRunResult>;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Pre-initialized Drip client singleton.
|
|
738
|
+
*
|
|
739
|
+
* Uses lazy initialization - only creates the client when first accessed.
|
|
740
|
+
* Reads `DRIP_API_KEY` from environment variables.
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```typescript
|
|
744
|
+
* import { drip } from '@drip-sdk/node';
|
|
745
|
+
*
|
|
746
|
+
* // Track usage with one line
|
|
747
|
+
* await drip.trackUsage({ customerId: 'cust_123', meter: 'api_calls', quantity: 1 });
|
|
748
|
+
*
|
|
749
|
+
* // Record a run
|
|
750
|
+
* await drip.recordRun({
|
|
751
|
+
* customerId: 'cust_123',
|
|
752
|
+
* workflow: 'agent-run',
|
|
753
|
+
* events: [{ eventType: 'llm.call', quantity: 1000, units: 'tokens' }],
|
|
754
|
+
* status: 'COMPLETED',
|
|
755
|
+
* });
|
|
756
|
+
* ```
|
|
757
|
+
*/
|
|
758
|
+
declare const drip: Drip;
|
|
759
|
+
|
|
760
|
+
// @ts-ignore
|
|
761
|
+
export = Drip;
|
|
762
|
+
export { type CreateCustomerParams, type Customer, Drip, type DripConfig, DripError, type EmitEventParams, type EndRunParams, type EndRunResult, type EventResult, type ListCustomersOptions, type ListCustomersResponse, type RecordRunEvent, type RecordRunParams, type RecordRunResult, type RunDetails, type RunResult, type RunStatus, type RunTimeline, type StartRunParams, type TrackUsageParams, type TrackUsageResult, drip };
|