@terrantula/sdk 0.0.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/local.js ADDED
@@ -0,0 +1,1549 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/local.ts
21
+ var local_exports = {};
22
+ __export(local_exports, {
23
+ createLocalClient: () => createLocalClient
24
+ });
25
+ module.exports = __toCommonJS(local_exports);
26
+
27
+ // src/index.ts
28
+ var import_client4 = require("hono/client");
29
+ var import_hono = require("hono");
30
+
31
+ // src/helpers.ts
32
+ function fallbackMessage(status) {
33
+ return `Request failed with status ${status}`;
34
+ }
35
+ var TerrantulaError = class extends Error {
36
+ constructor(status, body) {
37
+ const message = body != null && typeof body === "object" && "error" in body ? String(body.error) : fallbackMessage(status);
38
+ super(message);
39
+ this.status = status;
40
+ this.body = body;
41
+ this.name = "TerrantulaError";
42
+ }
43
+ status;
44
+ body;
45
+ };
46
+ function withSchema(schema, fn) {
47
+ return Object.assign(fn, { schema });
48
+ }
49
+ async function call(p) {
50
+ const res = await p;
51
+ const body = await res.json().catch(() => ({}));
52
+ if (!res.ok) throw new TerrantulaError(res.status, body);
53
+ return body;
54
+ }
55
+ var buildHeaders = (token) => {
56
+ if (!token) return {};
57
+ if (typeof token === "function")
58
+ return async () => ({ Authorization: `Bearer ${await token()}` });
59
+ return { Authorization: `Bearer ${token}` };
60
+ };
61
+ function stringifyQuery(params) {
62
+ return Object.fromEntries(
63
+ Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => [k, String(v)])
64
+ );
65
+ }
66
+
67
+ // src/orgs.ts
68
+ var import_zod = require("zod");
69
+ async function personalTokensRequest(baseUrl, hcOpts, path, init = {}) {
70
+ const fetchImpl = hcOpts?.fetch ?? fetch;
71
+ const rawHeaders = hcOpts?.headers;
72
+ const resolvedHeaders = typeof rawHeaders === "function" ? await rawHeaders() : rawHeaders ?? {};
73
+ return fetchImpl(`${baseUrl}${path}`, {
74
+ ...init,
75
+ // why: RequestInit['headers'] is HeadersInit (a union); we narrow to Record<string,string> after the static-record check above.
76
+ headers: { ...resolvedHeaders, ...init.headers }
77
+ });
78
+ }
79
+ async function callPersonalTokens(res) {
80
+ if (!res.ok) {
81
+ let message = fallbackMessage(res.status);
82
+ try {
83
+ const body = await res.json();
84
+ if (body.error) message = body.error;
85
+ } catch {
86
+ }
87
+ throw new TerrantulaError(res.status, { error: message });
88
+ }
89
+ return res.json();
90
+ }
91
+ function createOrgsClient(cloud, baseUrl, hcOpts) {
92
+ return {
93
+ create: withSchema(
94
+ import_zod.z.object({
95
+ name: import_zod.z.string().describe("Display name"),
96
+ slug: import_zod.z.string().describe("URL slug (lowercase, hyphens only)")
97
+ }),
98
+ (params) => call(cloud.orgs.$post({ json: params }))
99
+ ),
100
+ get: withSchema(
101
+ import_zod.z.object({
102
+ id: import_zod.z.string().describe("Organization ID")
103
+ }),
104
+ (params) => call(cloud.orgs[":id"].$get({ param: params }))
105
+ ),
106
+ listUsers: withSchema(
107
+ import_zod.z.object({
108
+ id: import_zod.z.string().describe("Organization ID")
109
+ }),
110
+ (params) => call(cloud.orgs[":id"].users.$get({ param: params }))
111
+ ),
112
+ inviteUser: withSchema(
113
+ import_zod.z.object({
114
+ id: import_zod.z.string().describe("Organization ID"),
115
+ email: import_zod.z.string().describe("User email"),
116
+ name: import_zod.z.string().describe("User full name"),
117
+ role: import_zod.z.enum(["owner", "admin", "member"]).optional().describe("Role (owner|admin|member)")
118
+ }),
119
+ (params) => {
120
+ const { id, ...body } = params;
121
+ return call(cloud.orgs[":id"].users.$post({ param: { id }, json: body }));
122
+ }
123
+ ),
124
+ updateUserRole: withSchema(
125
+ import_zod.z.object({
126
+ id: import_zod.z.string().describe("Organization ID"),
127
+ userId: import_zod.z.string().describe("User ID"),
128
+ role: import_zod.z.enum(["owner", "admin", "member"]).describe("New role")
129
+ }),
130
+ (params) => {
131
+ const { id, userId, ...body } = params;
132
+ return call(
133
+ cloud.orgs[":id"].users[":userId"].$patch({ param: { id, userId }, json: body })
134
+ );
135
+ }
136
+ ),
137
+ removeUser: withSchema(
138
+ import_zod.z.object({
139
+ id: import_zod.z.string().describe("Organization ID"),
140
+ userId: import_zod.z.string().describe("User ID")
141
+ }),
142
+ (params) => call(cloud.orgs[":id"].users[":userId"].$delete({ param: params }))
143
+ ),
144
+ leave: withSchema(
145
+ import_zod.z.object({
146
+ id: import_zod.z.string().describe("Organization ID")
147
+ }),
148
+ (params) => call(cloud.orgs[":id"].leave.$post({ param: params }))
149
+ ),
150
+ delete: withSchema(
151
+ import_zod.z.object({
152
+ id: import_zod.z.string().describe("Organization ID")
153
+ }),
154
+ (params) => call(cloud.orgs[":id"].$delete({ param: params }))
155
+ ),
156
+ listPersonalTokens: withSchema(
157
+ import_zod.z.object({
158
+ id: import_zod.z.string().describe("Organization ID")
159
+ }),
160
+ async (params) => callPersonalTokens(
161
+ await personalTokensRequest(baseUrl, hcOpts, `/orgs/${params.id}/personal-tokens`)
162
+ )
163
+ ),
164
+ createPersonalToken: withSchema(
165
+ import_zod.z.object({
166
+ id: import_zod.z.string().describe("Organization ID"),
167
+ name: import_zod.z.string().describe("Token label"),
168
+ expiresAt: import_zod.z.string().datetime().optional().describe("Optional ISO expiry")
169
+ }),
170
+ async (params) => {
171
+ const { id, ...body } = params;
172
+ return callPersonalTokens(
173
+ await personalTokensRequest(baseUrl, hcOpts, `/orgs/${id}/personal-tokens`, {
174
+ method: "POST",
175
+ headers: { "Content-Type": "application/json" },
176
+ body: JSON.stringify(body)
177
+ })
178
+ );
179
+ }
180
+ ),
181
+ revokePersonalToken: withSchema(
182
+ import_zod.z.object({
183
+ id: import_zod.z.string().describe("Organization ID"),
184
+ tokenId: import_zod.z.string().describe("Personal token ID")
185
+ }),
186
+ async (params) => callPersonalTokens(
187
+ await personalTokensRequest(
188
+ baseUrl,
189
+ hcOpts,
190
+ `/orgs/${params.id}/personal-tokens/${params.tokenId}`,
191
+ { method: "DELETE" }
192
+ )
193
+ )
194
+ ),
195
+ listSsoExtras: withSchema(
196
+ import_zod.z.object({
197
+ id: import_zod.z.string().describe("Organization ID")
198
+ }),
199
+ async (params) => callPersonalTokens(
200
+ await personalTokensRequest(baseUrl, hcOpts, `/orgs/${params.id}/sso-extras`)
201
+ )
202
+ ),
203
+ setSsoForce: withSchema(
204
+ import_zod.z.object({
205
+ id: import_zod.z.string().describe("Organization ID"),
206
+ providerId: import_zod.z.string().describe("SSO provider ID"),
207
+ forceSso: import_zod.z.boolean().describe("Force-SSO toggle for this provider")
208
+ }),
209
+ async (params) => callPersonalTokens(
210
+ await personalTokensRequest(
211
+ baseUrl,
212
+ hcOpts,
213
+ `/orgs/${params.id}/sso-extras/${params.providerId}`,
214
+ {
215
+ method: "PATCH",
216
+ headers: { "Content-Type": "application/json" },
217
+ body: JSON.stringify({ forceSso: params.forceSso })
218
+ }
219
+ )
220
+ )
221
+ )
222
+ };
223
+ }
224
+
225
+ // src/projects.ts
226
+ var import_zod2 = require("zod");
227
+ var import_client = require("hono/client");
228
+ function createProjectsClient(cloud, baseUrl, hcOpts) {
229
+ return {
230
+ list: withSchema(
231
+ import_zod2.z.object({
232
+ orgId: import_zod2.z.string().describe("Organization ID")
233
+ }),
234
+ (params) => call(cloud.orgs[":orgId"].projects.$get({ param: params }))
235
+ ),
236
+ create: withSchema(
237
+ import_zod2.z.object({
238
+ orgId: import_zod2.z.string().describe("Organization ID"),
239
+ name: import_zod2.z.string().describe("Project name"),
240
+ slug: import_zod2.z.string().describe("URL slug (lowercase, hyphens only)")
241
+ }),
242
+ (params) => {
243
+ const { orgId, ...body } = params;
244
+ return call(cloud.orgs[":orgId"].projects.$post({ param: { orgId }, json: body }));
245
+ }
246
+ ),
247
+ get: withSchema(
248
+ import_zod2.z.object({
249
+ orgId: import_zod2.z.string().describe("Organization ID"),
250
+ projectId: import_zod2.z.string().describe("Project ID")
251
+ }),
252
+ (params) => call(cloud.orgs[":orgId"].projects[":projectId"].$get({ param: params }))
253
+ ),
254
+ delete: withSchema(
255
+ import_zod2.z.object({
256
+ orgId: import_zod2.z.string().describe("Organization ID"),
257
+ projectId: import_zod2.z.string().describe("Project ID")
258
+ }),
259
+ (params) => call(cloud.orgs[":orgId"].projects[":projectId"].$delete({ param: params }))
260
+ ),
261
+ update: withSchema(
262
+ import_zod2.z.object({
263
+ orgId: import_zod2.z.string().describe("Organization ID"),
264
+ projectId: import_zod2.z.string().describe("Project ID"),
265
+ name: import_zod2.z.string().optional().describe("New project name"),
266
+ metadata: import_zod2.z.record(import_zod2.z.unknown()).optional().describe("Per-project UI settings")
267
+ }),
268
+ (params) => {
269
+ const { orgId, projectId, ...body } = params;
270
+ return call(
271
+ cloud.orgs[":orgId"].projects[":projectId"].$put({
272
+ param: { orgId, projectId },
273
+ json: body
274
+ })
275
+ );
276
+ }
277
+ ),
278
+ listMembers: withSchema(
279
+ import_zod2.z.object({
280
+ orgId: import_zod2.z.string().describe("Organization ID"),
281
+ projectId: import_zod2.z.string().describe("Project ID")
282
+ }),
283
+ (params) => call(cloud.orgs[":orgId"].projects[":projectId"].members.$get({ param: params }))
284
+ ),
285
+ addMember: withSchema(
286
+ import_zod2.z.object({
287
+ orgId: import_zod2.z.string().describe("Organization ID"),
288
+ projectId: import_zod2.z.string().describe("Project ID"),
289
+ userId: import_zod2.z.string().describe("User ID"),
290
+ role: import_zod2.z.enum(["owner", "admin", "member", "viewer"]).optional().describe("Role (owner|admin|member|viewer)"),
291
+ envName: import_zod2.z.string().optional().describe("Optional env scope; omit for project-wide access")
292
+ }),
293
+ (params) => {
294
+ const { orgId, projectId, ...body } = params;
295
+ return call(
296
+ cloud.orgs[":orgId"].projects[":projectId"].members.$post({
297
+ param: { orgId, projectId },
298
+ json: body
299
+ })
300
+ );
301
+ }
302
+ ),
303
+ removeMember: withSchema(
304
+ import_zod2.z.object({
305
+ orgId: import_zod2.z.string().describe("Organization ID"),
306
+ projectId: import_zod2.z.string().describe("Project ID"),
307
+ userId: import_zod2.z.string().describe("User ID")
308
+ }),
309
+ (params) => call(
310
+ cloud.orgs[":orgId"].projects[":projectId"].members[":userId"].$delete({
311
+ param: params
312
+ })
313
+ )
314
+ ),
315
+ updateCellScopes: withSchema(
316
+ import_zod2.z.object({
317
+ orgId: import_zod2.z.string().describe("Organization ID"),
318
+ projectId: import_zod2.z.string().describe("Project ID"),
319
+ userId: import_zod2.z.string().describe("User ID"),
320
+ cellScopes: import_zod2.z.union([import_zod2.z.array(import_zod2.z.string()), import_zod2.z.null()]).describe("null = all cells; array = restrict to listed cell-label values")
321
+ }),
322
+ (params) => {
323
+ const { orgId, projectId, userId, cellScopes } = params;
324
+ return call(
325
+ cloud.orgs[":orgId"].projects[":projectId"].members[":userId"]["cell-scopes"].$put({
326
+ param: { orgId, projectId, userId },
327
+ json: { cellScopes }
328
+ })
329
+ );
330
+ }
331
+ ),
332
+ listTokens: withSchema(
333
+ import_zod2.z.object({
334
+ orgId: import_zod2.z.string().describe("Organization ID"),
335
+ projectId: import_zod2.z.string().describe("Project ID")
336
+ }),
337
+ (params) => call(
338
+ (0, import_client.hc)(
339
+ `${baseUrl}/orgs/${params.orgId}/projects/${params.projectId}/tokens`,
340
+ hcOpts
341
+ ).index.$get()
342
+ )
343
+ ),
344
+ createToken: withSchema(
345
+ import_zod2.z.object({
346
+ orgId: import_zod2.z.string().describe("Organization ID"),
347
+ projectId: import_zod2.z.string().describe("Project ID"),
348
+ name: import_zod2.z.string().describe("Token name"),
349
+ role: import_zod2.z.enum(["owner", "admin", "member", "viewer"]).optional().describe("Role (owner|admin|member|viewer)"),
350
+ expiresAt: import_zod2.z.string().optional().describe("Expiry timestamp (ISO 8601)"),
351
+ envName: import_zod2.z.string().optional().describe("Optional env scope; omit for project-wide access"),
352
+ cellScopes: import_zod2.z.union([import_zod2.z.array(import_zod2.z.string()), import_zod2.z.null()]).optional().describe(
353
+ "Optional cell scope; null/omitted = all cells, array = restrict to listed cell-label values"
354
+ )
355
+ }),
356
+ (params) => {
357
+ const { orgId, projectId, ...body } = params;
358
+ return call(
359
+ (0, import_client.hc)(
360
+ `${baseUrl}/orgs/${orgId}/projects/${projectId}/tokens`,
361
+ hcOpts
362
+ ).index.$post({ json: body })
363
+ );
364
+ }
365
+ ),
366
+ revokeToken: withSchema(
367
+ import_zod2.z.object({
368
+ orgId: import_zod2.z.string().describe("Organization ID"),
369
+ projectId: import_zod2.z.string().describe("Project ID"),
370
+ tokenId: import_zod2.z.string().describe("Token ID")
371
+ }),
372
+ (params) => call(
373
+ (0, import_client.hc)(
374
+ `${baseUrl}/orgs/${params.orgId}/projects/${params.projectId}/tokens`,
375
+ hcOpts
376
+ )[":tokenId"].$delete({ param: { tokenId: params.tokenId } })
377
+ )
378
+ )
379
+ };
380
+ }
381
+
382
+ // src/entities.ts
383
+ var import_zod3 = require("zod");
384
+ var import_types = require("@terrantula/types");
385
+ function createEntityTypesClient(proj) {
386
+ return {
387
+ list: withSchema(
388
+ import_zod3.z.object({
389
+ projectId: import_zod3.z.string().describe("Project ID")
390
+ }),
391
+ (params) => call(proj(params.projectId)["entity-types"].$get())
392
+ ),
393
+ get: withSchema(
394
+ import_zod3.z.object({
395
+ projectId: import_zod3.z.string().describe("Project ID"),
396
+ name: import_zod3.z.string().describe("Entity type name")
397
+ }),
398
+ (params) => call(proj(params.projectId)["entity-types"][":name"].$get({ param: { name: params.name } }))
399
+ ),
400
+ create: withSchema(
401
+ import_types.EntityTypeSchema.extend({ projectId: import_zod3.z.string().describe("Project ID") }),
402
+ (params) => {
403
+ const { projectId, ...body } = params;
404
+ return call(proj(projectId)["entity-types"].$post({ json: body }));
405
+ }
406
+ ),
407
+ update: withSchema(
408
+ import_types.EntityTypeSchema.extend({ projectId: import_zod3.z.string().describe("Project ID") }),
409
+ (params) => {
410
+ const { projectId, ...body } = params;
411
+ return call(
412
+ proj(projectId)["entity-types"][":name"].$put({ param: { name: params.name }, json: body })
413
+ );
414
+ }
415
+ ),
416
+ delete: withSchema(
417
+ import_zod3.z.object({
418
+ projectId: import_zod3.z.string().describe("Project ID"),
419
+ name: import_zod3.z.string().describe("Entity type name")
420
+ }),
421
+ (params) => call(
422
+ proj(params.projectId)["entity-types"][":name"].$delete({ param: { name: params.name } })
423
+ )
424
+ )
425
+ };
426
+ }
427
+ function createEntitiesClient(projEnv) {
428
+ return {
429
+ list: withSchema(
430
+ import_zod3.z.object({
431
+ projectId: import_zod3.z.string().describe("Project ID"),
432
+ envName: import_zod3.z.string().describe("Environment name"),
433
+ entityType: import_zod3.z.string().optional().describe("Filter by entity type"),
434
+ state: import_zod3.z.string().optional().describe("Filter by state"),
435
+ pool: import_zod3.z.string().optional().describe("Filter by pool membership"),
436
+ limit: import_zod3.z.coerce.number().int().min(1).max(100).optional().describe("Max results (1-100)"),
437
+ cursor: import_zod3.z.string().optional().describe("Pagination cursor")
438
+ }),
439
+ (params) => {
440
+ const { projectId, envName, ...query } = params;
441
+ return call(
442
+ projEnv(projectId, envName)["entities"].$get({ query: stringifyQuery(query) })
443
+ );
444
+ }
445
+ ),
446
+ get: withSchema(
447
+ import_zod3.z.object({
448
+ projectId: import_zod3.z.string().describe("Project ID"),
449
+ envName: import_zod3.z.string().describe("Environment name"),
450
+ id: import_zod3.z.string().uuid().describe("Entity ID")
451
+ }),
452
+ (params) => call(projEnv(params.projectId, params.envName)["entities"][":id"].$get({ param: { id: params.id } }))
453
+ ),
454
+ create: withSchema(
455
+ import_types.EntitySchema.extend({
456
+ projectId: import_zod3.z.string().describe("Project ID"),
457
+ envName: import_zod3.z.string().describe("Environment name")
458
+ }),
459
+ (params) => {
460
+ const { projectId, envName, ...body } = params;
461
+ return call(projEnv(projectId, envName)["entities"].$post({ json: body }));
462
+ }
463
+ ),
464
+ delete: withSchema(
465
+ import_zod3.z.object({
466
+ projectId: import_zod3.z.string().describe("Project ID"),
467
+ envName: import_zod3.z.string().describe("Environment name"),
468
+ id: import_zod3.z.string().uuid().describe("Entity ID")
469
+ }),
470
+ (params) => call(
471
+ projEnv(params.projectId, params.envName)["entities"][":id"].$delete({ param: { id: params.id } })
472
+ )
473
+ ),
474
+ setMetric: withSchema(
475
+ import_zod3.z.object({
476
+ projectId: import_zod3.z.string().describe("Project ID"),
477
+ envName: import_zod3.z.string().describe("Environment name"),
478
+ id: import_zod3.z.string().uuid().describe("Entity ID"),
479
+ metricName: import_zod3.z.string().describe("Metric name"),
480
+ value: import_zod3.z.number().describe("Metric value")
481
+ }),
482
+ (params) => {
483
+ const { projectId, envName, id, metricName, value } = params;
484
+ return call(
485
+ projEnv(projectId, envName)["entities"][":id"]["metrics"][":metricName"].$put({
486
+ param: { id, metricName },
487
+ json: { value }
488
+ })
489
+ );
490
+ }
491
+ ),
492
+ trigger: withSchema(
493
+ import_zod3.z.object({
494
+ projectId: import_zod3.z.string().describe("Project ID"),
495
+ envName: import_zod3.z.string().describe("Environment name"),
496
+ id: import_zod3.z.string().uuid().describe("Entity ID"),
497
+ actionName: import_zod3.z.string().describe("Action name"),
498
+ parameters: import_zod3.z.record(import_zod3.z.unknown()).optional().describe("Action parameters as JSON"),
499
+ recommendations: import_zod3.z.record(import_zod3.z.string()).optional().describe("Recommendation selections as JSON")
500
+ }).describe("Trigger an instance-scope action on a single entity"),
501
+ (params) => {
502
+ const { projectId, envName, id, actionName, parameters, recommendations } = params;
503
+ return call(
504
+ projEnv(projectId, envName)["entities"][":id"]["actions"][":actionName"].$post({
505
+ param: { id, actionName },
506
+ json: { parameters, recommendations }
507
+ })
508
+ );
509
+ }
510
+ ),
511
+ getMetrics: withSchema(
512
+ import_zod3.z.object({
513
+ projectId: import_zod3.z.string().describe("Project ID"),
514
+ envName: import_zod3.z.string().describe("Environment name"),
515
+ entityId: import_zod3.z.string().describe("Entity ID")
516
+ }),
517
+ (params) => call(projEnv(params.projectId, params.envName).entities[":id"].metrics.$get({ param: { id: params.entityId } }))
518
+ ),
519
+ getMetricsBatch: withSchema(
520
+ import_zod3.z.object({
521
+ projectId: import_zod3.z.string().describe("Project ID"),
522
+ envName: import_zod3.z.string().describe("Environment name"),
523
+ entityIds: import_zod3.z.array(import_zod3.z.string().uuid()).min(1).max(500).describe("Entity IDs to fetch metrics for (max 500)")
524
+ }),
525
+ (params) => {
526
+ const { projectId, envName, entityIds } = params;
527
+ return call(
528
+ projEnv(projectId, envName).entities.metrics.$get({
529
+ query: { ids: entityIds.join(",") }
530
+ })
531
+ );
532
+ }
533
+ ),
534
+ getRelationships: withSchema(
535
+ import_zod3.z.object({
536
+ projectId: import_zod3.z.string().describe("Project ID"),
537
+ envName: import_zod3.z.string().describe("Environment name"),
538
+ entityId: import_zod3.z.string().describe("Entity ID")
539
+ }),
540
+ (params) => call(projEnv(params.projectId, params.envName).entities[":id"].relationships.$get({ param: { id: params.entityId } }))
541
+ ),
542
+ syncStamp: withSchema(
543
+ import_zod3.z.object({
544
+ projectId: import_zod3.z.string().describe("Project ID"),
545
+ envName: import_zod3.z.string().describe("Environment name"),
546
+ id: import_zod3.z.string().uuid().describe("Entity ID"),
547
+ source: import_zod3.z.string().min(1).describe("Source-of-truth name (e.g. argo, k8s, aws)"),
548
+ observedAt: import_zod3.z.string().datetime().optional().describe("ISO-8601 observation timestamp; defaults to server time")
549
+ }),
550
+ (params) => {
551
+ const { projectId, envName, id, source, observedAt } = params;
552
+ return call(
553
+ projEnv(projectId, envName)["entities"][":id"]["sync-stamp"].$post({
554
+ param: { id },
555
+ json: { source, observedAt }
556
+ })
557
+ );
558
+ }
559
+ )
560
+ };
561
+ }
562
+
563
+ // src/cells.ts
564
+ var import_zod4 = require("zod");
565
+ var import_types2 = require("@terrantula/types");
566
+ function createCellsClient(proj) {
567
+ return {
568
+ list: withSchema(
569
+ import_zod4.z.object({
570
+ projectId: import_zod4.z.string().describe("Project ID")
571
+ }),
572
+ (params) => call(proj(params.projectId)["cells"].$get())
573
+ ),
574
+ get: withSchema(
575
+ import_zod4.z.object({
576
+ projectId: import_zod4.z.string().describe("Project ID"),
577
+ name: import_zod4.z.string().describe("Cell name")
578
+ }),
579
+ (params) => call(proj(params.projectId)["cells"][":name"].$get({ param: { name: params.name } }))
580
+ ),
581
+ create: withSchema(
582
+ import_types2.CellSchema.extend({ projectId: import_zod4.z.string().describe("Project ID") }),
583
+ (params) => {
584
+ const { projectId, ...body } = params;
585
+ return call(proj(projectId)["cells"].$post({ json: body }));
586
+ }
587
+ ),
588
+ update: withSchema(
589
+ import_types2.CellSchema.extend({ projectId: import_zod4.z.string().describe("Project ID") }),
590
+ (params) => {
591
+ const { projectId, ...body } = params;
592
+ return call(
593
+ proj(projectId)["cells"][":name"].$put({ param: { name: params.name }, json: body })
594
+ );
595
+ }
596
+ ),
597
+ delete: withSchema(
598
+ import_zod4.z.object({
599
+ projectId: import_zod4.z.string().describe("Project ID"),
600
+ name: import_zod4.z.string().describe("Cell name")
601
+ }),
602
+ (params) => call(proj(params.projectId)["cells"][":name"].$delete({ param: { name: params.name } }))
603
+ ),
604
+ listMembers: withSchema(
605
+ import_zod4.z.object({
606
+ projectId: import_zod4.z.string().describe("Project ID"),
607
+ name: import_zod4.z.string().describe("Cell name")
608
+ }),
609
+ (params) => call(
610
+ proj(params.projectId)["cells"][":name"]["members"].$get({ param: { name: params.name } })
611
+ )
612
+ ),
613
+ addMember: withSchema(
614
+ import_zod4.z.object({
615
+ projectId: import_zod4.z.string().describe("Project ID"),
616
+ name: import_zod4.z.string().describe("Cell name"),
617
+ entityId: import_zod4.z.string().uuid().describe("Entity ID")
618
+ }),
619
+ (params) => {
620
+ const { projectId, name, entityId } = params;
621
+ return call(
622
+ proj(projectId)["cells"][":name"]["members"].$post({
623
+ param: { name },
624
+ json: { entityId }
625
+ })
626
+ );
627
+ }
628
+ ),
629
+ removeMember: withSchema(
630
+ import_zod4.z.object({
631
+ projectId: import_zod4.z.string().describe("Project ID"),
632
+ name: import_zod4.z.string().describe("Cell name"),
633
+ entityId: import_zod4.z.string().uuid().describe("Entity ID")
634
+ }),
635
+ (params) => call(
636
+ proj(params.projectId)["cells"][":name"]["members"][":entityId"].$delete({
637
+ param: { name: params.name, entityId: params.entityId }
638
+ })
639
+ )
640
+ )
641
+ };
642
+ }
643
+
644
+ // src/relationships.ts
645
+ var import_zod5 = require("zod");
646
+ var import_types3 = require("@terrantula/types");
647
+ function createRelationshipTypesClient(proj) {
648
+ return {
649
+ list: withSchema(
650
+ import_zod5.z.object({
651
+ projectId: import_zod5.z.string().describe("Project ID")
652
+ }),
653
+ (params) => call(proj(params.projectId)["relationship-types"].$get())
654
+ ),
655
+ get: withSchema(
656
+ import_zod5.z.object({
657
+ projectId: import_zod5.z.string().describe("Project ID"),
658
+ name: import_zod5.z.string().describe("Relationship type name")
659
+ }),
660
+ (params) => call(
661
+ proj(params.projectId)["relationship-types"][":name"].$get({
662
+ param: { name: params.name }
663
+ })
664
+ )
665
+ ),
666
+ create: withSchema(
667
+ import_types3.RelationshipTypeSchema.extend({ projectId: import_zod5.z.string().describe("Project ID") }),
668
+ (params) => {
669
+ const { projectId, ...body } = params;
670
+ return call(proj(projectId)["relationship-types"].$post({ json: body }));
671
+ }
672
+ ),
673
+ update: withSchema(
674
+ import_types3.RelationshipTypeSchema.extend({ projectId: import_zod5.z.string().describe("Project ID") }),
675
+ (params) => {
676
+ const { projectId, ...body } = params;
677
+ return call(
678
+ proj(projectId)["relationship-types"][":name"].$put({
679
+ param: { name: params.name },
680
+ json: body
681
+ })
682
+ );
683
+ }
684
+ ),
685
+ delete: withSchema(
686
+ import_zod5.z.object({
687
+ projectId: import_zod5.z.string().describe("Project ID"),
688
+ name: import_zod5.z.string().describe("Relationship type name")
689
+ }),
690
+ (params) => call(
691
+ proj(params.projectId)["relationship-types"][":name"].$delete({
692
+ param: { name: params.name }
693
+ })
694
+ )
695
+ )
696
+ };
697
+ }
698
+ function createRelationshipsClient(projEnv) {
699
+ return {
700
+ list: withSchema(
701
+ import_zod5.z.object({
702
+ projectId: import_zod5.z.string().describe("Project ID"),
703
+ envName: import_zod5.z.string().describe("Environment name"),
704
+ relationshipType: import_zod5.z.string().optional().describe("Filter by relationship type"),
705
+ state: import_zod5.z.string().optional().describe("Filter by state"),
706
+ fromEntity: import_zod5.z.string().uuid().optional().describe("Filter by from-entity ID"),
707
+ toEntity: import_zod5.z.string().uuid().optional().describe("Filter by to-entity ID"),
708
+ fromEntityPool: import_zod5.z.string().optional().describe("Filter by from-entity pool"),
709
+ toEntityPool: import_zod5.z.string().optional().describe("Filter by to-entity pool"),
710
+ limit: import_zod5.z.coerce.number().int().min(1).max(100).optional().describe("Max results (1-100)")
711
+ }),
712
+ (params) => {
713
+ const { projectId, envName, ...query } = params;
714
+ return call(
715
+ projEnv(projectId, envName)["relationships"].$get({ query: stringifyQuery(query) })
716
+ );
717
+ }
718
+ ),
719
+ get: withSchema(
720
+ import_zod5.z.object({
721
+ projectId: import_zod5.z.string().describe("Project ID"),
722
+ envName: import_zod5.z.string().describe("Environment name"),
723
+ id: import_zod5.z.string().uuid().describe("Relationship ID")
724
+ }),
725
+ (params) => call(
726
+ projEnv(params.projectId, params.envName)["relationships"][":id"].$get({ param: { id: params.id } })
727
+ )
728
+ ),
729
+ create: withSchema(
730
+ import_types3.RelationshipSchema.extend({
731
+ projectId: import_zod5.z.string().describe("Project ID"),
732
+ envName: import_zod5.z.string().describe("Environment name")
733
+ }),
734
+ (params) => {
735
+ const { projectId, envName, ...body } = params;
736
+ return call(projEnv(projectId, envName)["relationships"].$post({ json: body }));
737
+ }
738
+ ),
739
+ delete: withSchema(
740
+ import_zod5.z.object({
741
+ projectId: import_zod5.z.string().describe("Project ID"),
742
+ envName: import_zod5.z.string().describe("Environment name"),
743
+ id: import_zod5.z.string().uuid().describe("Relationship ID")
744
+ }),
745
+ (params) => call(
746
+ projEnv(params.projectId, params.envName)["relationships"][":id"].$delete({ param: { id: params.id } })
747
+ )
748
+ )
749
+ };
750
+ }
751
+
752
+ // src/actions.ts
753
+ var import_zod6 = require("zod");
754
+ var import_types4 = require("@terrantula/types");
755
+ function createActionsClient(proj, projEnv) {
756
+ return {
757
+ list: withSchema(
758
+ import_zod6.z.object({
759
+ projectId: import_zod6.z.string().describe("Project ID")
760
+ }),
761
+ (params) => call(proj(params.projectId)["actions"].$get())
762
+ ),
763
+ get: withSchema(
764
+ import_zod6.z.object({
765
+ projectId: import_zod6.z.string().describe("Project ID"),
766
+ name: import_zod6.z.string().describe("Action name")
767
+ }),
768
+ (params) => call(proj(params.projectId)["actions"][":name"].$get({ param: { name: params.name } }))
769
+ ),
770
+ create: withSchema(
771
+ import_types4.ActionSchema.extend({ projectId: import_zod6.z.string().describe("Project ID") }),
772
+ (params) => {
773
+ const { projectId, ...body } = params;
774
+ return call(proj(projectId)["actions"].$post({ json: body }));
775
+ }
776
+ ),
777
+ update: withSchema(
778
+ import_types4.ActionSchema.extend({ projectId: import_zod6.z.string().describe("Project ID") }),
779
+ (params) => {
780
+ const { projectId, ...body } = params;
781
+ return call(
782
+ proj(projectId)["actions"][":name"].$put({ param: { name: params.name }, json: body })
783
+ );
784
+ }
785
+ ),
786
+ delete: withSchema(
787
+ import_zod6.z.object({
788
+ projectId: import_zod6.z.string().describe("Project ID"),
789
+ name: import_zod6.z.string().describe("Action name")
790
+ }),
791
+ (params) => call(
792
+ proj(params.projectId)["actions"][":name"].$delete({ param: { name: params.name } })
793
+ )
794
+ ),
795
+ run: withSchema(
796
+ import_zod6.z.object({
797
+ projectId: import_zod6.z.string().describe("Project ID"),
798
+ envName: import_zod6.z.string().describe("Environment name"),
799
+ actionName: import_zod6.z.string().describe("Action name"),
800
+ parameters: import_zod6.z.record(import_zod6.z.unknown()).optional().describe("Action parameters as JSON"),
801
+ recommendations: import_zod6.z.record(import_zod6.z.string()).optional().describe("Recommendation selections as JSON")
802
+ }),
803
+ (params) => {
804
+ const { projectId, envName, actionName, parameters, recommendations } = params;
805
+ return call(
806
+ projEnv(projectId, envName)["actions"][":name"]["run"].$post({
807
+ param: { name: actionName },
808
+ json: { parameters, recommendations }
809
+ })
810
+ );
811
+ }
812
+ )
813
+ };
814
+ }
815
+ function createActionRunsClient(projEnv) {
816
+ return {
817
+ list: withSchema(
818
+ import_zod6.z.object({
819
+ projectId: import_zod6.z.string().describe("Project ID"),
820
+ envName: import_zod6.z.string().describe("Environment name"),
821
+ actionName: import_zod6.z.string().optional().describe("Filter by action name"),
822
+ entityId: import_zod6.z.string().uuid().optional().describe("Filter by entity ID"),
823
+ status: import_zod6.z.enum(["pending", "running", "succeeded", "failed", "cancelled"]).optional().describe("Filter by status"),
824
+ limit: import_zod6.z.coerce.number().int().min(1).max(100).optional().describe("Max results (1-100)")
825
+ }),
826
+ (params) => {
827
+ const { projectId, envName, ...query } = params;
828
+ return call(
829
+ projEnv(projectId, envName)["action-runs"].$get({ query: stringifyQuery(query) })
830
+ );
831
+ }
832
+ ),
833
+ get: withSchema(
834
+ import_zod6.z.object({
835
+ projectId: import_zod6.z.string().describe("Project ID"),
836
+ envName: import_zod6.z.string().describe("Environment name"),
837
+ id: import_zod6.z.string().uuid().describe("Action run ID")
838
+ }),
839
+ (params) => call(
840
+ projEnv(params.projectId, params.envName)["action-runs"][":id"].$get({ param: { id: params.id } })
841
+ )
842
+ ),
843
+ cancel: withSchema(
844
+ import_zod6.z.object({
845
+ projectId: import_zod6.z.string().describe("Project ID"),
846
+ envName: import_zod6.z.string().describe("Environment name"),
847
+ id: import_zod6.z.string().uuid().describe("Action run ID")
848
+ }),
849
+ (params) => call(
850
+ projEnv(params.projectId, params.envName)["action-runs"][":id"].$delete({ param: { id: params.id } })
851
+ )
852
+ )
853
+ };
854
+ }
855
+
856
+ // src/secrets.ts
857
+ var import_zod7 = require("zod");
858
+ var import_types5 = require("@terrantula/types");
859
+ function createSecretsClient(projEnv) {
860
+ return {
861
+ list: withSchema(
862
+ import_zod7.z.object({
863
+ projectId: import_zod7.z.string().describe("Project ID"),
864
+ envName: import_zod7.z.string().describe("Environment name")
865
+ }),
866
+ (params) => call(projEnv(params.projectId, params.envName)["secrets"].$get())
867
+ ),
868
+ get: withSchema(
869
+ import_zod7.z.object({
870
+ projectId: import_zod7.z.string().describe("Project ID"),
871
+ envName: import_zod7.z.string().describe("Environment name"),
872
+ name: import_zod7.z.string().describe("Secret name")
873
+ }),
874
+ (params) => call(
875
+ projEnv(params.projectId, params.envName)["secrets"][":name"].$get({ param: { name: params.name } })
876
+ )
877
+ ),
878
+ create: withSchema(
879
+ import_zod7.z.object({
880
+ projectId: import_zod7.z.string().describe("Project ID"),
881
+ envName: import_zod7.z.string().describe("Environment name"),
882
+ name: import_zod7.z.string().describe("Secret name"),
883
+ description: import_zod7.z.string().optional().describe("Description")
884
+ }),
885
+ (params) => {
886
+ const { projectId, envName, name, description } = params;
887
+ return call(
888
+ projEnv(projectId, envName)["secrets"].$post({ json: { kind: "Secret", name, description } })
889
+ );
890
+ }
891
+ ),
892
+ delete: withSchema(
893
+ import_zod7.z.object({
894
+ projectId: import_zod7.z.string().describe("Project ID"),
895
+ envName: import_zod7.z.string().describe("Environment name"),
896
+ name: import_zod7.z.string().describe("Secret name")
897
+ }),
898
+ (params) => call(
899
+ projEnv(params.projectId, params.envName)["secrets"][":name"].$delete({ param: { name: params.name } })
900
+ )
901
+ ),
902
+ setValue: withSchema(
903
+ import_zod7.z.object({
904
+ projectId: import_zod7.z.string().describe("Project ID"),
905
+ envName: import_zod7.z.string().describe("Environment name"),
906
+ name: import_zod7.z.string().describe("Secret name"),
907
+ value: import_zod7.z.string().min(1).describe("Secret value")
908
+ }),
909
+ (params) => {
910
+ const { projectId, envName, name, value } = params;
911
+ return call(
912
+ projEnv(projectId, envName)["secrets"][":name"]["value"].$put({
913
+ param: { name },
914
+ json: { value }
915
+ })
916
+ );
917
+ }
918
+ )
919
+ };
920
+ }
921
+ function createApplyClient(projEnv) {
922
+ return withSchema(
923
+ import_types5.ApplyRequestSchema.extend({
924
+ projectId: import_zod7.z.string().describe("Project ID"),
925
+ envName: import_zod7.z.string().describe("Environment name")
926
+ }),
927
+ (params) => {
928
+ const { projectId, envName, ...body } = params;
929
+ return call(projEnv(projectId, envName)["apply"].$post({ json: body }));
930
+ }
931
+ );
932
+ }
933
+
934
+ // src/github.ts
935
+ var import_zod8 = require("zod");
936
+ function createGithubClient(cloud, _baseUrl, _hcOpts) {
937
+ return {
938
+ connect: withSchema(
939
+ import_zod8.z.object({
940
+ projectId: import_zod8.z.string().describe("Project ID")
941
+ }),
942
+ (params) => call(cloud.api.github["install-url"].$post({ json: params }))
943
+ ),
944
+ installations: {
945
+ list: withSchema(
946
+ import_zod8.z.object({
947
+ orgId: import_zod8.z.string().describe("Organization ID")
948
+ }),
949
+ (params) => call(cloud.api.github.installations.$get({ query: params }))
950
+ ),
951
+ repos: withSchema(
952
+ import_zod8.z.object({
953
+ installationId: import_zod8.z.string().describe("Installation row ID")
954
+ }),
955
+ (params) => call(
956
+ cloud.api.github.installations[":installationId"].repos.$get({
957
+ param: params
958
+ })
959
+ )
960
+ ),
961
+ disconnect: withSchema(
962
+ import_zod8.z.object({
963
+ installationId: import_zod8.z.string().describe("Installation row ID")
964
+ }),
965
+ (params) => call(
966
+ cloud.api.github.installations[":installationId"].$delete({
967
+ param: params
968
+ })
969
+ )
970
+ ),
971
+ recover: withSchema(
972
+ import_zod8.z.object({
973
+ orgId: import_zod8.z.string().describe("Organization ID"),
974
+ installationId: import_zod8.z.number().int().positive().describe("GitHub installation ID (from the GitHub install URL)")
975
+ }),
976
+ (params) => call(cloud.api.github.installations.recover.$post({ json: params }))
977
+ )
978
+ },
979
+ projects: {
980
+ linkRepo: withSchema(
981
+ import_zod8.z.object({
982
+ orgId: import_zod8.z.string().describe("Organization ID"),
983
+ projectId: import_zod8.z.string().describe("Project ID"),
984
+ installationId: import_zod8.z.string().describe("Installation row ID"),
985
+ owner: import_zod8.z.string().describe("GitHub repo owner"),
986
+ name: import_zod8.z.string().describe("GitHub repo name")
987
+ }),
988
+ (params) => {
989
+ const { orgId, projectId, ...body } = params;
990
+ return call(
991
+ cloud.orgs[":orgId"].projects[":projectId"]["github-repos"].$post({
992
+ param: { orgId, projectId },
993
+ json: body
994
+ })
995
+ );
996
+ }
997
+ ),
998
+ unlinkRepo: withSchema(
999
+ import_zod8.z.object({
1000
+ orgId: import_zod8.z.string().describe("Organization ID"),
1001
+ projectId: import_zod8.z.string().describe("Project ID"),
1002
+ owner: import_zod8.z.string().describe("GitHub repo owner"),
1003
+ name: import_zod8.z.string().describe("GitHub repo name")
1004
+ }),
1005
+ (params) => call(
1006
+ cloud.orgs[":orgId"].projects[":projectId"]["github-repos"][":owner"][":name"].$delete({
1007
+ param: params
1008
+ })
1009
+ )
1010
+ )
1011
+ }
1012
+ };
1013
+ }
1014
+
1015
+ // src/export.ts
1016
+ var import_zod9 = require("zod");
1017
+ var SERVER_FIELDS = /* @__PURE__ */ new Set(["id", "projectId", "envId", "createdAt", "updatedAt"]);
1018
+ function stripServerFields(row) {
1019
+ const out = {};
1020
+ for (const [key, value] of Object.entries(row)) {
1021
+ if (!SERVER_FIELDS.has(key)) out[key] = value;
1022
+ }
1023
+ return out;
1024
+ }
1025
+ function createExportCatalogFn(proj, projEnv) {
1026
+ return withSchema(
1027
+ import_zod9.z.object({
1028
+ projectId: import_zod9.z.string().describe("Project ID"),
1029
+ envName: import_zod9.z.string().describe("Environment name to export secret declarations from")
1030
+ }).describe("Export every catalog kind as a single apply-shaped payload"),
1031
+ async (params) => {
1032
+ const projClient = proj(params.projectId);
1033
+ const envClient = projEnv(params.projectId, params.envName);
1034
+ const [entityTypes, cells, relationshipTypes, actions, secrets] = await Promise.all([
1035
+ call(projClient["entity-types"].$get()),
1036
+ call(projClient["cells"].$get()),
1037
+ call(projClient["relationship-types"].$get()),
1038
+ call(projClient["actions"].$get()),
1039
+ call(envClient["secrets"].$get())
1040
+ ]);
1041
+ const items = [
1042
+ ...entityTypes.map(
1043
+ (r) => ({ kind: "EntityType", ...stripServerFields(r) })
1044
+ ),
1045
+ ...cells.map(
1046
+ (r) => ({ kind: "Cell", ...stripServerFields(r) })
1047
+ ),
1048
+ ...relationshipTypes.map(
1049
+ (r) => ({ kind: "RelationshipType", ...stripServerFields(r) })
1050
+ ),
1051
+ ...actions.map(
1052
+ (r) => ({ kind: "Action", ...stripServerFields(r) })
1053
+ ),
1054
+ ...secrets.map(
1055
+ (r) => ({ kind: "Secret", ...stripServerFields(r) })
1056
+ )
1057
+ ];
1058
+ return { items };
1059
+ }
1060
+ );
1061
+ }
1062
+
1063
+ // src/catalog-revisions.ts
1064
+ var import_zod10 = require("zod");
1065
+ function createCatalogRevisionsClient(proj) {
1066
+ return {
1067
+ list: withSchema(
1068
+ import_zod10.z.object({
1069
+ projectId: import_zod10.z.string().describe("Project ID"),
1070
+ limit: import_zod10.z.coerce.number().int().min(1).max(200).optional().describe("Max revisions to return (1-200)")
1071
+ }),
1072
+ (params) => {
1073
+ const { projectId, ...query } = params;
1074
+ return call(
1075
+ proj(projectId)["catalog-revisions"].$get({ query: stringifyQuery(query) })
1076
+ );
1077
+ }
1078
+ ),
1079
+ get: withSchema(
1080
+ import_zod10.z.object({
1081
+ projectId: import_zod10.z.string().describe("Project ID"),
1082
+ id: import_zod10.z.string().uuid().describe("Revision ID")
1083
+ }),
1084
+ (params) => call(
1085
+ proj(params.projectId)["catalog-revisions"][":id"].$get({ param: { id: params.id } })
1086
+ )
1087
+ ),
1088
+ snapshots: withSchema(
1089
+ import_zod10.z.object({
1090
+ projectId: import_zod10.z.string().describe("Project ID"),
1091
+ id: import_zod10.z.string().uuid().describe("Revision ID to read snapshots for")
1092
+ }),
1093
+ (params) => call(
1094
+ proj(params.projectId)["catalog-revisions"][":id"]["snapshots"].$get({
1095
+ param: { id: params.id }
1096
+ })
1097
+ )
1098
+ ),
1099
+ /**
1100
+ * Roll back to a previous revision. Optionally filtered to a single hunk
1101
+ * via `hunkId`. Destructive rollbacks (e.g. reverting a create) require
1102
+ * `force: true`, mirroring POST /apply.
1103
+ */
1104
+ rollback: withSchema(
1105
+ import_zod10.z.object({
1106
+ projectId: import_zod10.z.string().describe("Project ID"),
1107
+ id: import_zod10.z.string().uuid().describe("Revision ID to roll back to"),
1108
+ hunkId: import_zod10.z.string().uuid().optional().describe("Single-hunk filter"),
1109
+ force: import_zod10.z.boolean().optional().describe("Required if the inverse diff is destructive")
1110
+ }),
1111
+ (params) => {
1112
+ const { projectId, id, hunkId, force } = params;
1113
+ return call(
1114
+ proj(projectId)["catalog-revisions"][":id"]["rollback"].$post({
1115
+ param: { id },
1116
+ json: { force: force ?? false },
1117
+ query: hunkId ? stringifyQuery({ hunkId }) : void 0
1118
+ })
1119
+ );
1120
+ }
1121
+ )
1122
+ };
1123
+ }
1124
+
1125
+ // src/audit-events.ts
1126
+ var import_zod11 = require("zod");
1127
+ function createAuditEventsClient(proj) {
1128
+ return {
1129
+ list: withSchema(
1130
+ import_zod11.z.object({
1131
+ projectId: import_zod11.z.string().describe("Project ID"),
1132
+ envName: import_zod11.z.string().optional().describe("Filter to a single env"),
1133
+ actorType: import_zod11.z.enum(["user", "token"]).optional().describe("Filter by actor type"),
1134
+ actorId: import_zod11.z.string().optional().describe("Filter by actor (user.id or apikey.id)"),
1135
+ action: import_zod11.z.string().optional().describe('Comma-separated actions (e.g. "create,delete")'),
1136
+ resourceKind: import_zod11.z.string().optional().describe("Filter to one resource kind (Entity | Token | Member | \u2026)"),
1137
+ since: import_zod11.z.string().datetime().optional().describe("ISO timestamp; only events strictly after this are returned"),
1138
+ limit: import_zod11.z.coerce.number().int().min(1).max(500).optional().describe("Max rows (1-500)")
1139
+ }).describe("List audit events for a project \u2014 auditor-friendly read-only feed"),
1140
+ (params) => {
1141
+ const { projectId, ...query } = params;
1142
+ return call(proj(projectId)["audit-events"].$get({ query: stringifyQuery(query) }));
1143
+ }
1144
+ )
1145
+ };
1146
+ }
1147
+
1148
+ // src/environments.ts
1149
+ var import_zod12 = require("zod");
1150
+ function createEnvironmentsClient(proj) {
1151
+ return {
1152
+ list: withSchema(
1153
+ import_zod12.z.object({
1154
+ projectId: import_zod12.z.string().describe("Project ID")
1155
+ }),
1156
+ (params) => call(proj(params.projectId)["environments"].$get())
1157
+ ),
1158
+ create: withSchema(
1159
+ import_zod12.z.object({
1160
+ projectId: import_zod12.z.string().describe("Project ID"),
1161
+ name: import_zod12.z.string().min(1).max(31).regex(/^[a-z0-9][a-z0-9-]{0,30}$/).describe("Environment name (lowercase letters, digits, hyphens; max 31 chars)")
1162
+ }),
1163
+ (params) => {
1164
+ const { projectId, name } = params;
1165
+ return call(proj(projectId)["environments"].$post({ json: { name } }));
1166
+ }
1167
+ ),
1168
+ delete: withSchema(
1169
+ import_zod12.z.object({
1170
+ projectId: import_zod12.z.string().describe("Project ID"),
1171
+ name: import_zod12.z.string().describe("Environment name")
1172
+ }),
1173
+ (params) => call(
1174
+ proj(params.projectId)["environments"][":envName"].$delete({
1175
+ param: { envName: params.name }
1176
+ })
1177
+ )
1178
+ )
1179
+ };
1180
+ }
1181
+
1182
+ // src/drift-events.ts
1183
+ var import_zod13 = require("zod");
1184
+ function createDriftEventsClient(projEnv) {
1185
+ return {
1186
+ list: withSchema(
1187
+ import_zod13.z.object({
1188
+ projectId: import_zod13.z.string().describe("Project ID"),
1189
+ envName: import_zod13.z.string().describe("Environment name"),
1190
+ status: import_zod13.z.enum(["open", "accepted", "reapplied", "snoozed"]).optional(),
1191
+ kind: import_zod13.z.string().optional().describe("Filter by entity type name"),
1192
+ entityId: import_zod13.z.string().uuid().optional(),
1193
+ since: import_zod13.z.string().optional().describe("ISO timestamp lower bound on detectedAt"),
1194
+ limit: import_zod13.z.coerce.number().int().min(1).max(500).optional()
1195
+ }),
1196
+ (params) => {
1197
+ const { projectId, envName, ...query } = params;
1198
+ return call(
1199
+ projEnv(projectId, envName)["drift-events"].$get({ query: stringifyQuery(query) })
1200
+ );
1201
+ }
1202
+ ),
1203
+ count: withSchema(
1204
+ import_zod13.z.object({ projectId: import_zod13.z.string(), envName: import_zod13.z.string() }),
1205
+ (params) => call(projEnv(params.projectId, params.envName)["drift-events"].count.$get())
1206
+ ),
1207
+ get: withSchema(
1208
+ import_zod13.z.object({
1209
+ projectId: import_zod13.z.string(),
1210
+ envName: import_zod13.z.string(),
1211
+ id: import_zod13.z.string().uuid()
1212
+ }),
1213
+ (params) => call(
1214
+ projEnv(params.projectId, params.envName)["drift-events"][":id"].$get({
1215
+ param: { id: params.id }
1216
+ })
1217
+ )
1218
+ ),
1219
+ accept: withSchema(
1220
+ import_zod13.z.object({
1221
+ projectId: import_zod13.z.string(),
1222
+ envName: import_zod13.z.string(),
1223
+ id: import_zod13.z.string().uuid()
1224
+ }),
1225
+ (params) => call(
1226
+ projEnv(params.projectId, params.envName)["drift-events"][":id"].accept.$post({
1227
+ param: { id: params.id }
1228
+ })
1229
+ )
1230
+ ),
1231
+ reapply: withSchema(
1232
+ import_zod13.z.object({
1233
+ projectId: import_zod13.z.string(),
1234
+ envName: import_zod13.z.string(),
1235
+ id: import_zod13.z.string().uuid()
1236
+ }),
1237
+ (params) => call(
1238
+ projEnv(params.projectId, params.envName)["drift-events"][":id"].reapply.$post({
1239
+ param: { id: params.id }
1240
+ })
1241
+ )
1242
+ ),
1243
+ snooze: withSchema(
1244
+ import_zod13.z.object({
1245
+ projectId: import_zod13.z.string(),
1246
+ envName: import_zod13.z.string(),
1247
+ id: import_zod13.z.string().uuid(),
1248
+ untilSeconds: import_zod13.z.number().int().positive().optional()
1249
+ }),
1250
+ (params) => call(
1251
+ projEnv(params.projectId, params.envName)["drift-events"][":id"].snooze.$post({
1252
+ param: { id: params.id },
1253
+ json: { untilSeconds: params.untilSeconds }
1254
+ })
1255
+ )
1256
+ )
1257
+ };
1258
+ }
1259
+
1260
+ // src/stats.ts
1261
+ var import_zod14 = require("zod");
1262
+ var WindowSchema = import_zod14.z.enum(["1h", "24h", "7d"]).optional().describe("Time window \u2014 default 24h");
1263
+ var BucketSchema = import_zod14.z.enum(["1m", "5m", "1h", "1d"]).optional().describe("Bucket granularity \u2014 default 1h");
1264
+ function createStatsClient(proj) {
1265
+ return {
1266
+ entitiesByState: withSchema(
1267
+ import_zod14.z.object({
1268
+ projectId: import_zod14.z.string().describe("Project ID"),
1269
+ window: WindowSchema,
1270
+ bucket: BucketSchema
1271
+ }),
1272
+ (params) => {
1273
+ const { projectId, ...query } = params;
1274
+ return call(proj(projectId)["stats"]["entities-by-state"].$get({ query: stringifyQuery(query) }));
1275
+ }
1276
+ ),
1277
+ runsByType: withSchema(
1278
+ import_zod14.z.object({
1279
+ projectId: import_zod14.z.string().describe("Project ID"),
1280
+ window: WindowSchema
1281
+ }),
1282
+ (params) => {
1283
+ const { projectId, ...query } = params;
1284
+ return call(proj(projectId)["stats"]["runs-by-type"].$get({ query: stringifyQuery(query) }));
1285
+ }
1286
+ ),
1287
+ failingKinds: withSchema(
1288
+ import_zod14.z.object({
1289
+ projectId: import_zod14.z.string().describe("Project ID"),
1290
+ window: WindowSchema
1291
+ }),
1292
+ (params) => {
1293
+ const { projectId, ...query } = params;
1294
+ return call(proj(projectId)["stats"]["failing-kinds"].$get({ query: stringifyQuery(query) }));
1295
+ }
1296
+ ),
1297
+ driftDensity: withSchema(
1298
+ import_zod14.z.object({
1299
+ projectId: import_zod14.z.string().describe("Project ID"),
1300
+ dim: import_zod14.z.string().optional().describe('Dimensions to bucket \u2014 e.g. "kind,cell"')
1301
+ }),
1302
+ (params) => {
1303
+ const { projectId, ...query } = params;
1304
+ return call(proj(projectId)["stats"]["drift-density"].$get({ query: stringifyQuery(query) }));
1305
+ }
1306
+ )
1307
+ };
1308
+ }
1309
+
1310
+ // src/notifications.ts
1311
+ var import_zod15 = require("zod");
1312
+ var import_client2 = require("hono/client");
1313
+ function createNotificationsClient(baseUrl, hcOpts) {
1314
+ const c = (0, import_client2.hc)(`${baseUrl}/notifications`, hcOpts);
1315
+ return {
1316
+ list: withSchema(
1317
+ import_zod15.z.object({
1318
+ limit: import_zod15.z.coerce.number().int().min(1).max(100).optional(),
1319
+ unread: import_zod15.z.boolean().optional()
1320
+ }),
1321
+ (params) => {
1322
+ const query = {};
1323
+ if (params.limit !== void 0) query.limit = String(params.limit);
1324
+ if (params.unread !== void 0) query.unread = String(params.unread);
1325
+ return call(c.index.$get({ query }));
1326
+ }
1327
+ ),
1328
+ read: withSchema(
1329
+ import_zod15.z.object({ id: import_zod15.z.string().uuid() }),
1330
+ (params) => call(c[":id"].read.$post({ param: { id: params.id } }))
1331
+ ),
1332
+ readAll: withSchema(
1333
+ import_zod15.z.object({}),
1334
+ () => call(c["read-all"].$post())
1335
+ )
1336
+ };
1337
+ }
1338
+
1339
+ // src/audit-export.ts
1340
+ var import_zod16 = require("zod");
1341
+ async function rawRequest(baseUrl, hcOpts, path, init = {}) {
1342
+ const fetchImpl = hcOpts?.fetch ?? fetch;
1343
+ const rawHeaders = hcOpts?.headers;
1344
+ const resolvedHeaders = typeof rawHeaders === "function" ? await rawHeaders() : rawHeaders ?? {};
1345
+ return fetchImpl(`${baseUrl}${path}`, {
1346
+ ...init,
1347
+ headers: {
1348
+ ...resolvedHeaders,
1349
+ ...init.headers
1350
+ }
1351
+ });
1352
+ }
1353
+ async function callRaw(res) {
1354
+ if (!res.ok) {
1355
+ let message = fallbackMessage(res.status);
1356
+ try {
1357
+ const body = await res.json();
1358
+ if (body.error) message = body.error;
1359
+ } catch {
1360
+ }
1361
+ throw new TerrantulaError(res.status, { error: message });
1362
+ }
1363
+ return res.json();
1364
+ }
1365
+ function createAuditExportClient(baseUrl, hcOpts) {
1366
+ return {
1367
+ /** GET /orgs/:orgId/audit-export/config — returns current config or throws 404. */
1368
+ getConfig: withSchema(
1369
+ import_zod16.z.object({ orgId: import_zod16.z.string().describe("Organization ID") }),
1370
+ async (params) => callRaw(
1371
+ await rawRequest(baseUrl, hcOpts, `/orgs/${params.orgId}/audit-export/config`)
1372
+ )
1373
+ ),
1374
+ /** POST /orgs/:orgId/audit-export/config — upsert the S3 export config. */
1375
+ setConfig: withSchema(
1376
+ import_zod16.z.object({
1377
+ orgId: import_zod16.z.string().describe("Organization ID"),
1378
+ bucket: import_zod16.z.string().describe("S3 bucket name"),
1379
+ region: import_zod16.z.string().describe("AWS region"),
1380
+ roleArn: import_zod16.z.string().describe("IAM role ARN for assume-role"),
1381
+ enabled: import_zod16.z.boolean().optional().describe("Enable/disable export")
1382
+ }),
1383
+ async (params) => {
1384
+ const { orgId, ...body } = params;
1385
+ return callRaw(
1386
+ await rawRequest(baseUrl, hcOpts, `/orgs/${orgId}/audit-export/config`, {
1387
+ method: "POST",
1388
+ headers: { "Content-Type": "application/json" },
1389
+ body: JSON.stringify(body)
1390
+ })
1391
+ );
1392
+ }
1393
+ ),
1394
+ /** POST /orgs/:orgId/audit-export/test-connection — dry-run write+delete. */
1395
+ testConnection: withSchema(
1396
+ import_zod16.z.object({
1397
+ orgId: import_zod16.z.string().describe("Organization ID"),
1398
+ bucket: import_zod16.z.string().describe("S3 bucket name"),
1399
+ region: import_zod16.z.string().describe("AWS region"),
1400
+ roleArn: import_zod16.z.string().describe("IAM role ARN for assume-role")
1401
+ }),
1402
+ async (params) => {
1403
+ const { orgId, ...body } = params;
1404
+ return callRaw(
1405
+ await rawRequest(baseUrl, hcOpts, `/orgs/${orgId}/audit-export/test-connection`, {
1406
+ method: "POST",
1407
+ headers: { "Content-Type": "application/json" },
1408
+ body: JSON.stringify(body)
1409
+ })
1410
+ );
1411
+ }
1412
+ ),
1413
+ /** GET /orgs/:orgId/audit-export/runs — recent batch run history. */
1414
+ listRuns: withSchema(
1415
+ import_zod16.z.object({
1416
+ orgId: import_zod16.z.string().describe("Organization ID"),
1417
+ limit: import_zod16.z.number().optional().describe("Max results (default 20, max 100)")
1418
+ }),
1419
+ async (params) => {
1420
+ const qs = params.limit ? `?limit=${params.limit}` : "";
1421
+ return callRaw(
1422
+ await rawRequest(
1423
+ baseUrl,
1424
+ hcOpts,
1425
+ `/orgs/${params.orgId}/audit-export/runs${qs}`
1426
+ )
1427
+ );
1428
+ }
1429
+ )
1430
+ };
1431
+ }
1432
+
1433
+ // src/user-preferences.ts
1434
+ var import_client3 = require("hono/client");
1435
+ function createUserPreferencesClient(baseUrl, hcOpts) {
1436
+ const c = (0, import_client3.hc)(
1437
+ `${baseUrl}/user/preferences`,
1438
+ hcOpts
1439
+ );
1440
+ return {
1441
+ get: (key) => call(c[":key"].$get({ param: { key } })),
1442
+ set: (key, value) => call(
1443
+ c[":key"].$put({
1444
+ param: { key },
1445
+ json: { value }
1446
+ })
1447
+ ),
1448
+ delete: (key) => call(c[":key"].$delete({ param: { key } }))
1449
+ };
1450
+ }
1451
+
1452
+ // src/index.ts
1453
+ var createClient = (baseUrl, options = {}) => {
1454
+ const opts = typeof options === "string" || typeof options === "function" ? { token: options } : options;
1455
+ const headers = buildHeaders(opts.token);
1456
+ const fetchImpl = opts.fetch;
1457
+ const hcOpts = fetchImpl ? { headers, fetch: fetchImpl } : { headers };
1458
+ const cloud = (0, import_client4.hc)(baseUrl, hcOpts);
1459
+ const proj = (projectId) => (0, import_client4.hc)(`${baseUrl}/projects/${projectId}`, hcOpts);
1460
+ const projEnv = (projectId, envName) => (0, import_client4.hc)(`${baseUrl}/projects/${projectId}/envs/${envName}`, hcOpts);
1461
+ const cells = createCellsClient(proj);
1462
+ const catalogRevisions = createCatalogRevisionsClient(proj);
1463
+ const exportCatalog = createExportCatalogFn(proj, projEnv);
1464
+ const client = {
1465
+ orgs: createOrgsClient(cloud, baseUrl, hcOpts),
1466
+ projects: createProjectsClient(cloud, baseUrl, hcOpts),
1467
+ github: createGithubClient(cloud, baseUrl, hcOpts),
1468
+ environments: createEnvironmentsClient(proj),
1469
+ entityTypes: createEntityTypesClient(proj),
1470
+ entities: createEntitiesClient(projEnv),
1471
+ cells,
1472
+ relationshipTypes: createRelationshipTypesClient(proj),
1473
+ relationships: createRelationshipsClient(projEnv),
1474
+ actions: createActionsClient(proj, projEnv),
1475
+ actionRuns: createActionRunsClient(projEnv),
1476
+ secrets: createSecretsClient(projEnv),
1477
+ apply: createApplyClient(projEnv),
1478
+ catalogRevisions,
1479
+ auditEvents: createAuditEventsClient(proj),
1480
+ driftEvents: createDriftEventsClient(projEnv),
1481
+ stats: createStatsClient(proj),
1482
+ notifications: createNotificationsClient(baseUrl, hcOpts),
1483
+ auditExport: createAuditExportClient(baseUrl, hcOpts),
1484
+ userPreferences: createUserPreferencesClient(baseUrl, hcOpts),
1485
+ exportCatalog
1486
+ };
1487
+ let warnedPools = false;
1488
+ let warnedApplyRevisions = false;
1489
+ let warnedExportSchema = false;
1490
+ Object.defineProperty(client, "pools", {
1491
+ enumerable: false,
1492
+ configurable: true,
1493
+ get() {
1494
+ if (!warnedPools) {
1495
+ console.warn("[@terrantula/sdk] `client.pools` is deprecated \u2014 use `client.cells`. Will be removed next release.");
1496
+ warnedPools = true;
1497
+ }
1498
+ return cells;
1499
+ }
1500
+ });
1501
+ Object.defineProperty(client, "applyRevisions", {
1502
+ enumerable: false,
1503
+ configurable: true,
1504
+ get() {
1505
+ if (!warnedApplyRevisions) {
1506
+ console.warn("[@terrantula/sdk] `client.applyRevisions` is deprecated \u2014 use `client.catalogRevisions`. Will be removed next release.");
1507
+ warnedApplyRevisions = true;
1508
+ }
1509
+ return catalogRevisions;
1510
+ }
1511
+ });
1512
+ Object.defineProperty(client, "exportSchema", {
1513
+ enumerable: false,
1514
+ configurable: true,
1515
+ get() {
1516
+ if (!warnedExportSchema) {
1517
+ console.warn("[@terrantula/sdk] `client.exportSchema` is deprecated \u2014 use `client.exportCatalog`. Will be removed next release.");
1518
+ warnedExportSchema = true;
1519
+ }
1520
+ return exportCatalog;
1521
+ }
1522
+ });
1523
+ return client;
1524
+ };
1525
+
1526
+ // src/local.ts
1527
+ var import_local = require("@terrantula/local");
1528
+ var import_node_os = require("os");
1529
+ var import_node_path = require("path");
1530
+ var import_node_fs = require("fs");
1531
+ function defaultLocalDbPath() {
1532
+ const dir = (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "terrantula");
1533
+ (0, import_node_fs.mkdirSync)(dir, { recursive: true });
1534
+ return (0, import_node_path.join)(dir, "local.db");
1535
+ }
1536
+ var createLocalClient = (options = {}) => {
1537
+ const opened = (0, import_local.openLocalDb)({ path: options.dbPath ?? defaultLocalDbPath() });
1538
+ const app = (0, import_local.createLocalApp)({ db: opened.db });
1539
+ const localFetch = ((input, init) => {
1540
+ const req = input instanceof Request ? input : new Request(input, init);
1541
+ return Promise.resolve(app.fetch(req));
1542
+ });
1543
+ const client = createClient("http://local/api", { fetch: localFetch });
1544
+ return Object.assign(client, { close: opened.close });
1545
+ };
1546
+ // Annotate the CommonJS export names for ESM import in node:
1547
+ 0 && (module.exports = {
1548
+ createLocalClient
1549
+ });