@miosa/sdk 1.2.4 → 1.2.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 (100) hide show
  1. package/README.md +75 -3
  2. package/dist/index.d.ts +323 -175
  3. package/dist/index.js +441 -386
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -2
  6. package/src/client.ts +0 -293
  7. package/src/errors.ts +0 -136
  8. package/src/http.test.ts +0 -374
  9. package/src/http.ts +0 -390
  10. package/src/index.ts +0 -564
  11. package/src/resources/admin.ts +0 -359
  12. package/src/resources/analytics.ts +0 -60
  13. package/src/resources/api-keys.ts +0 -135
  14. package/src/resources/audit-log.ts +0 -64
  15. package/src/resources/benchmarks.ts +0 -104
  16. package/src/resources/builder-sessions.ts +0 -75
  17. package/src/resources/channels.ts +0 -143
  18. package/src/resources/checkpoints.ts +0 -225
  19. package/src/resources/command-center.ts +0 -73
  20. package/src/resources/community.ts +0 -103
  21. package/src/resources/completions.ts +0 -104
  22. package/src/resources/computer-auto-stop.ts +0 -43
  23. package/src/resources/computer-env.ts +0 -76
  24. package/src/resources/computer-logs.ts +0 -50
  25. package/src/resources/computer-osa.ts +0 -76
  26. package/src/resources/computer-ports.ts +0 -91
  27. package/src/resources/computer-terminal.ts +0 -61
  28. package/src/resources/computer-volumes.ts +0 -64
  29. package/src/resources/computer.ts +0 -551
  30. package/src/resources/computers.ts +0 -75
  31. package/src/resources/credits.ts +0 -43
  32. package/src/resources/cron-jobs.ts +0 -191
  33. package/src/resources/custom_domains.ts +0 -123
  34. package/src/resources/dashboard.ts +0 -49
  35. package/src/resources/databases.ts +0 -218
  36. package/src/resources/deployments.test.ts +0 -194
  37. package/src/resources/deployments.ts +0 -1060
  38. package/src/resources/desktop.ts +0 -134
  39. package/src/resources/docker-deploy.test.ts +0 -102
  40. package/src/resources/docker-deploy.ts +0 -183
  41. package/src/resources/egress.test.ts +0 -318
  42. package/src/resources/egressAudit.ts +0 -245
  43. package/src/resources/egressNetwork.ts +0 -450
  44. package/src/resources/egressSecrets.ts +0 -577
  45. package/src/resources/email.ts +0 -212
  46. package/src/resources/embeddings.ts +0 -36
  47. package/src/resources/events.ts +0 -296
  48. package/src/resources/exec.ts +0 -319
  49. package/src/resources/external-keys.ts +0 -79
  50. package/src/resources/files.test.ts +0 -339
  51. package/src/resources/files.ts +0 -220
  52. package/src/resources/flat-custom-domains.ts +0 -127
  53. package/src/resources/functions.ts +0 -178
  54. package/src/resources/governance.test.ts +0 -355
  55. package/src/resources/governance.ts +0 -528
  56. package/src/resources/health-checks.ts +0 -165
  57. package/src/resources/integrations.ts +0 -183
  58. package/src/resources/mcp.ts +0 -70
  59. package/src/resources/models.ts +0 -45
  60. package/src/resources/network_policy.ts +0 -73
  61. package/src/resources/open-computers/agents.ts +0 -91
  62. package/src/resources/open-computers/apps.ts +0 -102
  63. package/src/resources/open-computers/clusters.ts +0 -88
  64. package/src/resources/open-computers/desktop.ts +0 -34
  65. package/src/resources/open-computers/files.ts +0 -97
  66. package/src/resources/open-computers/hosts.ts +0 -85
  67. package/src/resources/open-computers/index.ts +0 -98
  68. package/src/resources/open-computers/jobs.ts +0 -75
  69. package/src/resources/open-computers/open_computers.test.ts +0 -288
  70. package/src/resources/open-computers/secrets.ts +0 -115
  71. package/src/resources/open-computers/terminal.ts +0 -33
  72. package/src/resources/open-computers/tunnels.ts +0 -87
  73. package/src/resources/open-computers/types.ts +0 -343
  74. package/src/resources/open-computers/workspaces.ts +0 -135
  75. package/src/resources/org-invites.ts +0 -189
  76. package/src/resources/phase1.test.ts +0 -187
  77. package/src/resources/project-auth.ts +0 -142
  78. package/src/resources/project-integrations.ts +0 -133
  79. package/src/resources/provider-defaults.ts +0 -89
  80. package/src/resources/quotas.ts +0 -77
  81. package/src/resources/regions.ts +0 -94
  82. package/src/resources/sandbox-processes.ts +0 -112
  83. package/src/resources/sandbox-shares.ts +0 -83
  84. package/src/resources/sandbox-templates.ts +0 -195
  85. package/src/resources/sandboxes.live.test.ts +0 -92
  86. package/src/resources/sandboxes.test.ts +0 -653
  87. package/src/resources/sandboxes.ts +0 -1433
  88. package/src/resources/settings.ts +0 -143
  89. package/src/resources/snapshots-standalone.ts +0 -51
  90. package/src/resources/storage.ts +0 -221
  91. package/src/resources/tenant-events.ts +0 -32
  92. package/src/resources/tenant.ts +0 -148
  93. package/src/resources/usage.ts +0 -85
  94. package/src/resources/volumes.ts +0 -117
  95. package/src/resources/webhooks.ts +0 -224
  96. package/src/resources/workspace-invites.ts +0 -188
  97. package/src/resources/workspace-members.test.ts +0 -121
  98. package/src/resources/workspace-members.ts +0 -143
  99. package/src/resources/workspaces.ts +0 -285
  100. package/src/types.ts +0 -463
@@ -1,359 +0,0 @@
1
- import type { HttpClient } from "../http.js";
2
-
3
- type Json = Record<string, unknown>;
4
- type Query = Record<string, string | number | boolean | undefined>;
5
-
6
- function withDefined<T extends Record<string, unknown>>(obj: T): Partial<T> {
7
- const out: Record<string, unknown> = {};
8
- for (const [k, v] of Object.entries(obj)) {
9
- if (v !== undefined && v !== null) out[k] = v;
10
- }
11
- return out as Partial<T>;
12
- }
13
-
14
- export interface ListAdminUsersParams {
15
- limit?: number;
16
- cursor?: string;
17
- q?: string;
18
- status?: "active" | "suspended" | "deleted";
19
- }
20
-
21
- export interface ListAdminTenantsParams {
22
- limit?: number;
23
- cursor?: string;
24
- q?: string;
25
- }
26
-
27
- export interface ListAdminComputersParams {
28
- limit?: number;
29
- cursor?: string;
30
- status?:
31
- | "creating"
32
- | "provisioning"
33
- | "running"
34
- | "stopped"
35
- | "paused"
36
- | "error";
37
- tenantId?: string;
38
- }
39
-
40
- export interface ListAdminApiKeysParams {
41
- limit?: number;
42
- cursor?: string;
43
- tenantId?: string;
44
- status?: "active" | "revoked" | "expired";
45
- }
46
-
47
- export interface CreateAdminApiKeyParams {
48
- name: string;
49
- tenantId: string;
50
- userId: string;
51
- keyType?: "user" | "admin" | "platform";
52
- purpose?: "api" | "optimal";
53
- rateLimitRpm?: number;
54
- expiresAt?: string;
55
- allowedIps?: string[];
56
- }
57
-
58
- export interface BulkUserActionParams {
59
- userIds: string[];
60
- action: "suspend" | "unsuspend" | "delete" | "tag" | "notify";
61
- params?: Json;
62
- }
63
-
64
- /**
65
- * Admin surface — `/api/v1/admin/*` endpoints.
66
- *
67
- * Requires a `msk_a_*` or `msk_p_*` API key, or an admin JWT. Calls from
68
- * a user-role credential return 403 Forbidden.
69
- */
70
- export class Admin {
71
- private readonly http: HttpClient;
72
-
73
- constructor(http: HttpClient) {
74
- this.http = http;
75
- }
76
-
77
- /** Escape hatch — call any admin endpoint by method + path. */
78
- async request<T = Json>(
79
- method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
80
- path: string,
81
- body?: unknown,
82
- query?: Query,
83
- ): Promise<T> {
84
- const fullPath = query
85
- ? (() => {
86
- const qs = new URLSearchParams();
87
- for (const [k, v] of Object.entries(query)) {
88
- if (v !== undefined) qs.set(k, String(v));
89
- }
90
- const s = qs.toString();
91
- return s ? `${path}?${s}` : path;
92
- })()
93
- : path;
94
- // Route via the low-level method helpers so retries/backoff still apply.
95
- switch (method) {
96
- case "GET":
97
- return this.http.get<T>(fullPath);
98
- case "POST":
99
- return this.http.post<T>(fullPath, body);
100
- case "PUT":
101
- return this.http.put<T>(fullPath, body);
102
- case "PATCH":
103
- return this.http.patch<T>(fullPath, body);
104
- case "DELETE":
105
- return this.http.delete<T>(fullPath, body);
106
- }
107
- }
108
-
109
- // ── Overview ────────────────────────────────────────────────
110
-
111
- dashboard(): Promise<Json> {
112
- return this.http.get("/admin/dashboard");
113
- }
114
- stats(): Promise<Json> {
115
- return this.http.get("/admin/stats");
116
- }
117
- auditLog(params?: { limit?: number; cursor?: string }): Promise<Json> {
118
- return this.http.get("/admin/audit-log", {
119
- limit: params?.limit,
120
- cursor: params?.cursor,
121
- });
122
- }
123
- detailedHealth(): Promise<Json> {
124
- return this.http.get("/admin/health/detailed");
125
- }
126
-
127
- // ── Credits ─────────────────────────────────────────────────
128
-
129
- grantCredits(params: {
130
- tenantId: string;
131
- amount: number;
132
- description: string;
133
- expiresAt?: string;
134
- }): Promise<Json> {
135
- return this.http.post(
136
- "/admin/credits/grant",
137
- withDefined({
138
- tenant_id: params.tenantId,
139
- amount: params.amount,
140
- description: params.description,
141
- expires_at: params.expiresAt,
142
- }),
143
- );
144
- }
145
- deductCredits(params: {
146
- tenantId: string;
147
- amount: number;
148
- description: string;
149
- }): Promise<Json> {
150
- return this.http.post("/admin/credits/deduct", {
151
- tenant_id: params.tenantId,
152
- amount: params.amount,
153
- description: params.description,
154
- });
155
- }
156
- refundCredits(params: {
157
- tenantId: string;
158
- amount: number;
159
- description: string;
160
- transactionId?: string;
161
- }): Promise<Json> {
162
- return this.http.post(
163
- "/admin/credits/refund",
164
- withDefined({
165
- tenant_id: params.tenantId,
166
- amount: params.amount,
167
- description: params.description,
168
- transaction_id: params.transactionId,
169
- }),
170
- );
171
- }
172
- tenantBalance(tenantId: string): Promise<Json> {
173
- return this.http.get(`/admin/credits/${tenantId}/balance`);
174
- }
175
- tenantCreditHistory(
176
- tenantId: string,
177
- params?: { limit?: number; cursor?: string },
178
- ): Promise<Json> {
179
- return this.http.get(`/admin/credits/${tenantId}/history`, {
180
- limit: params?.limit,
181
- cursor: params?.cursor,
182
- });
183
- }
184
-
185
- // ── Users ───────────────────────────────────────────────────
186
-
187
- listUsers(params?: ListAdminUsersParams): Promise<Json> {
188
- return this.http.get("/admin/users", {
189
- limit: params?.limit,
190
- cursor: params?.cursor,
191
- q: params?.q,
192
- status: params?.status,
193
- });
194
- }
195
- getUser(userId: string): Promise<Json> {
196
- return this.http.get(`/admin/users/${userId}`);
197
- }
198
- updateUser(userId: string, attrs: Json): Promise<Json> {
199
- return this.http.put(`/admin/users/${userId}`, attrs);
200
- }
201
- deleteUser(userId: string): Promise<Json> {
202
- return this.http.delete(`/admin/users/${userId}`);
203
- }
204
- changeUserRole(
205
- userId: string,
206
- role: "user" | "admin" | "owner" | "super_admin",
207
- ): Promise<Json> {
208
- return this.http.post(`/admin/users/${userId}/role`, { role });
209
- }
210
- forceLogout(userId: string): Promise<Json> {
211
- return this.http.post(`/admin/users/${userId}/force-logout`);
212
- }
213
- suspendUser(userId: string, reason?: string): Promise<Json> {
214
- return this.http.post(
215
- `/admin/users/${userId}/suspend`,
216
- reason ? { reason } : undefined,
217
- );
218
- }
219
- unsuspendUser(userId: string): Promise<Json> {
220
- return this.http.post(`/admin/users/${userId}/unsuspend`);
221
- }
222
- banUser(userId: string, reason: string, expiresAt?: string): Promise<Json> {
223
- return this.http.post(
224
- `/admin/users/${userId}/ban`,
225
- withDefined({ reason, expires_at: expiresAt }),
226
- );
227
- }
228
- unbanUser(userId: string): Promise<Json> {
229
- return this.http.post(`/admin/users/${userId}/unban`);
230
- }
231
- bulkUserAction(params: BulkUserActionParams): Promise<Json> {
232
- return this.http.post(
233
- "/admin/users/bulk",
234
- withDefined({
235
- user_ids: params.userIds,
236
- action: params.action,
237
- params: params.params,
238
- }),
239
- );
240
- }
241
-
242
- // ── Tenants ─────────────────────────────────────────────────
243
-
244
- listTenants(params?: ListAdminTenantsParams): Promise<Json> {
245
- return this.http.get("/admin/tenants", {
246
- limit: params?.limit,
247
- cursor: params?.cursor,
248
- q: params?.q,
249
- });
250
- }
251
- tenantDetail(tenantId: string): Promise<Json> {
252
- return this.http.get(`/admin/tenants/${tenantId}/detail`);
253
- }
254
- suspendTenant(tenantId: string, reason?: string): Promise<Json> {
255
- return this.http.post(
256
- `/admin/tenants/${tenantId}/suspend`,
257
- reason ? { reason } : undefined,
258
- );
259
- }
260
- unsuspendTenant(tenantId: string): Promise<Json> {
261
- return this.http.post(`/admin/tenants/${tenantId}/unsuspend`);
262
- }
263
- changeTenantPlan(
264
- tenantId: string,
265
- plan: "free" | "starter" | "pro" | "scale",
266
- prorate = true,
267
- ): Promise<Json> {
268
- return this.http.post(`/admin/tenants/${tenantId}/plan`, { plan, prorate });
269
- }
270
- deleteTenant(tenantId: string): Promise<Json> {
271
- return this.http.delete(`/admin/tenants/${tenantId}`);
272
- }
273
-
274
- // ── Computers ───────────────────────────────────────────────
275
-
276
- listComputers(params?: ListAdminComputersParams): Promise<Json> {
277
- return this.http.get("/admin/computers", {
278
- limit: params?.limit,
279
- cursor: params?.cursor,
280
- status: params?.status,
281
- tenant_id: params?.tenantId,
282
- });
283
- }
284
- deleteComputer(computerId: string): Promise<Json> {
285
- return this.http.delete(`/admin/computers/${computerId}`);
286
- }
287
- suspendComputer(computerId: string): Promise<Json> {
288
- return this.http.post(`/admin/computers/${computerId}/suspend`);
289
- }
290
- resumeComputer(computerId: string): Promise<Json> {
291
- return this.http.post(`/admin/computers/${computerId}/resume`);
292
- }
293
- restartComputer(computerId: string): Promise<Json> {
294
- return this.http.post(`/admin/computers/${computerId}/restart`);
295
- }
296
- purgeStaleComputers(): Promise<Json> {
297
- return this.http.post("/admin/computers/purge-stale");
298
- }
299
-
300
- // ── API Keys ────────────────────────────────────────────────
301
-
302
- listApiKeys(params?: ListAdminApiKeysParams): Promise<Json> {
303
- return this.http.get("/admin/api-keys", {
304
- limit: params?.limit,
305
- cursor: params?.cursor,
306
- tenant_id: params?.tenantId,
307
- status: params?.status,
308
- });
309
- }
310
- createApiKey(params: CreateAdminApiKeyParams): Promise<Json> {
311
- return this.http.post(
312
- "/admin/api-keys",
313
- withDefined({
314
- name: params.name,
315
- tenant_id: params.tenantId,
316
- user_id: params.userId,
317
- key_type: params.keyType ?? "user",
318
- purpose: params.purpose ?? "api",
319
- rate_limit_rpm: params.rateLimitRpm,
320
- expires_at: params.expiresAt,
321
- allowed_ips: params.allowedIps,
322
- }),
323
- );
324
- }
325
- apiKeyStats(): Promise<Json> {
326
- return this.http.get("/admin/api-keys/stats");
327
- }
328
- bulkRevokeApiKeys(keyIds: string[]): Promise<Json> {
329
- return this.http.post("/admin/api-keys/bulk-revoke", { key_ids: keyIds });
330
- }
331
- revokeApiKey(keyId: string): Promise<Json> {
332
- return this.http.delete(`/admin/api-keys/${keyId}`);
333
- }
334
-
335
- // ── Optimal ─────────────────────────────────────────────────
336
-
337
- optimalStatus(): Promise<Json> {
338
- return this.http.get("/admin/optimal/status");
339
- }
340
- listOptimalModels(): Promise<Json> {
341
- return this.http.get("/admin/optimal/models");
342
- }
343
- switchOptimalModel(modelId: string): Promise<Json> {
344
- return this.http.post("/admin/optimal/models/switch", {
345
- model_id: modelId,
346
- });
347
- }
348
-
349
- /** POST /api/v1/admin/impersonate — returns {token, expires_at}. */
350
- impersonate(
351
- externalUserId: string,
352
- options: { ttlSec?: number } = {},
353
- ): Promise<{ token: string; expires_at: string }> {
354
- return this.http.post("/admin/impersonate", {
355
- external_user_id: externalUserId,
356
- ttl_sec: options.ttlSec ?? 3600,
357
- });
358
- }
359
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Analytics — overview + timeseries (admin scope).
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Request payloads ─────────────────────────────────────────────────────────
8
-
9
- export interface AnalyticsFilters {
10
- [key: string]: string | number | boolean | undefined;
11
- }
12
-
13
- export interface TimeseriesParams extends AnalyticsFilters {
14
- metric?: string;
15
- period?: string;
16
- }
17
-
18
- // ── Helpers ───────────────────────────────────────────────────────────────────
19
-
20
- function unwrap<T>(payload: unknown): T {
21
- if (payload && typeof payload === "object") {
22
- const p = payload as Record<string, unknown>;
23
- for (const k of ["data", "analytics", "series", "items"]) {
24
- if (k in p) return p[k] as T;
25
- }
26
- }
27
- return payload as T;
28
- }
29
-
30
- function stripUndefined(
31
- input: Record<string, unknown>,
32
- ): Record<string, string | number | boolean | undefined> {
33
- return Object.fromEntries(
34
- Object.entries(input).filter(([, v]) => v !== undefined),
35
- ) as Record<string, string | number | boolean | undefined>;
36
- }
37
-
38
- // ── Main resource ─────────────────────────────────────────────────────────────
39
-
40
- export class Analytics {
41
- constructor(private readonly http: HttpClient) {}
42
-
43
- /** Get the platform analytics overview. */
44
- async overview(
45
- filters: AnalyticsFilters = {},
46
- ): Promise<Record<string, unknown>> {
47
- const query = stripUndefined(filters as Record<string, unknown>);
48
- const data = await this.http.get<unknown>("/analytics/overview", query);
49
- return unwrap<Record<string, unknown>>(data);
50
- }
51
-
52
- /** Get a timeseries for a metric over a period. */
53
- async timeseries(
54
- params: TimeseriesParams = {},
55
- ): Promise<Record<string, unknown>> {
56
- const query = stripUndefined(params as Record<string, unknown>);
57
- const data = await this.http.get<unknown>("/analytics/timeseries", query);
58
- return unwrap<Record<string, unknown>>(data);
59
- }
60
- }
@@ -1,135 +0,0 @@
1
- /**
2
- * ApiKeys resource — programmatic API key management.
3
- *
4
- * The plaintext key is returned ONLY at create time. Store it immediately;
5
- * the server only keeps a hash.
6
- */
7
-
8
- import { randomUUID } from "node:crypto";
9
-
10
- import type { HttpClient } from "../http.js";
11
-
12
- // ── Branded IDs ──────────────────────────────────────────────────────────────
13
-
14
- export type ApiKeyId = string & { readonly __brand: "ApiKeyId" };
15
-
16
- // ── Resource shapes ──────────────────────────────────────────────────────────
17
-
18
- export interface ApiKeyData {
19
- id: ApiKeyId;
20
- tenant_id: string;
21
- name: string;
22
- prefix?: string;
23
- scopes?: string[];
24
- expires_at?: string | null;
25
- last_used_at?: string | null;
26
- created_at?: string;
27
- [key: string]: unknown;
28
- }
29
-
30
- export interface ApiKeyCreateResult extends ApiKeyData {
31
- /** One-time plaintext key. Store immediately. */
32
- token?: string;
33
- key?: string;
34
- }
35
-
36
- // ── Request payloads ─────────────────────────────────────────────────────────
37
-
38
- export interface ApiKeyListParams {
39
- limit?: number;
40
- cursor?: string;
41
- [key: string]: string | number | boolean | undefined;
42
- }
43
-
44
- export interface ApiKeyCreateParams {
45
- name: string;
46
- scopes?: string[];
47
- expires_at?: string;
48
- expiresAt?: string;
49
- idempotencyKey?: string;
50
- [key: string]: unknown;
51
- }
52
-
53
- // ── Helpers ───────────────────────────────────────────────────────────────────
54
-
55
- function unwrap<T>(payload: unknown): T {
56
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
57
- return (payload as { data: T }).data;
58
- }
59
- return payload as T;
60
- }
61
-
62
- function listItems<T>(
63
- payload: unknown,
64
- candidateKeys: string[] = ["data", "keys", "api_keys", "items"],
65
- ): T[] {
66
- if (Array.isArray(payload)) return payload;
67
- if (!payload || typeof payload !== "object") return [];
68
- const p = payload as Record<string, unknown>;
69
- if (Array.isArray(p.data)) return p.data as T[];
70
- for (const key of candidateKeys) {
71
- if (Array.isArray(p[key])) return p[key] as T[];
72
- }
73
- return [];
74
- }
75
-
76
- function stripUndefined(
77
- input: Record<string, unknown>,
78
- ): Record<string, unknown> {
79
- return Object.fromEntries(
80
- Object.entries(input).filter(([, v]) => v !== undefined),
81
- );
82
- }
83
-
84
- function idempotencyKey(key?: string): string {
85
- return key ?? randomUUID();
86
- }
87
-
88
- // ── Main resource ─────────────────────────────────────────────────────────────
89
-
90
- export class ApiKeys {
91
- constructor(private readonly http: HttpClient) {}
92
-
93
- async list(params: ApiKeyListParams = {}): Promise<ApiKeyData[]> {
94
- const query = stripUndefined({ ...params }) as Record<
95
- string,
96
- string | number | boolean | undefined
97
- >;
98
- const data = await this.http.get<unknown>("/api-keys", query);
99
- return listItems<ApiKeyData>(data);
100
- }
101
-
102
- async create(params: ApiKeyCreateParams): Promise<ApiKeyCreateResult> {
103
- const { idempotencyKey: ikey, expiresAt, ...rest } = params;
104
- const body = stripUndefined({
105
- ...rest,
106
- expires_at: expiresAt ?? rest.expires_at,
107
- });
108
- const data = await this.http.request<unknown>("/api-keys", {
109
- method: "POST",
110
- body,
111
- headers: { "Idempotency-Key": idempotencyKey(ikey) },
112
- });
113
- return unwrap<ApiKeyCreateResult>(data);
114
- }
115
-
116
- /** POST /api/v1/api-keys/scoped — L2 delegation token bound to one external user. */
117
- async createScoped(params: {
118
- externalUserId: string;
119
- scopes: string[];
120
- expiresAt?: string;
121
- }): Promise<ApiKeyCreateResult> {
122
- const body = stripUndefined({
123
- external_user_id: params.externalUserId,
124
- scopes: params.scopes,
125
- expires_at: params.expiresAt,
126
- });
127
- return unwrap<ApiKeyCreateResult>(
128
- await this.http.post<unknown>("/api-keys/scoped", body),
129
- );
130
- }
131
-
132
- async delete(keyId: string): Promise<void> {
133
- await this.http.delete<unknown>(`/api-keys/${keyId}`);
134
- }
135
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * Audit log — admin-scoped event history.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Resource shapes ──────────────────────────────────────────────────────────
8
-
9
- export interface AuditLogEvent {
10
- id?: string;
11
- action?: string;
12
- actor_id?: string;
13
- resource_type?: string;
14
- resource_id?: string;
15
- metadata?: Record<string, unknown>;
16
- inserted_at?: string;
17
- [key: string]: unknown;
18
- }
19
-
20
- // ── Request payloads ─────────────────────────────────────────────────────────
21
-
22
- export interface AuditLogListParams {
23
- action?: string;
24
- actor_id?: string;
25
- resource_type?: string;
26
- limit?: number;
27
- cursor?: string;
28
- [key: string]: string | number | boolean | undefined;
29
- }
30
-
31
- // ── Helpers ───────────────────────────────────────────────────────────────────
32
-
33
- function unwrap<T>(payload: unknown): T {
34
- if (payload && typeof payload === "object") {
35
- const p = payload as Record<string, unknown>;
36
- for (const k of ["data", "audit_log", "events", "items"]) {
37
- if (k in p) return p[k] as T;
38
- }
39
- }
40
- return payload as T;
41
- }
42
-
43
- function stripUndefined(
44
- input: Record<string, unknown>,
45
- ): Record<string, string | number | boolean | undefined> {
46
- return Object.fromEntries(
47
- Object.entries(input).filter(([, v]) => v !== undefined),
48
- ) as Record<string, string | number | boolean | undefined>;
49
- }
50
-
51
- // ── Main resource ─────────────────────────────────────────────────────────────
52
-
53
- export class AuditLog {
54
- constructor(private readonly http: HttpClient) {}
55
-
56
- /** List audit-log events with optional filters. */
57
- async list(params: AuditLogListParams = {}): Promise<AuditLogEvent[]> {
58
- const query = stripUndefined(params as Record<string, unknown>);
59
- const data = await this.http.get<unknown>("/audit-log", query);
60
- const result = unwrap<AuditLogEvent[] | unknown>(data);
61
- if (Array.isArray(result)) return result;
62
- return [];
63
- }
64
- }