alchemy 0.16.4 → 0.16.6

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.
Files changed (42) hide show
  1. package/lib/cloudflare/bindings.d.ts +4 -1
  2. package/lib/cloudflare/bindings.d.ts.map +1 -1
  3. package/lib/cloudflare/bindings.js.map +1 -1
  4. package/lib/cloudflare/bound.d.ts +3 -2
  5. package/lib/cloudflare/bound.d.ts.map +1 -1
  6. package/lib/cloudflare/kv-namespace.js +1 -1
  7. package/lib/cloudflare/kv-namespace.js.map +1 -1
  8. package/lib/cloudflare/worker.js +1 -1
  9. package/lib/cloudflare/worker.js.map +1 -1
  10. package/lib/cloudflare/wrangler.json.js +1 -1
  11. package/lib/cloudflare/wrangler.json.js.map +1 -1
  12. package/lib/sentry/api.d.ts +50 -0
  13. package/lib/sentry/api.d.ts.map +1 -0
  14. package/lib/sentry/api.js +76 -0
  15. package/lib/sentry/api.js.map +1 -0
  16. package/lib/sentry/client-key.d.ts +156 -0
  17. package/lib/sentry/client-key.d.ts.map +1 -0
  18. package/lib/sentry/client-key.js +126 -0
  19. package/lib/sentry/client-key.js.map +1 -0
  20. package/lib/sentry/index.d.ts +5 -0
  21. package/lib/sentry/index.d.ts.map +1 -0
  22. package/lib/sentry/index.js +5 -0
  23. package/lib/sentry/index.js.map +1 -0
  24. package/lib/sentry/project.d.ts +235 -0
  25. package/lib/sentry/project.d.ts.map +1 -0
  26. package/lib/sentry/project.js +146 -0
  27. package/lib/sentry/project.js.map +1 -0
  28. package/lib/sentry/team.d.ts +109 -0
  29. package/lib/sentry/team.d.ts.map +1 -0
  30. package/lib/sentry/team.js +109 -0
  31. package/lib/sentry/team.js.map +1 -0
  32. package/package.json +2 -1
  33. package/src/cloudflare/bindings.ts +4 -0
  34. package/src/cloudflare/bound.ts +1 -2
  35. package/src/cloudflare/kv-namespace.ts +1 -1
  36. package/src/cloudflare/worker.ts +2 -1
  37. package/src/cloudflare/wrangler.json.ts +1 -1
  38. package/src/sentry/api.ts +106 -0
  39. package/src/sentry/client-key.ts +295 -0
  40. package/src/sentry/index.ts +4 -0
  41. package/src/sentry/project.ts +420 -0
  42. package/src/sentry/team.ts +235 -0
@@ -0,0 +1,420 @@
1
+ import type { Context } from "../context.js";
2
+ import { Resource } from "../resource.js";
3
+ import type { Secret } from "../secret.js";
4
+ import { SentryApi } from "./api.js";
5
+
6
+ /**
7
+ * Properties for creating or updating a Project
8
+ */
9
+ export interface ProjectProps {
10
+ /**
11
+ * The name for the project
12
+ */
13
+ name: string;
14
+
15
+ /**
16
+ * Uniquely identifies a project and is used for the interface
17
+ */
18
+ slug?: string;
19
+
20
+ /**
21
+ * The platform for the project
22
+ */
23
+ platform?: string;
24
+
25
+ /**
26
+ * Whether to alert on every new issue
27
+ */
28
+ defaultRules?: boolean;
29
+
30
+ /**
31
+ * The team slug that owns the project
32
+ */
33
+ team: string;
34
+
35
+ /**
36
+ * The organization ID or slug that owns the project
37
+ */
38
+ organization: string;
39
+
40
+ /**
41
+ * Auth token to use (overrides environment variable)
42
+ */
43
+ authToken?: Secret;
44
+
45
+ /**
46
+ * Whether to adopt an existing project with the same slug if it exists
47
+ * If true and a project with the same slug exists, it will be adopted rather than creating a new one
48
+ *
49
+ * @default false
50
+ */
51
+ adopt?: boolean;
52
+ }
53
+
54
+ /**
55
+ * Output returned after Project creation/update
56
+ */
57
+ export interface Project
58
+ extends Omit<Resource<"sentry::Project">, "team">,
59
+ Omit<ProjectProps, "team"> {
60
+ /**
61
+ * The ID of the project
62
+ */
63
+ id: string;
64
+
65
+ /**
66
+ * The team that owns the project
67
+ */
68
+ team: {
69
+ id: string;
70
+ name: string;
71
+ slug: string;
72
+ };
73
+
74
+ /**
75
+ * All teams that have access to the project
76
+ */
77
+ teams: Array<{
78
+ id: string;
79
+ name: string;
80
+ slug: string;
81
+ }>;
82
+
83
+ /**
84
+ * Whether the project is bookmarked
85
+ */
86
+ isBookmarked: boolean;
87
+
88
+ /**
89
+ * Whether the current user is a member of the project
90
+ */
91
+ isMember: boolean;
92
+
93
+ /**
94
+ * Access permissions for the project
95
+ */
96
+ access: string[];
97
+
98
+ /**
99
+ * Whether the current user has access to the project
100
+ */
101
+ hasAccess: boolean;
102
+
103
+ /**
104
+ * Time at which the project was created
105
+ */
106
+ dateCreated: string;
107
+
108
+ /**
109
+ * List of environments in the project
110
+ */
111
+ environments: string[];
112
+
113
+ /**
114
+ * Event processing status
115
+ */
116
+ eventProcessing: {
117
+ symbolicationDegraded: boolean;
118
+ };
119
+
120
+ /**
121
+ * List of features enabled for the project
122
+ */
123
+ features: string[];
124
+
125
+ /**
126
+ * Whether the project has received its first event
127
+ */
128
+ firstEvent: string | null;
129
+
130
+ /**
131
+ * Whether the project has received its first transaction event
132
+ */
133
+ firstTransactionEvent: boolean;
134
+
135
+ /**
136
+ * Whether the project has sessions
137
+ */
138
+ hasSessions: boolean;
139
+
140
+ /**
141
+ * Whether the project has profiles
142
+ */
143
+ hasProfiles: boolean;
144
+
145
+ /**
146
+ * Whether the project has replays
147
+ */
148
+ hasReplays: boolean;
149
+
150
+ /**
151
+ * Whether the project has flags
152
+ */
153
+ hasFlags: boolean;
154
+
155
+ /**
156
+ * Whether the project has monitors
157
+ */
158
+ hasMonitors: boolean;
159
+
160
+ /**
161
+ * Whether the project has feedback
162
+ */
163
+ hasFeedbacks: boolean;
164
+
165
+ /**
166
+ * Whether the project has new feedback
167
+ */
168
+ hasNewFeedbacks: boolean;
169
+
170
+ /**
171
+ * Whether the project has minified stack traces
172
+ */
173
+ hasMinifiedStackTrace: boolean;
174
+
175
+ /**
176
+ * Whether the project has HTTP insights
177
+ */
178
+ hasInsightsHttp: boolean;
179
+
180
+ /**
181
+ * Whether the project has database insights
182
+ */
183
+ hasInsightsDb: boolean;
184
+
185
+ /**
186
+ * Whether the project has asset insights
187
+ */
188
+ hasInsightsAssets: boolean;
189
+
190
+ /**
191
+ * Whether the project has app start insights
192
+ */
193
+ hasInsightsAppStart: boolean;
194
+
195
+ /**
196
+ * Whether the project has screen load insights
197
+ */
198
+ hasInsightsScreenLoad: boolean;
199
+
200
+ /**
201
+ * Whether the project has vitals insights
202
+ */
203
+ hasInsightsVitals: boolean;
204
+
205
+ /**
206
+ * Whether the project has cache insights
207
+ */
208
+ hasInsightsCaches: boolean;
209
+
210
+ /**
211
+ * Whether the project has queue insights
212
+ */
213
+ hasInsightsQueues: boolean;
214
+
215
+ /**
216
+ * Whether the project has LLM monitoring
217
+ */
218
+ hasInsightsLlmMonitoring: boolean;
219
+
220
+ /**
221
+ * List of platforms in the project
222
+ */
223
+ platforms: string[];
224
+
225
+ /**
226
+ * Latest release information
227
+ */
228
+ latestRelease: string | null;
229
+
230
+ /**
231
+ * Whether the project has user reports
232
+ */
233
+ hasUserReports: boolean;
234
+
235
+ /**
236
+ * Latest deployment information
237
+ */
238
+ latestDeploys: string | null;
239
+ }
240
+
241
+ /**
242
+ * Create and manage Sentry projects
243
+ *
244
+ * @example
245
+ * // Create a basic Sentry project:
246
+ * const project = await Project("my-project", {
247
+ * name: "My Project",
248
+ * team: "my-team",
249
+ * organization: "my-org"
250
+ * });
251
+ *
252
+ * @example
253
+ * // Create a project for a specific platform:
254
+ * const project = await Project("js-project", {
255
+ * name: "JavaScript Project",
256
+ * team: "my-team",
257
+ * organization: "my-org",
258
+ * platform: "javascript"
259
+ * });
260
+ *
261
+ * @example
262
+ * // Create a project with a custom slug and disabled default rules:
263
+ * const project = await Project("custom-project", {
264
+ * name: "Custom Project",
265
+ * team: "my-team",
266
+ * organization: "my-org",
267
+ * slug: "custom-project-slug",
268
+ * defaultRules: false
269
+ * });
270
+ *
271
+ * @example
272
+ * // Create or adopt an existing project with the same slug:
273
+ * const project = await Project("existing-project", {
274
+ * name: "Existing Project",
275
+ * team: "my-team",
276
+ * organization: "my-org",
277
+ * adopt: true
278
+ * });
279
+ */
280
+ export const Project = Resource(
281
+ "sentry::Project",
282
+ async function (
283
+ this: Context<Project>,
284
+ id: string,
285
+ props: ProjectProps,
286
+ ): Promise<Project> {
287
+ const api = new SentryApi({ authToken: props.authToken });
288
+
289
+ if (this.phase === "delete") {
290
+ try {
291
+ if (this.output?.id) {
292
+ const response = await api.delete(
293
+ `/projects/${props.organization}/${this.output.slug || this.output.id}/`,
294
+ );
295
+ if (!response.ok && response.status !== 404) {
296
+ console.error("Error deleting project:", response.statusText);
297
+ }
298
+ }
299
+ } catch (error) {
300
+ console.error("Error deleting project:", error);
301
+ }
302
+ return this.destroy();
303
+ } else {
304
+ try {
305
+ let response;
306
+
307
+ if (this.phase === "update" && this.output?.id) {
308
+ response = await api.put(
309
+ `/projects/${props.organization}/${this.output.slug || this.output.id}/`,
310
+ props,
311
+ );
312
+ } else {
313
+ try {
314
+ response = await api.post(
315
+ `/teams/${props.organization}/${props.team}/projects/`,
316
+ props,
317
+ );
318
+ } catch (error) {
319
+ // Check if this is a "project already exists" error and adopt is enabled
320
+ if (
321
+ props.adopt &&
322
+ error instanceof Error &&
323
+ error.message.includes("already exists")
324
+ ) {
325
+ console.log(
326
+ `Project '${props.slug || props.name}' already exists, adopting it`,
327
+ );
328
+ // Find the existing project by slug
329
+ const existingProject = await findProjectBySlug(
330
+ api,
331
+ props.organization,
332
+ props.slug || props.name,
333
+ );
334
+ if (!existingProject) {
335
+ throw new Error(
336
+ `Failed to find existing project '${props.slug || props.name}' for adoption`,
337
+ );
338
+ }
339
+ response = await api.get(
340
+ `/projects/${props.organization}/${existingProject.slug}/`,
341
+ );
342
+ } else {
343
+ throw error;
344
+ }
345
+ }
346
+ }
347
+
348
+ if (!response.ok) {
349
+ throw new Error(`API error: ${response.statusText}`);
350
+ }
351
+
352
+ const data = (await response.json()) as Omit<
353
+ Project,
354
+ keyof ProjectProps
355
+ > & { team: Project["team"] };
356
+ return this({
357
+ ...props,
358
+ id: data.id,
359
+ team: data.team,
360
+ teams: data.teams,
361
+ isBookmarked: data.isBookmarked,
362
+ isMember: data.isMember,
363
+ access: data.access,
364
+ hasAccess: data.hasAccess,
365
+ dateCreated: data.dateCreated,
366
+ environments: data.environments,
367
+ eventProcessing: data.eventProcessing,
368
+ features: data.features,
369
+ firstEvent: data.firstEvent,
370
+ firstTransactionEvent: data.firstTransactionEvent,
371
+ hasSessions: data.hasSessions,
372
+ hasProfiles: data.hasProfiles,
373
+ hasReplays: data.hasReplays,
374
+ hasFlags: data.hasFlags,
375
+ hasMonitors: data.hasMonitors,
376
+ hasFeedbacks: data.hasFeedbacks,
377
+ hasNewFeedbacks: data.hasNewFeedbacks,
378
+ hasMinifiedStackTrace: data.hasMinifiedStackTrace,
379
+ hasInsightsHttp: data.hasInsightsHttp,
380
+ hasInsightsDb: data.hasInsightsDb,
381
+ hasInsightsAssets: data.hasInsightsAssets,
382
+ hasInsightsAppStart: data.hasInsightsAppStart,
383
+ hasInsightsScreenLoad: data.hasInsightsScreenLoad,
384
+ hasInsightsVitals: data.hasInsightsVitals,
385
+ hasInsightsCaches: data.hasInsightsCaches,
386
+ hasInsightsQueues: data.hasInsightsQueues,
387
+ hasInsightsLlmMonitoring: data.hasInsightsLlmMonitoring,
388
+ platforms: data.platforms,
389
+ latestRelease: data.latestRelease,
390
+ hasUserReports: data.hasUserReports,
391
+ latestDeploys: data.latestDeploys,
392
+ });
393
+ } catch (error) {
394
+ console.error("Error creating/updating project:", error);
395
+ throw error;
396
+ }
397
+ }
398
+ },
399
+ );
400
+
401
+ /**
402
+ * Find a project by slug
403
+ */
404
+ async function findProjectBySlug(
405
+ api: SentryApi,
406
+ organization: string,
407
+ slug: string,
408
+ ): Promise<{ id: string; slug: string } | null> {
409
+ const response = await api.get(`/projects/${organization}`);
410
+ if (!response.ok) {
411
+ throw new Error(`API error: ${response.statusText}`);
412
+ }
413
+
414
+ const projects = (await response.json()) as Array<{
415
+ id: string;
416
+ slug: string;
417
+ }>;
418
+ const project = projects.find((p) => p.slug === slug);
419
+ return project ? { id: project.id, slug: project.slug } : null;
420
+ }
@@ -0,0 +1,235 @@
1
+ import type { Context } from "../context.js";
2
+ import { Resource } from "../resource.js";
3
+ import type { Secret } from "../secret.js";
4
+ import { SentryApi } from "./api.js";
5
+
6
+ /**
7
+ * Properties for creating or updating a Team
8
+ */
9
+ export interface TeamProps {
10
+ /**
11
+ * The name for the team
12
+ */
13
+ name: string;
14
+
15
+ /**
16
+ * Uniquely identifies a team and is used for the interface
17
+ */
18
+ slug?: string;
19
+
20
+ /**
21
+ * The organization ID or slug that owns the team
22
+ */
23
+ organization: string;
24
+
25
+ /**
26
+ * Auth token to use (overrides environment variable)
27
+ */
28
+ authToken?: Secret;
29
+
30
+ /**
31
+ * Whether to adopt an existing team with the same slug if it exists
32
+ * If true and a team with the same slug exists, it will be adopted rather than creating a new one
33
+ *
34
+ * @default false
35
+ */
36
+ adopt?: boolean;
37
+ }
38
+
39
+ /**
40
+ * Output returned after Team creation/update
41
+ */
42
+ export interface Team extends Resource<"sentry::Team">, TeamProps {
43
+ /**
44
+ * The ID of the team
45
+ */
46
+ id: string;
47
+
48
+ /**
49
+ * Time at which the team was created
50
+ */
51
+ dateCreated: string;
52
+
53
+ /**
54
+ * Whether the current user is a member of the team
55
+ */
56
+ isMember: boolean;
57
+
58
+ /**
59
+ * The role of the current user in the team
60
+ */
61
+ teamRole: string;
62
+
63
+ /**
64
+ * Team flags
65
+ */
66
+ flags: {
67
+ "idp:provisioned": boolean;
68
+ };
69
+
70
+ /**
71
+ * Access permissions for the team
72
+ */
73
+ access: string[];
74
+
75
+ /**
76
+ * Whether the current user has access to the team
77
+ */
78
+ hasAccess: boolean;
79
+
80
+ /**
81
+ * Whether the team membership is pending
82
+ */
83
+ isPending: boolean;
84
+
85
+ /**
86
+ * Number of members in the team
87
+ */
88
+ memberCount: number;
89
+
90
+ /**
91
+ * Team avatar information
92
+ */
93
+ avatar: {
94
+ avatarType: string;
95
+ avatarUuid: string | null;
96
+ };
97
+ }
98
+
99
+ /**
100
+ * Create and manage Sentry teams
101
+ *
102
+ * @example
103
+ * // Create a basic Sentry team:
104
+ * const team = await Team("my-team", {
105
+ * name: "My Team",
106
+ * organization: "my-org"
107
+ * });
108
+ *
109
+ * @example
110
+ * // Create a team with a custom slug:
111
+ * const team = await Team("custom-team", {
112
+ * name: "Custom Team",
113
+ * organization: "my-org",
114
+ * slug: "custom-team-slug"
115
+ * });
116
+ *
117
+ * @example
118
+ * // Create or adopt an existing team with the same slug:
119
+ * const team = await Team("existing-team", {
120
+ * name: "Existing Team",
121
+ * organization: "my-org",
122
+ * adopt: true
123
+ * });
124
+ */
125
+ export const Team = Resource(
126
+ "sentry::Team",
127
+ async function (
128
+ this: Context<Team>,
129
+ id: string,
130
+ props: TeamProps,
131
+ ): Promise<Team> {
132
+ const api = new SentryApi({ authToken: props.authToken });
133
+
134
+ if (this.phase === "delete") {
135
+ try {
136
+ if (this.output?.id) {
137
+ const response = await api.delete(
138
+ `/teams/${props.organization}/${this.output.slug || this.output.id}/`,
139
+ );
140
+ if (!response.ok && response.status !== 404) {
141
+ console.error("Error deleting team:", response.statusText);
142
+ }
143
+ }
144
+ } catch (error) {
145
+ console.error("Error deleting team:", error);
146
+ }
147
+ return this.destroy();
148
+ } else {
149
+ try {
150
+ let response;
151
+
152
+ if (this.phase === "update" && this.output?.id) {
153
+ response = await api.put(
154
+ `/teams/${props.organization}/${this.output.slug || this.output.id}/`,
155
+ props,
156
+ );
157
+ } else {
158
+ try {
159
+ response = await api.post(
160
+ `/organizations/${props.organization}/teams/`,
161
+ props,
162
+ );
163
+ } catch (error) {
164
+ // Check if this is a "team already exists" error and adopt is enabled
165
+ if (
166
+ props.adopt &&
167
+ error instanceof Error &&
168
+ error.message.includes("already exists")
169
+ ) {
170
+ console.log(
171
+ `Team '${props.slug || props.name}' already exists, adopting it`,
172
+ );
173
+ // Find the existing team by slug
174
+ const existingTeam = await findTeamBySlug(
175
+ api,
176
+ props.organization,
177
+ props.slug || props.name,
178
+ );
179
+ if (!existingTeam) {
180
+ throw new Error(
181
+ `Failed to find existing team '${props.slug || props.name}' for adoption`,
182
+ );
183
+ }
184
+ response = await api.get(
185
+ `/organizations/${props.organization}/teams/${existingTeam.slug}/`,
186
+ );
187
+ } else {
188
+ throw error;
189
+ }
190
+ }
191
+ }
192
+
193
+ if (!response.ok) {
194
+ throw new Error(`API error: ${response.statusText}`);
195
+ }
196
+
197
+ const data = (await response.json()) as Omit<Team, keyof TeamProps>;
198
+ return this({
199
+ ...props,
200
+ id: data.id,
201
+ dateCreated: data.dateCreated,
202
+ isMember: data.isMember,
203
+ teamRole: data.teamRole,
204
+ flags: data.flags,
205
+ access: data.access,
206
+ hasAccess: data.hasAccess,
207
+ isPending: data.isPending,
208
+ memberCount: data.memberCount,
209
+ avatar: data.avatar,
210
+ });
211
+ } catch (error) {
212
+ console.error("Error creating/updating team:", error);
213
+ throw error;
214
+ }
215
+ }
216
+ },
217
+ );
218
+
219
+ /**
220
+ * Find a team by slug
221
+ */
222
+ async function findTeamBySlug(
223
+ api: SentryApi,
224
+ organization: string,
225
+ slug: string,
226
+ ): Promise<{ id: string; slug: string } | null> {
227
+ const response = await api.get(`/teams/${organization}/${slug}/`);
228
+ if (!response.ok) {
229
+ throw new Error(`API error: ${response.statusText}`);
230
+ }
231
+
232
+ const teams = (await response.json()) as Array<{ id: string; slug: string }>;
233
+ const team = teams.find((t) => t.slug === slug);
234
+ return team ? { id: team.id, slug: team.slug } : null;
235
+ }