@drip-sdk/node 1.1.0 → 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 +159 -293
- package/dist/core.cjs +2 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +165 -43
- package/dist/core.d.ts +165 -43
- package/dist/core.js +2 -2
- package/dist/core.js.map +1 -1
- package/dist/express.cjs +2 -2
- package/dist/express.cjs.map +1 -1
- 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 +171 -54
- package/dist/index.d.ts +171 -54
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/langchain.cjs +2 -2
- package/dist/langchain.cjs.map +1 -1
- package/dist/langchain.d.cts +2 -2
- package/dist/langchain.d.ts +2 -2
- package/dist/langchain.js +2 -2
- package/dist/langchain.js.map +1 -1
- package/dist/middleware.cjs +2 -2
- package/dist/middleware.cjs.map +1 -1
- 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.js +2 -2
- package/dist/next.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -498,17 +498,29 @@ interface RetryOptions {
|
|
|
498
498
|
}
|
|
499
499
|
/**
|
|
500
500
|
* Configuration options for the Drip SDK client.
|
|
501
|
+
*
|
|
502
|
+
* All fields are optional - the SDK will read from environment variables:
|
|
503
|
+
* - `DRIP_API_KEY` - Your Drip API key
|
|
504
|
+
* - `DRIP_BASE_URL` - Override API base URL (optional)
|
|
501
505
|
*/
|
|
502
506
|
interface DripConfig {
|
|
503
507
|
/**
|
|
504
508
|
* Your Drip API key. Obtain this from the Drip dashboard.
|
|
505
|
-
*
|
|
509
|
+
* Falls back to `DRIP_API_KEY` environment variable if not provided.
|
|
510
|
+
*
|
|
511
|
+
* Supports both key types:
|
|
512
|
+
* - **Secret keys** (`sk_live_...` / `sk_test_...`): Full access to all endpoints
|
|
513
|
+
* - **Public keys** (`pk_live_...` / `pk_test_...`): Safe for client-side use.
|
|
514
|
+
* Can access usage, customers, charges, sessions, analytics, etc.
|
|
515
|
+
* Cannot access webhook management, API key management, or feature flags.
|
|
516
|
+
*
|
|
517
|
+
* @example "sk_live_abc123..." or "pk_live_abc123..."
|
|
506
518
|
*/
|
|
507
|
-
apiKey
|
|
519
|
+
apiKey?: string;
|
|
508
520
|
/**
|
|
509
521
|
* Base URL for the Drip API. Defaults to production API.
|
|
510
|
-
*
|
|
511
|
-
* @default "https://
|
|
522
|
+
* Falls back to `DRIP_BASE_URL` environment variable if not provided.
|
|
523
|
+
* @default "https://drip-app-hlunj.ondigitalocean.app/v1"
|
|
512
524
|
*/
|
|
513
525
|
baseUrl?: string;
|
|
514
526
|
/**
|
|
@@ -645,8 +657,8 @@ interface ChargeParams {
|
|
|
645
657
|
*/
|
|
646
658
|
quantity: number;
|
|
647
659
|
/**
|
|
648
|
-
* Unique key to prevent duplicate charges.
|
|
649
|
-
*
|
|
660
|
+
* Unique key to prevent duplicate charges and map each call to a single event.
|
|
661
|
+
* Auto-generated if not provided. Retrying with the same key returns the original charge.
|
|
650
662
|
* @example "req_abc123"
|
|
651
663
|
*/
|
|
652
664
|
idempotencyKey?: string;
|
|
@@ -944,7 +956,7 @@ interface CreateWorkflowParams {
|
|
|
944
956
|
/** URL-safe identifier (lowercase alphanumeric with underscores/hyphens) */
|
|
945
957
|
slug: string;
|
|
946
958
|
/** Type of workflow */
|
|
947
|
-
productSurface?: 'RPC' | 'WEBHOOK' | 'AGENT' | 'PIPELINE' | 'CUSTOM';
|
|
959
|
+
productSurface?: 'API' | 'RPC' | 'WEBHOOK' | 'AGENT' | 'PIPELINE' | 'CUSTOM';
|
|
948
960
|
/** Optional description */
|
|
949
961
|
description?: string;
|
|
950
962
|
/** Additional metadata */
|
|
@@ -1231,47 +1243,88 @@ interface RecordRunResult {
|
|
|
1231
1243
|
summary: string;
|
|
1232
1244
|
}
|
|
1233
1245
|
/**
|
|
1234
|
-
* Full run timeline response.
|
|
1246
|
+
* Full run timeline response from GET /runs/:id/timeline.
|
|
1235
1247
|
*/
|
|
1236
1248
|
interface RunTimeline {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
endedAt: string | null;
|
|
1246
|
-
durationMs: number | null;
|
|
1247
|
-
errorMessage: string | null;
|
|
1248
|
-
errorCode: string | null;
|
|
1249
|
-
correlationId: string | null;
|
|
1250
|
-
metadata: Record<string, unknown> | null;
|
|
1251
|
-
};
|
|
1252
|
-
timeline: Array<{
|
|
1249
|
+
runId: string;
|
|
1250
|
+
workflowId: string | null;
|
|
1251
|
+
customerId: string;
|
|
1252
|
+
status: RunStatus;
|
|
1253
|
+
startedAt: string | null;
|
|
1254
|
+
endedAt: string | null;
|
|
1255
|
+
durationMs: number | null;
|
|
1256
|
+
events: Array<{
|
|
1253
1257
|
id: string;
|
|
1254
1258
|
eventType: string;
|
|
1255
|
-
|
|
1256
|
-
|
|
1259
|
+
actionName: string | null;
|
|
1260
|
+
outcome: 'SUCCESS' | 'FAILED' | 'PENDING' | 'TIMEOUT' | 'RETRYING';
|
|
1261
|
+
explanation: string | null;
|
|
1257
1262
|
description: string | null;
|
|
1258
|
-
costUnits: number | null;
|
|
1259
1263
|
timestamp: string;
|
|
1260
|
-
|
|
1264
|
+
durationMs: number | null;
|
|
1261
1265
|
parentEventId: string | null;
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
+
retryOfEventId: string | null;
|
|
1267
|
+
attemptNumber: number;
|
|
1268
|
+
retriedByEventId: string | null;
|
|
1269
|
+
costUsdc: string | null;
|
|
1270
|
+
isRetry: boolean;
|
|
1271
|
+
retryChain: {
|
|
1272
|
+
totalAttempts: number;
|
|
1273
|
+
finalOutcome: string;
|
|
1274
|
+
events: string[];
|
|
1275
|
+
} | null;
|
|
1276
|
+
metadata: {
|
|
1277
|
+
usageType: string;
|
|
1278
|
+
quantity: number;
|
|
1279
|
+
units: string | null;
|
|
1266
1280
|
} | null;
|
|
1267
1281
|
}>;
|
|
1282
|
+
anomalies: Array<{
|
|
1283
|
+
id: string;
|
|
1284
|
+
type: string;
|
|
1285
|
+
severity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
1286
|
+
title: string;
|
|
1287
|
+
explanation: string;
|
|
1288
|
+
relatedEventIds: string[];
|
|
1289
|
+
detectedAt: string;
|
|
1290
|
+
status: 'OPEN' | 'INVESTIGATING' | 'RESOLVED' | 'FALSE_POSITIVE' | 'IGNORED';
|
|
1291
|
+
}>;
|
|
1292
|
+
summary: {
|
|
1293
|
+
totalEvents: number;
|
|
1294
|
+
byType: Record<string, number>;
|
|
1295
|
+
byOutcome: Record<string, number>;
|
|
1296
|
+
retriedEvents: number;
|
|
1297
|
+
failedEvents: number;
|
|
1298
|
+
totalCostUsdc: string | null;
|
|
1299
|
+
};
|
|
1300
|
+
hasMore: boolean;
|
|
1301
|
+
nextCursor: string | null;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Run details response from GET /runs/:id.
|
|
1305
|
+
*/
|
|
1306
|
+
interface RunDetails {
|
|
1307
|
+
id: string;
|
|
1308
|
+
customerId: string;
|
|
1309
|
+
customerName: string | null;
|
|
1310
|
+
workflowId: string;
|
|
1311
|
+
workflowName: string;
|
|
1312
|
+
status: RunStatus;
|
|
1313
|
+
startedAt: string | null;
|
|
1314
|
+
endedAt: string | null;
|
|
1315
|
+
durationMs: number | null;
|
|
1316
|
+
errorMessage: string | null;
|
|
1317
|
+
errorCode: string | null;
|
|
1318
|
+
correlationId: string | null;
|
|
1319
|
+
metadata: Record<string, unknown> | null;
|
|
1268
1320
|
totals: {
|
|
1269
1321
|
eventCount: number;
|
|
1270
1322
|
totalQuantity: string;
|
|
1271
1323
|
totalCostUnits: string;
|
|
1272
|
-
totalChargedUsdc: string;
|
|
1273
1324
|
};
|
|
1274
|
-
|
|
1325
|
+
_links: {
|
|
1326
|
+
timeline: string;
|
|
1327
|
+
};
|
|
1275
1328
|
}
|
|
1276
1329
|
/**
|
|
1277
1330
|
* Parameters for wrapping an external API call with usage tracking.
|
|
@@ -1376,6 +1429,14 @@ declare class Drip {
|
|
|
1376
1429
|
private readonly baseUrl;
|
|
1377
1430
|
private readonly timeout;
|
|
1378
1431
|
private readonly resilience;
|
|
1432
|
+
/**
|
|
1433
|
+
* The type of API key being used.
|
|
1434
|
+
*
|
|
1435
|
+
* - `'secret'` — Full access (sk_live_... / sk_test_...)
|
|
1436
|
+
* - `'public'` — Client-safe, restricted access (pk_live_... / pk_test_...)
|
|
1437
|
+
* - `'unknown'` — Key format not recognized (legacy or custom)
|
|
1438
|
+
*/
|
|
1439
|
+
readonly keyType: 'secret' | 'public' | 'unknown';
|
|
1379
1440
|
/**
|
|
1380
1441
|
* Creates a new Drip SDK client.
|
|
1381
1442
|
*
|
|
@@ -1386,23 +1447,29 @@ declare class Drip {
|
|
|
1386
1447
|
* ```typescript
|
|
1387
1448
|
* // Basic usage
|
|
1388
1449
|
* const drip = new Drip({
|
|
1389
|
-
* apiKey: '
|
|
1450
|
+
* apiKey: 'sk_live_...',
|
|
1390
1451
|
* });
|
|
1391
1452
|
*
|
|
1392
1453
|
* // With production resilience (recommended)
|
|
1393
1454
|
* const drip = new Drip({
|
|
1394
|
-
* apiKey: '
|
|
1455
|
+
* apiKey: 'sk_live_...',
|
|
1395
1456
|
* resilience: true,
|
|
1396
1457
|
* });
|
|
1397
1458
|
*
|
|
1398
1459
|
* // High throughput mode
|
|
1399
1460
|
* const drip = new Drip({
|
|
1400
|
-
* apiKey: '
|
|
1461
|
+
* apiKey: 'sk_live_...',
|
|
1401
1462
|
* resilience: 'high-throughput',
|
|
1402
1463
|
* });
|
|
1403
1464
|
* ```
|
|
1404
1465
|
*/
|
|
1405
|
-
constructor(config
|
|
1466
|
+
constructor(config?: DripConfig);
|
|
1467
|
+
/**
|
|
1468
|
+
* Asserts that the SDK was initialized with a secret key (sk_).
|
|
1469
|
+
* Throws a clear error if a public key is being used for a secret-key-only operation.
|
|
1470
|
+
* @internal
|
|
1471
|
+
*/
|
|
1472
|
+
private assertSecretKey;
|
|
1406
1473
|
/**
|
|
1407
1474
|
* Makes an authenticated request to the Drip API.
|
|
1408
1475
|
* @internal
|
|
@@ -1874,8 +1941,8 @@ declare class Drip {
|
|
|
1874
1941
|
* @example
|
|
1875
1942
|
* ```typescript
|
|
1876
1943
|
* const workflow = await drip.createWorkflow({
|
|
1877
|
-
* name: '
|
|
1878
|
-
* slug: '
|
|
1944
|
+
* name: 'Document Processing',
|
|
1945
|
+
* slug: 'doc_processing',
|
|
1879
1946
|
* productSurface: 'AGENT',
|
|
1880
1947
|
* });
|
|
1881
1948
|
* ```
|
|
@@ -1940,33 +2007,53 @@ declare class Drip {
|
|
|
1940
2007
|
totalCostUnits: string | null;
|
|
1941
2008
|
}>;
|
|
1942
2009
|
/**
|
|
1943
|
-
* Gets
|
|
2010
|
+
* Gets run details with summary totals.
|
|
2011
|
+
*
|
|
2012
|
+
* For full event history with retry chains and anomalies, use `getRunTimeline()`.
|
|
2013
|
+
*
|
|
2014
|
+
* @param runId - The run ID
|
|
2015
|
+
* @returns Run details with totals
|
|
2016
|
+
*
|
|
2017
|
+
* @example
|
|
2018
|
+
* ```typescript
|
|
2019
|
+
* const run = await drip.getRun('run_abc123');
|
|
2020
|
+
* console.log(`Status: ${run.status}, Events: ${run.totals.eventCount}`);
|
|
2021
|
+
* ```
|
|
2022
|
+
*/
|
|
2023
|
+
getRun(runId: string): Promise<RunDetails>;
|
|
2024
|
+
/**
|
|
2025
|
+
* Gets a run's full timeline with events, anomalies, and analytics.
|
|
1944
2026
|
*
|
|
1945
2027
|
* This is the key endpoint for debugging "what happened" in an execution.
|
|
1946
2028
|
*
|
|
1947
2029
|
* @param runId - The run ID
|
|
1948
|
-
* @
|
|
2030
|
+
* @param options - Pagination and filtering options
|
|
2031
|
+
* @returns Full timeline with events, anomalies, and summary
|
|
1949
2032
|
*
|
|
1950
2033
|
* @example
|
|
1951
2034
|
* ```typescript
|
|
1952
|
-
* const
|
|
2035
|
+
* const timeline = await drip.getRunTimeline('run_abc123');
|
|
1953
2036
|
*
|
|
1954
|
-
* console.log(`Status: ${
|
|
1955
|
-
* console.log(`
|
|
1956
|
-
* console.log(`Total cost: ${totals.totalCostUnits}`);
|
|
2037
|
+
* console.log(`Status: ${timeline.status}`);
|
|
2038
|
+
* console.log(`Events: ${timeline.summary.totalEvents}`);
|
|
1957
2039
|
*
|
|
1958
|
-
* for (const event of timeline) {
|
|
1959
|
-
* console.log(`${event.eventType}: ${event.
|
|
2040
|
+
* for (const event of timeline.events) {
|
|
2041
|
+
* console.log(`${event.eventType}: ${event.outcome}`);
|
|
1960
2042
|
* }
|
|
1961
2043
|
* ```
|
|
1962
2044
|
*/
|
|
1963
|
-
getRunTimeline(runId: string
|
|
2045
|
+
getRunTimeline(runId: string, options?: {
|
|
2046
|
+
limit?: number;
|
|
2047
|
+
cursor?: string;
|
|
2048
|
+
includeAnomalies?: boolean;
|
|
2049
|
+
collapseRetries?: boolean;
|
|
2050
|
+
}): Promise<RunTimeline>;
|
|
1964
2051
|
/**
|
|
1965
2052
|
* Emits an event to a run.
|
|
1966
2053
|
*
|
|
1967
|
-
*
|
|
2054
|
+
* Each event is assigned a unique idempotency key (auto-generated if not provided).
|
|
2055
|
+
* This maps each inference or API call to a single trackable event.
|
|
1968
2056
|
* Use `Drip.generateIdempotencyKey()` for deterministic key generation.
|
|
1969
|
-
* If `idempotencyKey` is omitted, repeated calls may create duplicate events.
|
|
1970
2057
|
*
|
|
1971
2058
|
* @param params - Event parameters
|
|
1972
2059
|
* @returns The created event
|
|
@@ -2007,10 +2094,13 @@ declare class Drip {
|
|
|
2007
2094
|
success: boolean;
|
|
2008
2095
|
created: number;
|
|
2009
2096
|
duplicates: number;
|
|
2097
|
+
skipped: number;
|
|
2010
2098
|
events: Array<{
|
|
2011
2099
|
id: string;
|
|
2012
2100
|
eventType: string;
|
|
2013
2101
|
isDuplicate: boolean;
|
|
2102
|
+
skipped?: boolean;
|
|
2103
|
+
reason?: string;
|
|
2014
2104
|
}>;
|
|
2015
2105
|
}>;
|
|
2016
2106
|
/**
|
|
@@ -2135,7 +2225,7 @@ declare class Drip {
|
|
|
2135
2225
|
* // Record a complete agent run in one call
|
|
2136
2226
|
* const result = await drip.recordRun({
|
|
2137
2227
|
* customerId: 'cust_123',
|
|
2138
|
-
* workflow: '
|
|
2228
|
+
* workflow: 'doc_processing', // Auto-creates if doesn't exist
|
|
2139
2229
|
* events: [
|
|
2140
2230
|
* { eventType: 'agent.start', description: 'Started processing' },
|
|
2141
2231
|
* { eventType: 'tool.ocr', quantity: 3, units: 'pages', costUnits: 0.15 },
|
|
@@ -2154,7 +2244,7 @@ declare class Drip {
|
|
|
2154
2244
|
* // Record a failed run with error details
|
|
2155
2245
|
* const result = await drip.recordRun({
|
|
2156
2246
|
* customerId: 'cust_123',
|
|
2157
|
-
* workflow: '
|
|
2247
|
+
* workflow: 'doc_processing',
|
|
2158
2248
|
* events: [
|
|
2159
2249
|
* { eventType: 'agent.start', description: 'Started processing' },
|
|
2160
2250
|
* { eventType: 'tool.ocr', quantity: 1, units: 'pages' },
|
|
@@ -2326,6 +2416,33 @@ declare class Drip {
|
|
|
2326
2416
|
createStreamMeter(options: StreamMeterOptions): StreamMeter;
|
|
2327
2417
|
}
|
|
2328
2418
|
|
|
2419
|
+
/**
|
|
2420
|
+
* Pre-initialized Drip client singleton.
|
|
2421
|
+
*
|
|
2422
|
+
* Uses lazy initialization - only creates the client when first accessed.
|
|
2423
|
+
* Reads `DRIP_API_KEY` from environment variables.
|
|
2424
|
+
*
|
|
2425
|
+
* @example
|
|
2426
|
+
* ```typescript
|
|
2427
|
+
* import { drip } from '@drip-sdk/node';
|
|
2428
|
+
*
|
|
2429
|
+
* // Track usage with one line
|
|
2430
|
+
* await drip.trackUsage({ customerId: 'cust_123', meter: 'api_calls', quantity: 1 });
|
|
2431
|
+
*
|
|
2432
|
+
* // Charge with one line
|
|
2433
|
+
* await drip.charge({ customerId: 'cust_123', meter: 'api_calls', quantity: 1 });
|
|
2434
|
+
*
|
|
2435
|
+
* // Record a run
|
|
2436
|
+
* await drip.recordRun({
|
|
2437
|
+
* customerId: 'cust_123',
|
|
2438
|
+
* workflow: 'agent-run',
|
|
2439
|
+
* events: [{ eventType: 'llm.call', quantity: 1000, units: 'tokens' }],
|
|
2440
|
+
* status: 'COMPLETED',
|
|
2441
|
+
* });
|
|
2442
|
+
* ```
|
|
2443
|
+
*/
|
|
2444
|
+
declare const drip: Drip;
|
|
2445
|
+
|
|
2329
2446
|
// @ts-ignore
|
|
2330
2447
|
export = Drip;
|
|
2331
|
-
export { type BalanceResult, type Charge, type ChargeParams, type ChargeResult, type ChargeStatus, type CheckoutParams, type CheckoutResult, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitState, type CostEstimateLineItem, type CostEstimateResponse, type CreateCustomerParams, type CreateWebhookParams, type CreateWebhookResponse, type CreateWorkflowParams, type CustomPricing, type Customer, type DeleteWebhookResponse, Drip, type DripConfig, DripError, type EmitEventParams, type EndRunParams, type EstimateFromHypotheticalParams, type EstimateFromUsageParams, type EventResult, type HypotheticalUsageItem, type ListChargesOptions, type ListChargesResponse, type ListCustomersOptions, type ListCustomersResponse, type ListMetersResponse, type ListWebhooksResponse, type Meter, MetricsCollector, type MetricsSummary, RateLimiter, type RateLimiterConfig, type RecordRunEvent, type RecordRunParams, type RecordRunResult, type RequestMetrics, type ResilienceConfig, type ResilienceHealth, ResilienceManager, type RetryConfig, RetryExhaustedError, type RetryOptions, type RunResult, type RunStatus, type RunTimeline, type StartRunParams, StreamMeter, type StreamMeterFlushResult, type StreamMeterOptions, type TrackUsageParams, type TrackUsageResult, type Webhook, type WebhookEventType, type Workflow, type WrapApiCallParams, type WrapApiCallResult, calculateBackoff, createDefaultResilienceConfig, createDisabledResilienceConfig, createHighThroughputResilienceConfig, isRetryableError };
|
|
2448
|
+
export { type BalanceResult, type Charge, type ChargeParams, type ChargeResult, type ChargeStatus, type CheckoutParams, type CheckoutResult, CircuitBreaker, type CircuitBreakerConfig, CircuitBreakerOpenError, type CircuitState, type CostEstimateLineItem, type CostEstimateResponse, type CreateCustomerParams, type CreateWebhookParams, type CreateWebhookResponse, type CreateWorkflowParams, type CustomPricing, type Customer, type DeleteWebhookResponse, Drip, type DripConfig, DripError, type EmitEventParams, type EndRunParams, type EstimateFromHypotheticalParams, type EstimateFromUsageParams, type EventResult, type HypotheticalUsageItem, type ListChargesOptions, type ListChargesResponse, type ListCustomersOptions, type ListCustomersResponse, type ListMetersResponse, type ListWebhooksResponse, type Meter, MetricsCollector, type MetricsSummary, RateLimiter, type RateLimiterConfig, type RecordRunEvent, type RecordRunParams, type RecordRunResult, type RequestMetrics, type ResilienceConfig, type ResilienceHealth, ResilienceManager, type RetryConfig, RetryExhaustedError, type RetryOptions, type RunDetails, type RunResult, type RunStatus, type RunTimeline, type StartRunParams, StreamMeter, type StreamMeterFlushResult, type StreamMeterOptions, type TrackUsageParams, type TrackUsageResult, type Webhook, type WebhookEventType, type Workflow, type WrapApiCallParams, type WrapApiCallResult, calculateBackoff, createDefaultResilienceConfig, createDisabledResilienceConfig, createHighThroughputResilienceConfig, drip, isRetryableError };
|