@rustrak/client 0.16.3 → 0.17.0

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
@@ -128,13 +128,24 @@ var alertRuleChannelInputSchema = z.object({
128
128
  integration_id: z.number().int(),
129
129
  routing_override: z.record(z.string(), z.unknown()).default({})
130
130
  });
131
+ var alertRuleConditionsSchema = z.object({
132
+ /** The quietest level that still fires. The server takes `null` as absent. */
133
+ min_level: z.enum(["debug", "info", "warning", "error", "fatal"]).nullish(),
134
+ /** When non-empty, the only environments that fire. */
135
+ environments: z.array(z.string()).optional(),
136
+ /** A new issue fires when it reaches this many events, not on its first. */
137
+ min_events: z.number().int().min(1).nullish()
138
+ });
131
139
  var alertRuleSchema = z.object({
132
140
  id: z.number().int(),
133
141
  project_id: z.number().int(),
134
142
  name: z.string(),
135
143
  alert_type: alertTypeSchema,
136
144
  is_enabled: z.boolean(),
137
- conditions: z.record(z.string(), z.unknown()),
145
+ // A rule stored before the filters existed may hold any object. The server
146
+ // evaluates one it cannot read as no filters; one bad row must not fail the
147
+ // whole list either.
148
+ conditions: alertRuleConditionsSchema.catch({}),
138
149
  cooldown_minutes: z.number().int(),
139
150
  last_triggered_at: dateTimeSchema.nullable(),
140
151
  created_at: dateTimeSchema,
@@ -147,13 +158,13 @@ var createAlertRuleSchema = z.object({
147
158
  alert_type: alertTypeSchema,
148
159
  channels: z.array(alertRuleChannelInputSchema).default([]),
149
160
  is_enabled: z.boolean().optional(),
150
- conditions: z.record(z.string(), z.unknown()).optional(),
161
+ conditions: alertRuleConditionsSchema.optional(),
151
162
  cooldown_minutes: z.number().int().min(0).optional()
152
163
  });
153
164
  var updateAlertRuleSchema = z.object({
154
165
  name: z.string().min(1).optional(),
155
166
  is_enabled: z.boolean().optional(),
156
- conditions: z.record(z.string(), z.unknown()).optional(),
167
+ conditions: alertRuleConditionsSchema.optional(),
157
168
  cooldown_minutes: z.number().int().min(0).optional(),
158
169
  channels: z.array(alertRuleChannelInputSchema).optional()
159
170
  });
@@ -225,6 +236,89 @@ var eventDetailSchema = z.object({
225
236
  data: z.record(z.string(), z.any())
226
237
  // Full Sentry event JSON
227
238
  });
239
+ var gitHubAppSchema = z.object({
240
+ app_id: z.number().int(),
241
+ slug: z.string(),
242
+ html_url: z.string(),
243
+ owner_login: z.string(),
244
+ install_url: z.string(),
245
+ last_webhook_at: dateTimeSchema.nullable(),
246
+ created_at: dateTimeSchema
247
+ });
248
+ var gitHubInstallationSchema = z.object({
249
+ id: z.number().int(),
250
+ account_login: z.string(),
251
+ account_type: z.string(),
252
+ suspended: z.boolean(),
253
+ created_at: dateTimeSchema
254
+ });
255
+ var gitHubStatusSchema = z.object({
256
+ app: gitHubAppSchema.nullable(),
257
+ installations: z.array(gitHubInstallationSchema),
258
+ webhook_url: z.string()
259
+ });
260
+ var gitHubManifestSchema = z.object({
261
+ action_url: z.string(),
262
+ manifest: z.string()
263
+ });
264
+ var gitHubRepositorySchema = z.object({
265
+ installation_id: z.number().int(),
266
+ full_name: z.string(),
267
+ default_branch: z.string(),
268
+ private: z.boolean(),
269
+ html_url: z.string()
270
+ });
271
+ var codeMappingSchema = z.object({
272
+ stack_root: z.string(),
273
+ source_root: z.string()
274
+ });
275
+ var projectRepositorySchema = z.object({
276
+ project_id: z.number().int(),
277
+ installation_id: z.number().int(),
278
+ repo_full_name: z.string(),
279
+ default_branch: z.string(),
280
+ html_url: z.string(),
281
+ code_mappings: z.array(codeMappingSchema),
282
+ /** Open a GitHub issue for new issues that pass `auto_create_conditions`. */
283
+ auto_create_issues: z.boolean(),
284
+ auto_create_conditions: alertRuleConditionsSchema,
285
+ codeowners_rules: z.number().int().nullable(),
286
+ codeowners_synced_at: dateTimeSchema.nullable()
287
+ });
288
+ var updateProjectRepositorySchema = z.object({
289
+ installation_id: z.number().int(),
290
+ repo_full_name: z.string().min(1),
291
+ code_mappings: z.array(codeMappingSchema).optional(),
292
+ auto_create_issues: z.boolean().optional(),
293
+ auto_create_conditions: alertRuleConditionsSchema.optional()
294
+ });
295
+ var issueLinkSchema = z.object({
296
+ id: z.number().int(),
297
+ issue_id: z.string(),
298
+ repo_full_name: z.string(),
299
+ number: z.number().int(),
300
+ title: z.string(),
301
+ url: z.string(),
302
+ state: z.string(),
303
+ created_at: dateTimeSchema
304
+ });
305
+ var repoCommitSchema = z.object({
306
+ repo_full_name: z.string(),
307
+ sha: z.string(),
308
+ message: z.string(),
309
+ author_name: z.string(),
310
+ author_login: z.string().nullable(),
311
+ url: z.string(),
312
+ committed_at: dateTimeSchema
313
+ });
314
+ var issueGitHubSchema = z.object({
315
+ links: z.array(issueLinkSchema),
316
+ suspect_commits: z.array(repoCommitSchema),
317
+ owners: z.array(z.string())
318
+ });
319
+ var gitHubLoginSchema = z.object({
320
+ login: z.string().nullable()
321
+ });
228
322
  var globalRoleSchema = z.enum(["admin", "member"]);
229
323
  var teamMemberSchema = z.object({
230
324
  id: z.number().int(),
@@ -1657,6 +1751,109 @@ var EventsResource = class extends BaseResource {
1657
1751
  );
1658
1752
  }
1659
1753
  };
1754
+
1755
+ // src/resources/github.ts
1756
+ var GitHubResource = class extends BaseResource {
1757
+ /** The app, its installations and the webhook address (admin only). */
1758
+ async status() {
1759
+ return this.request(() => this.http.get("api/github"), gitHubStatusSchema);
1760
+ }
1761
+ /** The form to post to GitHub to create the app, under an org if given. */
1762
+ async manifest(organization) {
1763
+ return this.request(
1764
+ () => this.http.post("api/github/manifest", { json: { organization } }),
1765
+ gitHubManifestSchema
1766
+ );
1767
+ }
1768
+ async disconnect() {
1769
+ return this.requestVoid(() => this.http.delete("api/github"));
1770
+ }
1771
+ /** Repositories the installations reach, for a project's settings. */
1772
+ async repositories(projectId) {
1773
+ return this.request(
1774
+ () => this.http.get("api/github/repositories", {
1775
+ searchParams: { project_id: projectId }
1776
+ }),
1777
+ gitHubRepositorySchema.array()
1778
+ );
1779
+ }
1780
+ async projectRepository(projectId) {
1781
+ return this.request(
1782
+ () => this.http.get(`api/projects/${projectId}/github`),
1783
+ projectRepositorySchema.nullable()
1784
+ );
1785
+ }
1786
+ async setProjectRepository(projectId, input) {
1787
+ const validated = this.validateInput(input, updateProjectRepositorySchema);
1788
+ if (!validated.success) {
1789
+ return validated;
1790
+ }
1791
+ return this.request(
1792
+ () => this.http.put(`api/projects/${projectId}/github`, {
1793
+ json: validated.data
1794
+ }),
1795
+ projectRepositorySchema
1796
+ );
1797
+ }
1798
+ async removeProjectRepository(projectId) {
1799
+ return this.requestVoid(
1800
+ () => this.http.delete(`api/projects/${projectId}/github`)
1801
+ );
1802
+ }
1803
+ /** Copies the repository's CODEOWNERS into Rustrak. */
1804
+ async syncCodeowners(projectId) {
1805
+ return this.request(
1806
+ () => this.http.post(`api/projects/${projectId}/github/codeowners`),
1807
+ projectRepositorySchema
1808
+ );
1809
+ }
1810
+ /** Links, suspect commits and owners for one issue. */
1811
+ async issue(projectId, issueId) {
1812
+ return this.request(
1813
+ () => this.http.get(`api/projects/${projectId}/issues/${issueId}/github`),
1814
+ issueGitHubSchema
1815
+ );
1816
+ }
1817
+ async createIssue(projectId, issueId, input = {}) {
1818
+ return this.request(
1819
+ () => this.http.post(
1820
+ `api/projects/${projectId}/issues/${issueId}/github/issues`,
1821
+ { json: input }
1822
+ ),
1823
+ issueLinkSchema
1824
+ );
1825
+ }
1826
+ /** `reference` is a GitHub URL, `owner/repo#12` or `#12`. */
1827
+ async linkIssue(projectId, issueId, reference) {
1828
+ return this.request(
1829
+ () => this.http.post(
1830
+ `api/projects/${projectId}/issues/${issueId}/github/links`,
1831
+ { json: { reference } }
1832
+ ),
1833
+ issueLinkSchema
1834
+ );
1835
+ }
1836
+ async unlinkIssue(projectId, issueId, linkId) {
1837
+ return this.requestVoid(
1838
+ () => this.http.delete(
1839
+ `api/projects/${projectId}/issues/${issueId}/github/links/${linkId}`
1840
+ )
1841
+ );
1842
+ }
1843
+ /** The signed-in person's GitHub username, used to sync assignees. */
1844
+ async myLogin() {
1845
+ return this.request(
1846
+ () => this.http.get("api/github/me"),
1847
+ gitHubLoginSchema
1848
+ );
1849
+ }
1850
+ async setMyLogin(login) {
1851
+ return this.request(
1852
+ () => this.http.put("api/github/me", { json: { login } }),
1853
+ gitHubLoginSchema
1854
+ );
1855
+ }
1856
+ };
1660
1857
  var serverVersionSchema = z.object({
1661
1858
  version: z.string()
1662
1859
  });
@@ -2695,6 +2892,10 @@ var RustrakClient = class {
2695
2892
  * Health API resource (version info)
2696
2893
  */
2697
2894
  health;
2895
+ /**
2896
+ * GitHub integration resource
2897
+ */
2898
+ github;
2698
2899
  /**
2699
2900
  * Create a new Rustrak API client
2700
2901
  *
@@ -2707,6 +2908,7 @@ var RustrakClient = class {
2707
2908
  this.issues = new IssuesResource(this.http);
2708
2909
  this.events = new EventsResource(this.http);
2709
2910
  this.tokens = new TokensResource(this.http);
2911
+ this.github = new GitHubResource(this.http);
2710
2912
  this.alertIntegrations = new AlertIntegrationsResource(this.http);
2711
2913
  this.alertRules = new AlertRulesResource(this.http);
2712
2914
  this.sourceMaps = new SourceMapsResource(this.http);