@rustrak/client 0.3.13 → 0.3.14

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/dist/index.cjs CHANGED
@@ -7,7 +7,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
8
  var ky__default = /*#__PURE__*/_interopDefault(ky);
9
9
 
10
- // src/resources/alert-integrations.ts
10
+ // src/resources/agents.ts
11
11
  var paginatedResponseSchema = (itemSchema) => zod.z.object({
12
12
  items: zod.z.array(itemSchema),
13
13
  next_cursor: zod.z.string().optional(),
@@ -38,7 +38,29 @@ zod.z.object({
38
38
  message: zod.z.string().optional()
39
39
  });
40
40
 
41
- // src/schemas/alert.ts
41
+ // src/schemas/agent.ts
42
+ var agentTimeseriesPointSchema = zod.z.object({
43
+ bucket: dateTimeSchema,
44
+ value: zod.z.number()
45
+ });
46
+ var agentDurationPointSchema = zod.z.object({
47
+ bucket: dateTimeSchema,
48
+ avg_ms: zod.z.number(),
49
+ p95_ms: zod.z.number()
50
+ });
51
+ var genAiBreakdownRowSchema = zod.z.object({
52
+ label: zod.z.string(),
53
+ value: zod.z.number()
54
+ });
55
+ var agentTraceSummarySchema = zod.z.object({
56
+ trace_id: zod.z.string(),
57
+ /** Every distinct agent that ran in this trace, earliest first. */
58
+ agent_names: zod.z.array(zod.z.string()),
59
+ duration_ms: zod.z.number().nullable(),
60
+ total_tokens: zod.z.number(),
61
+ tool_call_count: zod.z.number().int(),
62
+ started_at: dateTimeSchema
63
+ });
42
64
  var providerTypeSchema = zod.z.enum(["webhook", "email", "slack"]);
43
65
  var alertTypeSchema = zod.z.enum(["new_issue", "regression", "unmute"]);
44
66
  var alertStatusSchema = zod.z.enum([
@@ -54,451 +76,81 @@ var alertIntegrationSchema = zod.z.object({
54
76
  credentials: zod.z.record(zod.z.string(), zod.z.unknown()),
55
77
  is_enabled: zod.z.boolean(),
56
78
  failure_count: zod.z.number().int(),
57
- last_failure_at: dateTimeSchema.nullable(),
58
- last_failure_message: zod.z.string().nullable(),
59
- last_success_at: dateTimeSchema.nullable(),
60
- created_at: dateTimeSchema,
61
- updated_at: dateTimeSchema
62
- });
63
- var createAlertIntegrationSchema = zod.z.object({
64
- name: zod.z.string().min(1),
65
- provider_type: providerTypeSchema,
66
- credentials: zod.z.record(zod.z.string(), zod.z.unknown()),
67
- is_enabled: zod.z.boolean().optional()
68
- });
69
- var updateAlertIntegrationSchema = zod.z.object({
70
- name: zod.z.string().min(1).optional(),
71
- credentials: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
72
- is_enabled: zod.z.boolean().optional()
73
- });
74
- var alertRuleChannelInputSchema = zod.z.object({
75
- integration_id: zod.z.number().int(),
76
- routing_override: zod.z.record(zod.z.string(), zod.z.unknown()).default({})
77
- });
78
- var alertRuleSchema = zod.z.object({
79
- id: zod.z.number().int(),
80
- project_id: zod.z.number().int(),
81
- name: zod.z.string(),
82
- alert_type: alertTypeSchema,
83
- is_enabled: zod.z.boolean(),
84
- conditions: zod.z.record(zod.z.string(), zod.z.unknown()),
85
- cooldown_minutes: zod.z.number().int(),
86
- last_triggered_at: dateTimeSchema.nullable(),
87
- created_at: dateTimeSchema,
88
- updated_at: dateTimeSchema,
89
- channels: zod.z.array(alertRuleChannelInputSchema).default([]),
90
- integration_ids: zod.z.array(zod.z.number().int())
91
- });
92
- var createAlertRuleSchema = zod.z.object({
93
- name: zod.z.string().min(1),
94
- alert_type: alertTypeSchema,
95
- channels: zod.z.array(alertRuleChannelInputSchema).default([]),
96
- is_enabled: zod.z.boolean().optional(),
97
- conditions: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
98
- cooldown_minutes: zod.z.number().int().min(0).optional()
99
- });
100
- var updateAlertRuleSchema = zod.z.object({
101
- name: zod.z.string().min(1).optional(),
102
- is_enabled: zod.z.boolean().optional(),
103
- conditions: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
104
- cooldown_minutes: zod.z.number().int().min(0).optional(),
105
- channels: zod.z.array(alertRuleChannelInputSchema).optional()
106
- });
107
- var alertHistorySchema = zod.z.object({
108
- id: zod.z.number().int(),
109
- alert_rule_id: zod.z.number().int().nullable(),
110
- integration_id: zod.z.number().int().nullable(),
111
- issue_id: zod.z.string().uuid().nullable(),
112
- project_id: zod.z.number().int().nullable(),
113
- alert_type: zod.z.string(),
114
- channel_type: zod.z.string(),
115
- channel_name: zod.z.string(),
116
- status: alertStatusSchema,
117
- attempt_count: zod.z.number().int(),
118
- next_retry_at: dateTimeSchema.nullable(),
119
- error_message: zod.z.string().nullable(),
120
- http_status_code: zod.z.number().int().nullable(),
121
- idempotency_key: zod.z.string(),
122
- created_at: dateTimeSchema,
123
- sent_at: dateTimeSchema.nullable()
124
- });
125
- var testChannelResponseSchema = zod.z.object({
126
- success: zod.z.boolean(),
127
- message: zod.z.string()
128
- });
129
- var testIntegrationBodySchema = zod.z.object({
130
- routing_override: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
131
- });
132
-
133
- // src/errors/base.ts
134
- var RustrakError = class extends Error {
135
- /**
136
- * Whether this error is safe to retry
137
- */
138
- retryable;
139
- /**
140
- * HTTP status code if applicable
141
- */
142
- statusCode;
143
- /**
144
- * Original error cause
145
- */
146
- cause;
147
- constructor(message, options) {
148
- super(message);
149
- this.name = this.constructor.name;
150
- this.retryable = options?.retryable ?? false;
151
- this.statusCode = options?.statusCode;
152
- this.cause = options?.cause;
153
- if (Error.captureStackTrace) {
154
- Error.captureStackTrace(this, this.constructor);
155
- }
156
- }
157
- };
158
-
159
- // src/errors/http.ts
160
- var NetworkError = class extends RustrakError {
161
- constructor(message, cause) {
162
- super(message, { retryable: true, cause });
163
- }
164
- };
165
- var AuthenticationError = class extends RustrakError {
166
- constructor(message = "Authentication failed") {
167
- super(message, { retryable: false, statusCode: 401 });
168
- }
169
- };
170
- var AuthorizationError = class extends RustrakError {
171
- constructor(message = "Insufficient permissions") {
172
- super(message, { retryable: false, statusCode: 403 });
173
- }
174
- };
175
- var NotFoundError = class extends RustrakError {
176
- constructor(resource) {
177
- super(`Resource not found: ${resource}`, {
178
- retryable: false,
179
- statusCode: 404
180
- });
181
- }
182
- };
183
- var RateLimitError = class extends RustrakError {
184
- /**
185
- * Number of seconds to wait before retrying (from Retry-After header)
186
- */
187
- retryAfter;
188
- constructor(message = "Rate limit exceeded", retryAfter) {
189
- super(message, { retryable: true, statusCode: 429 });
190
- if (retryAfter !== void 0) {
191
- this.retryAfter = typeof retryAfter === "string" ? parseInt(retryAfter, 10) : retryAfter;
192
- }
193
- }
194
- };
195
- var ServerError = class extends RustrakError {
196
- constructor(message, statusCode = 500) {
197
- super(message, { retryable: true, statusCode });
198
- }
199
- };
200
- var BadRequestError = class extends RustrakError {
201
- constructor(message) {
202
- super(message, { retryable: false, statusCode: 400 });
203
- }
204
- };
205
-
206
- // src/errors/validation.ts
207
- var ValidationError = class extends RustrakError {
208
- /**
209
- * Zod validation errors
210
- */
211
- validationErrors;
212
- constructor(message, validationErrors) {
213
- super(message, { retryable: false });
214
- this.validationErrors = validationErrors;
215
- }
216
- /**
217
- * Get a formatted string of validation errors
218
- */
219
- getValidationDetails() {
220
- if (!this.validationErrors) {
221
- return this.message;
222
- }
223
- const errors = this.validationErrors.issues.map((err) => `${err.path.map(String).join(".")}: ${err.message}`).join(", ");
224
- return `${this.message} - ${errors}`;
225
- }
226
- };
227
-
228
- // src/resources/base.ts
229
- var BaseResource = class {
230
- http;
231
- constructor(http) {
232
- this.http = http;
233
- }
234
- /**
235
- * Validate API response against Zod schema
236
- * @throws {ValidationError} if validation fails
237
- */
238
- validate(data, schema) {
239
- const result = schema.safeParse(data);
240
- if (!result.success) {
241
- throw new ValidationError("API response validation failed", result.error);
242
- }
243
- return result.data;
244
- }
245
- };
246
-
247
- // src/resources/alert-integrations.ts
248
- var AlertIntegrationsResource = class extends BaseResource {
249
- /**
250
- * List all alert integrations
251
- */
252
- async list() {
253
- const data = await this.http.get("api/integrations").json();
254
- return this.validate(data, zod.z.array(alertIntegrationSchema));
255
- }
256
- /**
257
- * Get a single alert integration by ID
258
- */
259
- async get(id) {
260
- const data = await this.http.get(`api/integrations/${id}`).json();
261
- return this.validate(data, alertIntegrationSchema);
262
- }
263
- /**
264
- * Create a new alert integration
265
- */
266
- async create(input) {
267
- const validatedInput = this.validate(input, createAlertIntegrationSchema);
268
- const data = await this.http.post("api/integrations", { json: validatedInput }).json();
269
- return this.validate(data, alertIntegrationSchema);
270
- }
271
- /**
272
- * Update an existing alert integration
273
- */
274
- async update(id, input) {
275
- const validatedInput = this.validate(input, updateAlertIntegrationSchema);
276
- const data = await this.http.patch(`api/integrations/${id}`, { json: validatedInput }).json();
277
- return this.validate(data, alertIntegrationSchema);
278
- }
279
- /**
280
- * Delete an alert integration
281
- */
282
- async delete(id) {
283
- await this.http.delete(`api/integrations/${id}`);
284
- }
285
- /**
286
- * Send a test notification to verify integration configuration.
287
- * For Slack bot_token integrations, routingOverride must include `channel`.
288
- */
289
- async test(id, routingOverride) {
290
- const body = routingOverride !== void 0 ? this.validate(
291
- { routing_override: routingOverride },
292
- testIntegrationBodySchema
293
- ) : void 0;
294
- const data = await this.http.post(
295
- `api/integrations/${id}/test`,
296
- body !== void 0 ? { json: body } : void 0
297
- ).json();
298
- return this.validate(data, testChannelResponseSchema);
299
- }
300
- };
301
- var AlertRulesResource = class extends BaseResource {
302
- /**
303
- * List all alert rules for a project
304
- */
305
- async list(projectId) {
306
- const data = await this.http.get(`api/projects/${projectId}/alert-rules`).json();
307
- return this.validate(data, zod.z.array(alertRuleSchema));
308
- }
309
- /**
310
- * Get a single alert rule by ID
311
- */
312
- async get(projectId, ruleId) {
313
- const data = await this.http.get(`api/projects/${projectId}/alert-rules/${ruleId}`).json();
314
- return this.validate(data, alertRuleSchema);
315
- }
316
- /**
317
- * Create a new alert rule for a project
318
- */
319
- async create(projectId, input) {
320
- const validatedInput = this.validate(input, createAlertRuleSchema);
321
- const data = await this.http.post(`api/projects/${projectId}/alert-rules`, { json: validatedInput }).json();
322
- return this.validate(data, alertRuleSchema);
323
- }
324
- /**
325
- * Update an existing alert rule
326
- */
327
- async update(projectId, ruleId, input) {
328
- const validatedInput = this.validate(input, updateAlertRuleSchema);
329
- const data = await this.http.patch(`api/projects/${projectId}/alert-rules/${ruleId}`, {
330
- json: validatedInput
331
- }).json();
332
- return this.validate(data, alertRuleSchema);
333
- }
334
- /**
335
- * Delete an alert rule
336
- */
337
- async delete(projectId, ruleId) {
338
- await this.http.delete(`api/projects/${projectId}/alert-rules/${ruleId}`);
339
- }
340
- /**
341
- * List alert history for a project
342
- */
343
- async listHistory(projectId, options) {
344
- const searchParams = new URLSearchParams();
345
- if (options?.limit !== void 0) {
346
- searchParams.set("limit", options.limit.toString());
347
- }
348
- const query = searchParams.toString();
349
- const url = query ? `api/projects/${projectId}/alert-history?${query}` : `api/projects/${projectId}/alert-history`;
350
- const data = await this.http.get(url).json();
351
- return this.validate(data, zod.z.array(alertHistorySchema));
352
- }
353
- };
354
- var globalRoleSchema = zod.z.enum(["admin", "member"]);
355
- var teamMemberSchema = zod.z.object({
356
- id: zod.z.number().int(),
357
- email: zod.z.string().email(),
358
- role: globalRoleSchema,
359
- is_active: zod.z.boolean(),
360
- /** True for the first-registered account, which cannot be demoted or deleted. */
361
- is_primary: zod.z.boolean().optional(),
362
- created_at: dateTimeSchema,
363
- last_login: dateTimeSchema.nullable().optional()
364
- });
365
- var updateUserRoleSchema = zod.z.object({
366
- role: globalRoleSchema
367
- });
368
-
369
- // src/schemas/invitation.ts
370
- var invitationStatusSchema = zod.z.string();
371
- var invitationSchema = zod.z.object({
372
- token: zod.z.string(),
373
- email: zod.z.string().email(),
374
- role: globalRoleSchema,
375
- status: invitationStatusSchema,
376
- expires_at: dateTimeSchema,
377
- created_at: dateTimeSchema
378
- });
379
- var invitationInfoSchema = zod.z.object({
380
- email: zod.z.string().email(),
381
- role: globalRoleSchema,
382
- status: invitationStatusSchema,
383
- expires_at: dateTimeSchema
384
- });
385
- var createInvitationSchema = zod.z.object({
386
- email: zod.z.string().email(),
387
- role: globalRoleSchema
388
- });
389
- var acceptInvitationSchema = zod.z.object({
390
- token: zod.z.string().min(1),
391
- password: zod.z.string().min(1)
392
- });
393
- var userSchema = zod.z.object({
394
- id: zod.z.number().int().positive(),
395
- email: zod.z.string().email(),
396
- role: globalRoleSchema,
397
- is_admin: zod.z.boolean()
398
- });
399
- var authResponseSchema = zod.z.object({
400
- user: userSchema
401
- });
402
- zod.z.object({
403
- user: userSchema,
404
- cookies: zod.z.array(zod.z.string())
405
- });
406
- var loginRequestSchema = zod.z.object({
407
- email: zod.z.string().email(),
408
- password: zod.z.string().min(1)
409
- });
410
- var registerRequestSchema = zod.z.object({
411
- email: zod.z.string().email(),
412
- password: zod.z.string().min(1)
413
- });
414
-
415
- // src/resources/auth.ts
416
- var AuthResource = class extends BaseResource {
417
- /**
418
- * Register a new user account
419
- * Creates a new user and automatically logs them in (sets session cookie)
420
- * @param credentials - Email and password for the new account
421
- * @returns LoginResult with user information and session cookies
422
- */
423
- async register(credentials) {
424
- const validatedInput = this.validate(credentials, registerRequestSchema);
425
- const response = await this.http.post("auth/register", {
426
- json: validatedInput
427
- });
428
- const cookies = response.headers.getSetCookie();
429
- const data = await response.json();
430
- const authResponse = this.validate(data, authResponseSchema);
431
- return {
432
- user: authResponse.user,
433
- cookies
434
- };
435
- }
436
- /**
437
- * Login with email and password
438
- * Authenticates the user and sets a session cookie
439
- * @param credentials - Email and password
440
- * @returns LoginResult with user information and session cookies
441
- */
442
- async login(credentials) {
443
- const validatedInput = this.validate(credentials, loginRequestSchema);
444
- const response = await this.http.post("auth/login", {
445
- json: validatedInput
446
- });
447
- const cookies = response.headers.getSetCookie();
448
- const data = await response.json();
449
- const authResponse = this.validate(data, authResponseSchema);
450
- return {
451
- user: authResponse.user,
452
- cookies
453
- };
454
- }
455
- /**
456
- * Logout the current user
457
- * Clears the session cookie
458
- * @returns Array of Set-Cookie headers (typically clearing cookies)
459
- */
460
- async logout() {
461
- const response = await this.http.post("auth/logout");
462
- return response.headers.getSetCookie();
463
- }
464
- /**
465
- * Get current authenticated user
466
- * Requires a valid session cookie
467
- * @returns User information
468
- */
469
- async getCurrentUser() {
470
- const data = await this.http.get("auth/me").json();
471
- return this.validate(data, userSchema);
472
- }
473
- /**
474
- * Get the details of a pending invitation by its token (public endpoint)
475
- * Used by the accept-invitation page before the user has an account
476
- * @param token - Invitation token
477
- * @returns Invitation info (email, role, status, expiry)
478
- */
479
- async getInvitation(token) {
480
- const data = await this.http.get(`auth/invitation/${token}`).json();
481
- return this.validate(data, invitationInfoSchema);
482
- }
483
- /**
484
- * Accept a pending invitation, creating the user account and logging in
485
- * @param input - Invitation token and the new account's password
486
- * @returns LoginResult with user information and session cookies
487
- */
488
- async acceptInvitation(input) {
489
- const validatedInput = this.validate(input, acceptInvitationSchema);
490
- const response = await this.http.post("auth/accept-invitation", {
491
- json: validatedInput
492
- });
493
- const cookies = response.headers.getSetCookie();
494
- const data = await response.json();
495
- const authResponse = this.validate(data, authResponseSchema);
496
- return {
497
- user: authResponse.user,
498
- cookies
499
- };
500
- }
501
- };
79
+ last_failure_at: dateTimeSchema.nullable(),
80
+ last_failure_message: zod.z.string().nullable(),
81
+ last_success_at: dateTimeSchema.nullable(),
82
+ created_at: dateTimeSchema,
83
+ updated_at: dateTimeSchema
84
+ });
85
+ var createAlertIntegrationSchema = zod.z.object({
86
+ name: zod.z.string().min(1),
87
+ provider_type: providerTypeSchema,
88
+ credentials: zod.z.record(zod.z.string(), zod.z.unknown()),
89
+ is_enabled: zod.z.boolean().optional()
90
+ });
91
+ var updateAlertIntegrationSchema = zod.z.object({
92
+ name: zod.z.string().min(1).optional(),
93
+ credentials: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
94
+ is_enabled: zod.z.boolean().optional()
95
+ });
96
+ var alertRuleChannelInputSchema = zod.z.object({
97
+ integration_id: zod.z.number().int(),
98
+ routing_override: zod.z.record(zod.z.string(), zod.z.unknown()).default({})
99
+ });
100
+ var alertRuleSchema = zod.z.object({
101
+ id: zod.z.number().int(),
102
+ project_id: zod.z.number().int(),
103
+ name: zod.z.string(),
104
+ alert_type: alertTypeSchema,
105
+ is_enabled: zod.z.boolean(),
106
+ conditions: zod.z.record(zod.z.string(), zod.z.unknown()),
107
+ cooldown_minutes: zod.z.number().int(),
108
+ last_triggered_at: dateTimeSchema.nullable(),
109
+ created_at: dateTimeSchema,
110
+ updated_at: dateTimeSchema,
111
+ channels: zod.z.array(alertRuleChannelInputSchema).default([]),
112
+ integration_ids: zod.z.array(zod.z.number().int())
113
+ });
114
+ var createAlertRuleSchema = zod.z.object({
115
+ name: zod.z.string().min(1),
116
+ alert_type: alertTypeSchema,
117
+ channels: zod.z.array(alertRuleChannelInputSchema).default([]),
118
+ is_enabled: zod.z.boolean().optional(),
119
+ conditions: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
120
+ cooldown_minutes: zod.z.number().int().min(0).optional()
121
+ });
122
+ var updateAlertRuleSchema = zod.z.object({
123
+ name: zod.z.string().min(1).optional(),
124
+ is_enabled: zod.z.boolean().optional(),
125
+ conditions: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
126
+ cooldown_minutes: zod.z.number().int().min(0).optional(),
127
+ channels: zod.z.array(alertRuleChannelInputSchema).optional()
128
+ });
129
+ var alertHistorySchema = zod.z.object({
130
+ id: zod.z.number().int(),
131
+ alert_rule_id: zod.z.number().int().nullable(),
132
+ integration_id: zod.z.number().int().nullable(),
133
+ issue_id: zod.z.string().uuid().nullable(),
134
+ project_id: zod.z.number().int().nullable(),
135
+ alert_type: zod.z.string(),
136
+ channel_type: zod.z.string(),
137
+ channel_name: zod.z.string(),
138
+ status: alertStatusSchema,
139
+ attempt_count: zod.z.number().int(),
140
+ next_retry_at: dateTimeSchema.nullable(),
141
+ error_message: zod.z.string().nullable(),
142
+ http_status_code: zod.z.number().int().nullable(),
143
+ idempotency_key: zod.z.string(),
144
+ created_at: dateTimeSchema,
145
+ sent_at: dateTimeSchema.nullable()
146
+ });
147
+ var testChannelResponseSchema = zod.z.object({
148
+ success: zod.z.boolean(),
149
+ message: zod.z.string()
150
+ });
151
+ var testIntegrationBodySchema = zod.z.object({
152
+ routing_override: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
153
+ });
502
154
  var eventSchema = zod.z.object({
503
155
  id: uuidSchema,
504
156
  event_id: eventIdSchema,
@@ -529,6 +181,45 @@ var eventDetailSchema = zod.z.object({
529
181
  data: zod.z.record(zod.z.string(), zod.z.any())
530
182
  // Full Sentry event JSON
531
183
  });
184
+ var globalRoleSchema = zod.z.enum(["admin", "member"]);
185
+ var teamMemberSchema = zod.z.object({
186
+ id: zod.z.number().int(),
187
+ email: zod.z.string().email(),
188
+ role: globalRoleSchema,
189
+ is_active: zod.z.boolean(),
190
+ /** True for the first-registered account, which cannot be demoted or deleted. */
191
+ is_primary: zod.z.boolean().optional(),
192
+ created_at: dateTimeSchema,
193
+ last_login: dateTimeSchema.nullable().optional()
194
+ });
195
+ var updateUserRoleSchema = zod.z.object({
196
+ role: globalRoleSchema
197
+ });
198
+
199
+ // src/schemas/invitation.ts
200
+ var invitationStatusSchema = zod.z.string();
201
+ var invitationSchema = zod.z.object({
202
+ token: zod.z.string(),
203
+ email: zod.z.string().email(),
204
+ role: globalRoleSchema,
205
+ status: invitationStatusSchema,
206
+ expires_at: dateTimeSchema,
207
+ created_at: dateTimeSchema
208
+ });
209
+ var invitationInfoSchema = zod.z.object({
210
+ email: zod.z.string().email(),
211
+ role: globalRoleSchema,
212
+ status: invitationStatusSchema,
213
+ expires_at: dateTimeSchema
214
+ });
215
+ var createInvitationSchema = zod.z.object({
216
+ email: zod.z.string().email(),
217
+ role: globalRoleSchema
218
+ });
219
+ var acceptInvitationSchema = zod.z.object({
220
+ token: zod.z.string().min(1),
221
+ password: zod.z.string().min(1)
222
+ });
532
223
  var issueStatusSchema = zod.z.enum(["unresolved", "resolved", "ignored"]);
533
224
  var issuePrioritySchema = zod.z.enum(["low", "medium", "high"]);
534
225
  var issueSchema = zod.z.object({
@@ -832,6 +523,8 @@ var transactionDetailSchema = zod.z.object({
832
523
  });
833
524
  var spanSchema = zod.z.object({
834
525
  id: uuidSchema,
526
+ /** Parent transaction, if this span was extracted from one. `null` for a standalone span. */
527
+ transaction_id: uuidSchema.nullable(),
835
528
  span_id: zod.z.string().nullable(),
836
529
  trace_id: zod.z.string().nullable(),
837
530
  parent_span_id: zod.z.string().nullable(),
@@ -843,7 +536,21 @@ var spanSchema = zod.z.object({
843
536
  duration_ms: zod.z.number().nullable(),
844
537
  exclusive_time_ms: zod.z.number().nullable(),
845
538
  is_segment: zod.z.boolean(),
846
- segment_id: zod.z.string().nullable()
539
+ segment_id: zod.z.string().nullable(),
540
+ /** Only ever set for standalone spans — a transaction-embedded span has no parent row to inherit these from. */
541
+ platform: zod.z.string().nullable(),
542
+ release: zod.z.string().nullable(),
543
+ environment: zod.z.string().nullable(),
544
+ /** gen_ai.* denormalized fields — all null unless recognized as an AI span. */
545
+ gen_ai_operation_type: zod.z.string().nullable(),
546
+ gen_ai_agent_name: zod.z.string().nullable(),
547
+ gen_ai_request_model: zod.z.string().nullable(),
548
+ gen_ai_response_model: zod.z.string().nullable(),
549
+ gen_ai_tool_name: zod.z.string().nullable(),
550
+ gen_ai_conversation_id: zod.z.string().nullable(),
551
+ gen_ai_usage_input_tokens: zod.z.number().nullable(),
552
+ gen_ai_usage_output_tokens: zod.z.number().nullable(),
553
+ gen_ai_usage_total_tokens: zod.z.number().nullable()
847
554
  });
848
555
  var transactionStatsSchema = zod.z.object({
849
556
  transaction_name: zod.z.string(),
@@ -854,6 +561,422 @@ var transactionStatsSchema = zod.z.object({
854
561
  p99_ms: zod.z.number(),
855
562
  failure_rate: zod.z.number()
856
563
  });
564
+ var userSchema = zod.z.object({
565
+ id: zod.z.number().int().positive(),
566
+ email: zod.z.string().email(),
567
+ role: globalRoleSchema,
568
+ is_admin: zod.z.boolean()
569
+ });
570
+ var authResponseSchema = zod.z.object({
571
+ user: userSchema
572
+ });
573
+ zod.z.object({
574
+ user: userSchema,
575
+ cookies: zod.z.array(zod.z.string())
576
+ });
577
+ var loginRequestSchema = zod.z.object({
578
+ email: zod.z.string().email(),
579
+ password: zod.z.string().min(1)
580
+ });
581
+ var registerRequestSchema = zod.z.object({
582
+ email: zod.z.string().email(),
583
+ password: zod.z.string().min(1)
584
+ });
585
+
586
+ // src/errors/base.ts
587
+ var RustrakError = class extends Error {
588
+ /**
589
+ * Whether this error is safe to retry
590
+ */
591
+ retryable;
592
+ /**
593
+ * HTTP status code if applicable
594
+ */
595
+ statusCode;
596
+ /**
597
+ * Original error cause
598
+ */
599
+ cause;
600
+ constructor(message, options) {
601
+ super(message);
602
+ this.name = this.constructor.name;
603
+ this.retryable = options?.retryable ?? false;
604
+ this.statusCode = options?.statusCode;
605
+ this.cause = options?.cause;
606
+ if (Error.captureStackTrace) {
607
+ Error.captureStackTrace(this, this.constructor);
608
+ }
609
+ }
610
+ };
611
+
612
+ // src/errors/http.ts
613
+ var NetworkError = class extends RustrakError {
614
+ constructor(message, cause) {
615
+ super(message, { retryable: true, cause });
616
+ }
617
+ };
618
+ var AuthenticationError = class extends RustrakError {
619
+ constructor(message = "Authentication failed") {
620
+ super(message, { retryable: false, statusCode: 401 });
621
+ }
622
+ };
623
+ var AuthorizationError = class extends RustrakError {
624
+ constructor(message = "Insufficient permissions") {
625
+ super(message, { retryable: false, statusCode: 403 });
626
+ }
627
+ };
628
+ var NotFoundError = class extends RustrakError {
629
+ constructor(resource) {
630
+ super(`Resource not found: ${resource}`, {
631
+ retryable: false,
632
+ statusCode: 404
633
+ });
634
+ }
635
+ };
636
+ var RateLimitError = class extends RustrakError {
637
+ /**
638
+ * Number of seconds to wait before retrying (from Retry-After header)
639
+ */
640
+ retryAfter;
641
+ constructor(message = "Rate limit exceeded", retryAfter) {
642
+ super(message, { retryable: true, statusCode: 429 });
643
+ if (retryAfter !== void 0) {
644
+ this.retryAfter = typeof retryAfter === "string" ? parseInt(retryAfter, 10) : retryAfter;
645
+ }
646
+ }
647
+ };
648
+ var ServerError = class extends RustrakError {
649
+ constructor(message, statusCode = 500) {
650
+ super(message, { retryable: true, statusCode });
651
+ }
652
+ };
653
+ var BadRequestError = class extends RustrakError {
654
+ constructor(message) {
655
+ super(message, { retryable: false, statusCode: 400 });
656
+ }
657
+ };
658
+
659
+ // src/errors/validation.ts
660
+ var ValidationError = class extends RustrakError {
661
+ /**
662
+ * Zod validation errors
663
+ */
664
+ validationErrors;
665
+ constructor(message, validationErrors) {
666
+ super(message, { retryable: false });
667
+ this.validationErrors = validationErrors;
668
+ }
669
+ /**
670
+ * Get a formatted string of validation errors
671
+ */
672
+ getValidationDetails() {
673
+ if (!this.validationErrors) {
674
+ return this.message;
675
+ }
676
+ const errors = this.validationErrors.issues.map((err) => `${err.path.map(String).join(".")}: ${err.message}`).join(", ");
677
+ return `${this.message} - ${errors}`;
678
+ }
679
+ };
680
+
681
+ // src/resources/base.ts
682
+ var BaseResource = class {
683
+ http;
684
+ constructor(http) {
685
+ this.http = http;
686
+ }
687
+ /**
688
+ * Validate API response against Zod schema
689
+ * @throws {ValidationError} if validation fails
690
+ */
691
+ validate(data, schema) {
692
+ const result = schema.safeParse(data);
693
+ if (!result.success) {
694
+ throw new ValidationError("API response validation failed", result.error);
695
+ }
696
+ return result.data;
697
+ }
698
+ };
699
+
700
+ // src/resources/agents.ts
701
+ function timeseriesSearchParams(options) {
702
+ const searchParams = {};
703
+ if (options?.period_hours) {
704
+ searchParams.period_hours = String(options.period_hours);
705
+ }
706
+ if (options?.interval_hours) {
707
+ searchParams.interval_hours = String(options.interval_hours);
708
+ }
709
+ return searchParams;
710
+ }
711
+ function breakdownSearchParams(options) {
712
+ const searchParams = {};
713
+ if (options?.period_hours) {
714
+ searchParams.period_hours = String(options.period_hours);
715
+ }
716
+ if (options?.limit) {
717
+ searchParams.limit = String(options.limit);
718
+ }
719
+ return searchParams;
720
+ }
721
+ var AgentsResource = class extends BaseResource {
722
+ /**
723
+ * Time-bucketed count of agent-run spans (`gen_ai.operation.type:agent`).
724
+ */
725
+ async getRuns(projectId, options) {
726
+ const data = await this.http.get(`api/projects/${projectId}/agents/runs`, {
727
+ searchParams: timeseriesSearchParams(options)
728
+ }).json();
729
+ return this.validate(data, zod.z.array(agentTimeseriesPointSchema));
730
+ }
731
+ /**
732
+ * Time-bucketed avg/p95 duration for `agent`/`ai_client` spans.
733
+ */
734
+ async getDuration(projectId, options) {
735
+ const data = await this.http.get(`api/projects/${projectId}/agents/duration`, {
736
+ searchParams: timeseriesSearchParams(options)
737
+ }).json();
738
+ return this.validate(data, zod.z.array(agentDurationPointSchema));
739
+ }
740
+ /**
741
+ * Top models by LLM call count (`gen_ai.operation.type:ai_client`).
742
+ */
743
+ async getModelsByCalls(projectId, options) {
744
+ const data = await this.http.get(`api/projects/${projectId}/agents/models/calls`, {
745
+ searchParams: breakdownSearchParams(options)
746
+ }).json();
747
+ return this.validate(data, zod.z.array(genAiBreakdownRowSchema));
748
+ }
749
+ /**
750
+ * Top models by total tokens used (`gen_ai.operation.type:ai_client`).
751
+ */
752
+ async getModelsByTokens(projectId, options) {
753
+ const data = await this.http.get(`api/projects/${projectId}/agents/models/tokens`, {
754
+ searchParams: breakdownSearchParams(options)
755
+ }).json();
756
+ return this.validate(data, zod.z.array(genAiBreakdownRowSchema));
757
+ }
758
+ /**
759
+ * Top tools by call count (`gen_ai.operation.type:tool`).
760
+ */
761
+ async getTools(projectId, options) {
762
+ const data = await this.http.get(`api/projects/${projectId}/agents/tools`, {
763
+ searchParams: breakdownSearchParams(options)
764
+ }).json();
765
+ return this.validate(data, zod.z.array(genAiBreakdownRowSchema));
766
+ }
767
+ /**
768
+ * Paginated per-trace_id aggregate (duration, tokens, tool usage) across
769
+ * all AI spans sharing that trace, regardless of origin.
770
+ */
771
+ async getTraces(projectId, options) {
772
+ const searchParams = {};
773
+ if (options?.page) {
774
+ searchParams.page = String(options.page);
775
+ }
776
+ if (options?.per_page) {
777
+ searchParams.per_page = String(options.per_page);
778
+ }
779
+ const data = await this.http.get(`api/projects/${projectId}/agents/traces`, { searchParams }).json();
780
+ return this.validate(
781
+ data,
782
+ offsetPaginatedResponseSchema(agentTraceSummarySchema)
783
+ );
784
+ }
785
+ };
786
+ var AlertIntegrationsResource = class extends BaseResource {
787
+ /**
788
+ * List all alert integrations
789
+ */
790
+ async list() {
791
+ const data = await this.http.get("api/integrations").json();
792
+ return this.validate(data, zod.z.array(alertIntegrationSchema));
793
+ }
794
+ /**
795
+ * Get a single alert integration by ID
796
+ */
797
+ async get(id) {
798
+ const data = await this.http.get(`api/integrations/${id}`).json();
799
+ return this.validate(data, alertIntegrationSchema);
800
+ }
801
+ /**
802
+ * Create a new alert integration
803
+ */
804
+ async create(input) {
805
+ const validatedInput = this.validate(input, createAlertIntegrationSchema);
806
+ const data = await this.http.post("api/integrations", { json: validatedInput }).json();
807
+ return this.validate(data, alertIntegrationSchema);
808
+ }
809
+ /**
810
+ * Update an existing alert integration
811
+ */
812
+ async update(id, input) {
813
+ const validatedInput = this.validate(input, updateAlertIntegrationSchema);
814
+ const data = await this.http.patch(`api/integrations/${id}`, { json: validatedInput }).json();
815
+ return this.validate(data, alertIntegrationSchema);
816
+ }
817
+ /**
818
+ * Delete an alert integration
819
+ */
820
+ async delete(id) {
821
+ await this.http.delete(`api/integrations/${id}`);
822
+ }
823
+ /**
824
+ * Send a test notification to verify integration configuration.
825
+ * For Slack bot_token integrations, routingOverride must include `channel`.
826
+ */
827
+ async test(id, routingOverride) {
828
+ const body = routingOverride !== void 0 ? this.validate(
829
+ { routing_override: routingOverride },
830
+ testIntegrationBodySchema
831
+ ) : void 0;
832
+ const data = await this.http.post(
833
+ `api/integrations/${id}/test`,
834
+ body !== void 0 ? { json: body } : void 0
835
+ ).json();
836
+ return this.validate(data, testChannelResponseSchema);
837
+ }
838
+ };
839
+ var AlertRulesResource = class extends BaseResource {
840
+ /**
841
+ * List all alert rules for a project
842
+ */
843
+ async list(projectId) {
844
+ const data = await this.http.get(`api/projects/${projectId}/alert-rules`).json();
845
+ return this.validate(data, zod.z.array(alertRuleSchema));
846
+ }
847
+ /**
848
+ * Get a single alert rule by ID
849
+ */
850
+ async get(projectId, ruleId) {
851
+ const data = await this.http.get(`api/projects/${projectId}/alert-rules/${ruleId}`).json();
852
+ return this.validate(data, alertRuleSchema);
853
+ }
854
+ /**
855
+ * Create a new alert rule for a project
856
+ */
857
+ async create(projectId, input) {
858
+ const validatedInput = this.validate(input, createAlertRuleSchema);
859
+ const data = await this.http.post(`api/projects/${projectId}/alert-rules`, { json: validatedInput }).json();
860
+ return this.validate(data, alertRuleSchema);
861
+ }
862
+ /**
863
+ * Update an existing alert rule
864
+ */
865
+ async update(projectId, ruleId, input) {
866
+ const validatedInput = this.validate(input, updateAlertRuleSchema);
867
+ const data = await this.http.patch(`api/projects/${projectId}/alert-rules/${ruleId}`, {
868
+ json: validatedInput
869
+ }).json();
870
+ return this.validate(data, alertRuleSchema);
871
+ }
872
+ /**
873
+ * Delete an alert rule
874
+ */
875
+ async delete(projectId, ruleId) {
876
+ await this.http.delete(`api/projects/${projectId}/alert-rules/${ruleId}`);
877
+ }
878
+ /**
879
+ * List alert history for a project
880
+ */
881
+ async listHistory(projectId, options) {
882
+ const searchParams = new URLSearchParams();
883
+ if (options?.limit !== void 0) {
884
+ searchParams.set("limit", options.limit.toString());
885
+ }
886
+ const query = searchParams.toString();
887
+ const url = query ? `api/projects/${projectId}/alert-history?${query}` : `api/projects/${projectId}/alert-history`;
888
+ const data = await this.http.get(url).json();
889
+ return this.validate(data, zod.z.array(alertHistorySchema));
890
+ }
891
+ };
892
+
893
+ // src/resources/auth.ts
894
+ var AuthResource = class extends BaseResource {
895
+ /**
896
+ * Register a new user account
897
+ * Creates a new user and automatically logs them in (sets session cookie)
898
+ * @param credentials - Email and password for the new account
899
+ * @returns LoginResult with user information and session cookies
900
+ */
901
+ async register(credentials) {
902
+ const validatedInput = this.validate(credentials, registerRequestSchema);
903
+ const response = await this.http.post("auth/register", {
904
+ json: validatedInput
905
+ });
906
+ const cookies = response.headers.getSetCookie();
907
+ const data = await response.json();
908
+ const authResponse = this.validate(data, authResponseSchema);
909
+ return {
910
+ user: authResponse.user,
911
+ cookies
912
+ };
913
+ }
914
+ /**
915
+ * Login with email and password
916
+ * Authenticates the user and sets a session cookie
917
+ * @param credentials - Email and password
918
+ * @returns LoginResult with user information and session cookies
919
+ */
920
+ async login(credentials) {
921
+ const validatedInput = this.validate(credentials, loginRequestSchema);
922
+ const response = await this.http.post("auth/login", {
923
+ json: validatedInput
924
+ });
925
+ const cookies = response.headers.getSetCookie();
926
+ const data = await response.json();
927
+ const authResponse = this.validate(data, authResponseSchema);
928
+ return {
929
+ user: authResponse.user,
930
+ cookies
931
+ };
932
+ }
933
+ /**
934
+ * Logout the current user
935
+ * Clears the session cookie
936
+ * @returns Array of Set-Cookie headers (typically clearing cookies)
937
+ */
938
+ async logout() {
939
+ const response = await this.http.post("auth/logout");
940
+ return response.headers.getSetCookie();
941
+ }
942
+ /**
943
+ * Get current authenticated user
944
+ * Requires a valid session cookie
945
+ * @returns User information
946
+ */
947
+ async getCurrentUser() {
948
+ const data = await this.http.get("auth/me").json();
949
+ return this.validate(data, userSchema);
950
+ }
951
+ /**
952
+ * Get the details of a pending invitation by its token (public endpoint)
953
+ * Used by the accept-invitation page before the user has an account
954
+ * @param token - Invitation token
955
+ * @returns Invitation info (email, role, status, expiry)
956
+ */
957
+ async getInvitation(token) {
958
+ const data = await this.http.get(`auth/invitation/${token}`).json();
959
+ return this.validate(data, invitationInfoSchema);
960
+ }
961
+ /**
962
+ * Accept a pending invitation, creating the user account and logging in
963
+ * @param input - Invitation token and the new account's password
964
+ * @returns LoginResult with user information and session cookies
965
+ */
966
+ async acceptInvitation(input) {
967
+ const validatedInput = this.validate(input, acceptInvitationSchema);
968
+ const response = await this.http.post("auth/accept-invitation", {
969
+ json: validatedInput
970
+ });
971
+ const cookies = response.headers.getSetCookie();
972
+ const data = await response.json();
973
+ const authResponse = this.validate(data, authResponseSchema);
974
+ return {
975
+ user: authResponse.user,
976
+ cookies
977
+ };
978
+ }
979
+ };
857
980
 
858
981
  // src/resources/events.ts
859
982
  var EventsResource = class extends BaseResource {
@@ -1330,6 +1453,37 @@ var SourceMapsResource = class extends BaseResource {
1330
1453
  return this.validate(data, listSourceMapsResponseSchema);
1331
1454
  }
1332
1455
  };
1456
+
1457
+ // src/resources/spans.ts
1458
+ var SpansResource = class extends BaseResource {
1459
+ /**
1460
+ * List spans for a project with offset-based pagination (newest first),
1461
+ * optionally filtered by op/status/trace_id/operation_type.
1462
+ */
1463
+ async list(projectId, options) {
1464
+ const searchParams = {};
1465
+ if (options?.page) {
1466
+ searchParams.page = String(options.page);
1467
+ }
1468
+ if (options?.per_page) {
1469
+ searchParams.per_page = String(options.per_page);
1470
+ }
1471
+ if (options?.op) {
1472
+ searchParams.op = options.op;
1473
+ }
1474
+ if (options?.status) {
1475
+ searchParams.status = options.status;
1476
+ }
1477
+ if (options?.trace_id) {
1478
+ searchParams.trace_id = options.trace_id;
1479
+ }
1480
+ if (options?.operation_type) {
1481
+ searchParams.operation_type = options.operation_type;
1482
+ }
1483
+ const data = await this.http.get(`api/projects/${projectId}/spans`, { searchParams }).json();
1484
+ return this.validate(data, offsetPaginatedResponseSchema(spanSchema));
1485
+ }
1486
+ };
1333
1487
  var StorageResource = class extends BaseResource {
1334
1488
  /**
1335
1489
  * Get the instance-wide storage summary: row counts per data category, the
@@ -1658,6 +1812,14 @@ var RustrakClient = class {
1658
1812
  * Logs API resource (standalone logs)
1659
1813
  */
1660
1814
  logs;
1815
+ /**
1816
+ * Spans API resource (standalone + transaction-embedded spans, shared table)
1817
+ */
1818
+ spans;
1819
+ /**
1820
+ * AI Agent Monitoring dashboard API resource
1821
+ */
1822
+ agents;
1661
1823
  /**
1662
1824
  * Storage API resource (usage + retention cleanup, admin only)
1663
1825
  */
@@ -1688,6 +1850,8 @@ var RustrakClient = class {
1688
1850
  this.releases = new ReleasesResource(this.http);
1689
1851
  this.transactions = new TransactionsResource(this.http);
1690
1852
  this.logs = new LogsResource(this.http);
1853
+ this.spans = new SpansResource(this.http);
1854
+ this.agents = new AgentsResource(this.http);
1691
1855
  this.storage = new StorageResource(this.http);
1692
1856
  this.health = new HealthResource(this.http);
1693
1857
  }