@rustrak/client 0.17.0 → 0.18.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/dist/index.js CHANGED
@@ -502,6 +502,96 @@ var upsertProjectMemberSchema = z.object({
502
502
  user_id: z.number().int(),
503
503
  role: projectRoleSchema
504
504
  });
505
+ var intervalUnitSchema = z.enum([
506
+ "minute",
507
+ "hour",
508
+ "day",
509
+ "week",
510
+ "month",
511
+ "year"
512
+ ]);
513
+ var scheduleSchema = z.discriminatedUnion("type", [
514
+ z.object({ type: z.literal("crontab"), value: z.string() }),
515
+ z.object({
516
+ type: z.literal("interval"),
517
+ value: z.number().int().min(1),
518
+ unit: intervalUnitSchema
519
+ })
520
+ ]);
521
+ var previewScheduleSchema = z.object({
522
+ schedule: scheduleSchema,
523
+ /** IANA zone the schedule is read in. Defaults to UTC. */
524
+ timezone: z.string().optional()
525
+ });
526
+ var schedulePreviewSchema = z.object({
527
+ next_runs: z.array(dateTimeSchema)
528
+ });
529
+
530
+ // src/schemas/monitor.ts
531
+ var monitorConfigSchema = z.object({
532
+ schedule: scheduleSchema,
533
+ checkin_margin: z.number().int(),
534
+ max_runtime: z.number().int(),
535
+ timezone: z.string(),
536
+ failure_issue_threshold: z.number().int(),
537
+ recovery_threshold: z.number().int()
538
+ });
539
+ var monitorConfigInputSchema = z.object({
540
+ schedule: scheduleSchema.optional(),
541
+ checkin_margin: z.number().int().min(1).optional(),
542
+ max_runtime: z.number().int().min(1).optional(),
543
+ timezone: z.string().optional(),
544
+ failure_issue_threshold: z.number().int().min(1).max(720).optional(),
545
+ recovery_threshold: z.number().int().min(1).max(720).optional()
546
+ });
547
+ var checkInStatusSchema = z.enum([
548
+ "ok",
549
+ "error",
550
+ "in_progress",
551
+ "missed",
552
+ "timeout",
553
+ "unknown"
554
+ ]);
555
+ var monitorEnvironmentStatusSchema = z.enum(["active", "ok", "error"]);
556
+ var checkInSchema = z.object({
557
+ id: uuidSchema,
558
+ environment: z.string(),
559
+ status: checkInStatusSchema,
560
+ duration_ms: z.number().int().nullable(),
561
+ date_added: dateTimeSchema,
562
+ date_updated: dateTimeSchema,
563
+ expected_time: dateTimeSchema.nullable()
564
+ });
565
+ var monitorEnvironmentSchema = z.object({
566
+ id: uuidSchema,
567
+ environment: z.string(),
568
+ status: monitorEnvironmentStatusSchema,
569
+ next_checkin: dateTimeSchema.nullable(),
570
+ next_checkin_latest: dateTimeSchema.nullable(),
571
+ last_checkin: dateTimeSchema.nullable(),
572
+ /** Newest first. */
573
+ recent_checkins: z.array(checkInSchema)
574
+ });
575
+ var monitorSchema = z.object({
576
+ id: uuidSchema,
577
+ slug: z.string(),
578
+ name: z.string(),
579
+ config: monitorConfigSchema,
580
+ is_muted: z.boolean(),
581
+ created_at: dateTimeSchema,
582
+ environments: z.array(monitorEnvironmentSchema)
583
+ });
584
+ var createMonitorSchema = z.object({
585
+ name: z.string().trim().min(1).max(128),
586
+ /** Derived from `name` when left out. */
587
+ slug: z.string().min(1).max(50).optional(),
588
+ config: monitorConfigInputSchema
589
+ });
590
+ var updateMonitorSchema = z.object({
591
+ name: z.string().trim().min(1).max(128).optional(),
592
+ config: monitorConfigInputSchema.optional(),
593
+ is_muted: z.boolean().optional()
594
+ });
505
595
  var metricDeltaSchema = z.object({
506
596
  current: z.number().int(),
507
597
  /**
@@ -674,14 +764,21 @@ var projectStorageSchema = z.object({
674
764
  spans_count: z.number(),
675
765
  logs_count: z.number(),
676
766
  source_maps_count: z.number(),
677
- estimated_bytes: z.number()
767
+ /** `events_bytes + transactions_bytes + logs_bytes`. */
768
+ estimated_bytes: z.number(),
769
+ events_bytes: z.number(),
770
+ /** Transactions with their spans. */
771
+ transactions_bytes: z.number(),
772
+ logs_bytes: z.number()
678
773
  });
679
774
  var cleanupCountsSchema = z.object({
680
775
  events: z.number(),
681
776
  transactions: z.number(),
682
777
  spans: z.number(),
683
778
  logs: z.number(),
684
- issues_removed: z.number()
779
+ issues_removed: z.number(),
780
+ /** Unused source maps deleted; only a retention cleanup removes them. */
781
+ source_maps: z.number().default(0)
685
782
  });
686
783
  var cleanupStatusSchema = z.object({
687
784
  state: z.enum(["idle", "running", "completed", "failed"]),
@@ -694,6 +791,53 @@ var sourceMapGcResultSchema = z.object({
694
791
  files_removed: z.number(),
695
792
  bytes_freed: z.number()
696
793
  });
794
+ var kindAgeSchema = z.object({
795
+ counts: z.array(z.number()),
796
+ oldest: dateTimeSchema.nullable()
797
+ });
798
+ var storageAgeSchema = z.object({
799
+ bucket_days: z.array(z.number()),
800
+ projects: z.array(
801
+ z.object({
802
+ project_id: z.number(),
803
+ events: kindAgeSchema,
804
+ transactions: kindAgeSchema,
805
+ logs: kindAgeSchema
806
+ })
807
+ )
808
+ });
809
+ var retentionDaysSchema = z.number().int().min(1).max(36500).nullable();
810
+ var retentionWindowsSchema = z.object({
811
+ events_days: retentionDaysSchema,
812
+ /** Transactions with their spans. */
813
+ transactions_days: retentionDaysSchema,
814
+ logs_days: retentionDaysSchema
815
+ });
816
+ var projectRetentionSchema = retentionWindowsSchema.extend({
817
+ project_id: z.number().int()
818
+ });
819
+ var retentionSettingsSchema = z.object({
820
+ defaults: retentionWindowsSchema,
821
+ overrides: z.array(projectRetentionSchema),
822
+ frequency: z.enum(["daily", "weekly"]),
823
+ /** Hour of the day, UTC. */
824
+ hour: z.number().int().min(0).max(23),
825
+ /** Day of a weekly cleanup, 0 = Sunday. */
826
+ weekday: z.number().int().min(0).max(6)
827
+ });
828
+ var retentionRunSchema = z.object({
829
+ started_at: dateTimeSchema,
830
+ finished_at: dateTimeSchema.nullable(),
831
+ status: z.enum(["running", "ok", "error"]),
832
+ removed: cleanupCountsSchema.nullable(),
833
+ error: z.string().nullable()
834
+ });
835
+ var retentionSchema = z.object({
836
+ settings: retentionSettingsSchema,
837
+ /** Null while everything is kept forever, and for up to a minute after the settings change. */
838
+ next_run_at: dateTimeSchema.nullable(),
839
+ last_run: retentionRunSchema.nullable()
840
+ });
697
841
  var cleanupOptionsSchema = z.object({
698
842
  older_than_days: z.number().int().min(1),
699
843
  project_id: z.number().int().optional(),
@@ -2200,6 +2344,77 @@ var MembersResource = class extends BaseResource {
2200
2344
  );
2201
2345
  }
2202
2346
  };
2347
+ var MonitorsResource = class extends BaseResource {
2348
+ /** Every monitor of a project, with its environments and recent check-ins. */
2349
+ async list(projectId) {
2350
+ return this.request(
2351
+ () => this.http.get(`api/projects/${projectId}/monitors`),
2352
+ z.array(monitorSchema)
2353
+ );
2354
+ }
2355
+ async get(projectId, slug) {
2356
+ return this.request(
2357
+ () => this.http.get(
2358
+ `api/projects/${projectId}/monitors/${encodeURIComponent(slug)}`
2359
+ ),
2360
+ monitorSchema
2361
+ );
2362
+ }
2363
+ async create(projectId, input) {
2364
+ const validated = this.validateInput(input, createMonitorSchema);
2365
+ if (!validated.success) {
2366
+ return validated;
2367
+ }
2368
+ return this.request(
2369
+ () => this.http.post(`api/projects/${projectId}/monitors`, {
2370
+ json: validated.data
2371
+ }),
2372
+ monitorSchema
2373
+ );
2374
+ }
2375
+ /** Fields left out keep their value, including each field of `config`. */
2376
+ async update(projectId, slug, input) {
2377
+ const validated = this.validateInput(input, updateMonitorSchema);
2378
+ if (!validated.success) {
2379
+ return validated;
2380
+ }
2381
+ return this.request(
2382
+ () => this.http.put(
2383
+ `api/projects/${projectId}/monitors/${encodeURIComponent(slug)}`,
2384
+ { json: validated.data }
2385
+ ),
2386
+ monitorSchema
2387
+ );
2388
+ }
2389
+ /** Deletes the monitor and its check-ins. Its issues stay. */
2390
+ async delete(projectId, slug) {
2391
+ return this.requestVoid(
2392
+ () => this.http.delete(
2393
+ `api/projects/${projectId}/monitors/${encodeURIComponent(slug)}`
2394
+ )
2395
+ );
2396
+ }
2397
+ /** Check-ins of one monitor, newest first. */
2398
+ async listCheckIns(projectId, slug, options) {
2399
+ const searchParams = {};
2400
+ if (options?.page) {
2401
+ searchParams.page = String(options.page);
2402
+ }
2403
+ if (options?.per_page) {
2404
+ searchParams.per_page = String(options.per_page);
2405
+ }
2406
+ if (options?.environment) {
2407
+ searchParams.environment = options.environment;
2408
+ }
2409
+ return this.request(
2410
+ () => this.http.get(
2411
+ `api/projects/${projectId}/monitors/${encodeURIComponent(slug)}/checkins`,
2412
+ { searchParams }
2413
+ ),
2414
+ offsetPaginatedResponseSchema(checkInSchema)
2415
+ );
2416
+ }
2417
+ };
2203
2418
 
2204
2419
  // src/resources/projects.ts
2205
2420
  var ProjectsResource = class extends BaseResource {
@@ -2301,6 +2516,21 @@ var ReleasesResource = class extends BaseResource {
2301
2516
  }
2302
2517
  };
2303
2518
 
2519
+ // src/resources/schedules.ts
2520
+ var SchedulesResource = class extends BaseResource {
2521
+ /** Validates a schedule and lists its next five runs. */
2522
+ async preview(input) {
2523
+ const validated = this.validateInput(input, previewScheduleSchema);
2524
+ if (!validated.success) {
2525
+ return validated;
2526
+ }
2527
+ return this.request(
2528
+ () => this.http.post("api/schedules/preview", { json: validated.data }),
2529
+ schedulePreviewSchema
2530
+ );
2531
+ }
2532
+ };
2533
+
2304
2534
  // src/resources/sessions.ts
2305
2535
  var SessionsResource = class extends BaseResource {
2306
2536
  /**
@@ -2633,6 +2863,66 @@ var StorageResource = class extends BaseResource {
2633
2863
  sourceMapGcResultSchema
2634
2864
  );
2635
2865
  }
2866
+ /**
2867
+ * Retention: how long each kind of data is kept, by default and per
2868
+ * project, when its cleanup runs next and how the last one went.
2869
+ */
2870
+ async getRetention() {
2871
+ return this.request(
2872
+ () => this.http.get("api/storage/retention"),
2873
+ retentionSchema
2874
+ );
2875
+ }
2876
+ /** Replaces the retention settings. A new schedule applies within a minute. */
2877
+ async updateRetention(settings) {
2878
+ const validated = this.validateInput(settings, retentionSettingsSchema);
2879
+ if (!validated.success) {
2880
+ return validated;
2881
+ }
2882
+ return this.request(
2883
+ () => this.http.put("api/storage/retention", { json: validated.data }),
2884
+ retentionSchema
2885
+ );
2886
+ }
2887
+ /**
2888
+ * Enforces the saved retention now, without waiting for the schedule, and
2889
+ * deletes unused source maps. Returns the started job; follow it with
2890
+ * {@link getCleanupStatus}. A `validation` error while everything is kept
2891
+ * forever, `conflict` while a cleanup runs.
2892
+ */
2893
+ async runRetention() {
2894
+ return this.request(
2895
+ () => this.http.post("api/storage/retention/run", {
2896
+ // No retry, as for `executeCleanup`: a lost response after the
2897
+ // cleanup started would be retried into a refused second run.
2898
+ retry: 0
2899
+ }),
2900
+ cleanupStatusSchema
2901
+ );
2902
+ }
2903
+ /** How long ago each project's data arrived, per kind, in age buckets. */
2904
+ async getAge() {
2905
+ return this.request(
2906
+ () => this.http.get("api/storage/age"),
2907
+ storageAgeSchema
2908
+ );
2909
+ }
2910
+ /**
2911
+ * Dry-run: what enforcing these retention settings now would delete, each
2912
+ * project against its own windows. Saves and deletes nothing.
2913
+ */
2914
+ async previewRetention(settings) {
2915
+ const validated = this.validateInput(settings, retentionSettingsSchema);
2916
+ if (!validated.success) {
2917
+ return validated;
2918
+ }
2919
+ return this.request(
2920
+ () => this.http.post("api/storage/retention/preview", {
2921
+ json: validated.data
2922
+ }),
2923
+ cleanupCountsSchema
2924
+ );
2925
+ }
2636
2926
  };
2637
2927
 
2638
2928
  // src/resources/team.ts
@@ -2872,6 +3162,14 @@ var RustrakClient = class {
2872
3162
  * Logs API resource (standalone logs)
2873
3163
  */
2874
3164
  logs;
3165
+ /**
3166
+ * Cron monitors API resource (Sentry Crons)
3167
+ */
3168
+ monitors;
3169
+ /**
3170
+ * Schedules API resource (previews for crontab/interval schedules)
3171
+ */
3172
+ schedules;
2875
3173
  /**
2876
3174
  * Spans API resource (standalone + transaction-embedded spans, shared table)
2877
3175
  */
@@ -2919,6 +3217,8 @@ var RustrakClient = class {
2919
3217
  this.releases = new ReleasesResource(this.http);
2920
3218
  this.transactions = new TransactionsResource(this.http);
2921
3219
  this.logs = new LogsResource(this.http);
3220
+ this.monitors = new MonitorsResource(this.http);
3221
+ this.schedules = new SchedulesResource(this.http);
2922
3222
  this.spans = new SpansResource(this.http);
2923
3223
  this.agents = new AgentsResource(this.http);
2924
3224
  this.stats = new StatsResource(this.http);