@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,143 +0,0 @@
1
- /**
2
- * Settings — tenant config, branding, BYOK provider keys.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Request payloads ─────────────────────────────────────────────────────────
8
-
9
- export interface SettingsUpdateParams {
10
- [key: string]: unknown;
11
- }
12
-
13
- export interface BrandingUpdateParams {
14
- logo_url?: string;
15
- primary_color?: string;
16
- wordmark?: string;
17
- [key: string]: unknown;
18
- }
19
-
20
- export interface ProviderKeyUpsertParams {
21
- key: string;
22
- [key: string]: unknown;
23
- }
24
-
25
- // ── Helpers ───────────────────────────────────────────────────────────────────
26
-
27
- function unwrap<T>(payload: unknown): T {
28
- if (payload && typeof payload === "object") {
29
- const p = payload as Record<string, unknown>;
30
- for (const k of [
31
- "data",
32
- "settings",
33
- "branding",
34
- "provider_keys",
35
- "items",
36
- ]) {
37
- if (k in p) return p[k] as T;
38
- }
39
- }
40
- return payload as T;
41
- }
42
-
43
- function listItems<T>(payload: unknown): T[] {
44
- const result = unwrap<T[] | unknown>(payload);
45
- if (Array.isArray(result)) return result;
46
- return [];
47
- }
48
-
49
- function stripUndefined(
50
- input: Record<string, unknown>,
51
- ): Record<string, unknown> {
52
- return Object.fromEntries(
53
- Object.entries(input).filter(([, v]) => v !== undefined),
54
- );
55
- }
56
-
57
- // ── Main resource ─────────────────────────────────────────────────────────────
58
-
59
- export class Settings {
60
- constructor(private readonly http: HttpClient) {}
61
-
62
- /** Get the current tenant settings. */
63
- async get(): Promise<Record<string, unknown>> {
64
- const data = await this.http.get<unknown>("/settings");
65
- return unwrap<Record<string, unknown>>(data);
66
- }
67
-
68
- /** Update tenant settings. */
69
- async update(params: SettingsUpdateParams): Promise<Record<string, unknown>> {
70
- const body = stripUndefined(params as Record<string, unknown>);
71
- const data = await this.http.put<unknown>("/settings", body);
72
- return unwrap<Record<string, unknown>>(data);
73
- }
74
-
75
- // ── Branding ──────────────────────────────────────────────────────────────
76
-
77
- /** Get tenant branding (logo, colors, custom wordmark). */
78
- async getBranding(): Promise<Record<string, unknown>> {
79
- const data = await this.http.get<unknown>("/settings/branding");
80
- return unwrap<Record<string, unknown>>(data);
81
- }
82
-
83
- /** Update tenant branding. */
84
- async updateBranding(
85
- params: BrandingUpdateParams,
86
- ): Promise<Record<string, unknown>> {
87
- const body = stripUndefined(params as Record<string, unknown>);
88
- const data = await this.http.put<unknown>("/settings/branding", body);
89
- return unwrap<Record<string, unknown>>(data);
90
- }
91
-
92
- // ── Read-only reference data ───────────────────────────────────────────────
93
-
94
- /** Get tenant-scoped compute pricing. */
95
- async computePricing(): Promise<unknown> {
96
- const data = await this.http.get<unknown>("/settings/compute-pricing");
97
- return unwrap(data);
98
- }
99
-
100
- /** Get tenant-scoped GPU pricing. */
101
- async gpuPricing(): Promise<unknown> {
102
- const data = await this.http.get<unknown>("/settings/gpu-pricing");
103
- return unwrap(data);
104
- }
105
-
106
- /** List models available to this tenant. */
107
- async availableModels(): Promise<unknown> {
108
- const data = await this.http.get<unknown>("/settings/available-models");
109
- return unwrap(data);
110
- }
111
-
112
- /** List regions enabled for this tenant. */
113
- async regions(): Promise<unknown> {
114
- const data = await this.http.get<unknown>("/settings/regions");
115
- return unwrap(data);
116
- }
117
-
118
- // ── BYOK provider keys ────────────────────────────────────────────────────
119
-
120
- /** List tenant-level BYOK provider keys (Anthropic, OpenAI, etc.). */
121
- async listProviderKeys(): Promise<Record<string, unknown>[]> {
122
- const data = await this.http.get<unknown>("/settings/provider-keys");
123
- return listItems<Record<string, unknown>>(data);
124
- }
125
-
126
- /** Create or update a BYOK provider key. */
127
- async upsertProviderKey(
128
- provider: string,
129
- params: ProviderKeyUpsertParams,
130
- ): Promise<Record<string, unknown>> {
131
- const body = stripUndefined(params as Record<string, unknown>);
132
- const data = await this.http.put<unknown>(
133
- `/settings/provider-keys/${provider}`,
134
- body,
135
- );
136
- return unwrap<Record<string, unknown>>(data);
137
- }
138
-
139
- /** Delete a BYOK provider key. */
140
- async deleteProviderKey(provider: string): Promise<void> {
141
- await this.http.delete<unknown>(`/settings/provider-keys/${provider}`);
142
- }
143
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * SnapshotsStandalone — fleet-wide snapshot index for admin callers.
3
- *
4
- * Routes: /admin/snapshots/*
5
- * Requires admin credential.
6
- *
7
- * Per-computer snapshots remain nested under client.computers.get(id).checkpoints.
8
- * This resource exposes the fleet-wide read-only index used by the admin dashboard.
9
- */
10
-
11
- import type { HttpClient } from "../http.js";
12
-
13
- function unwrap(data: unknown): Record<string, unknown> {
14
- if (data && typeof data === "object") {
15
- const d = data as Record<string, unknown>;
16
- for (const k of ["data", "snapshots", "items"]) {
17
- if (k in d) return d[k] as Record<string, unknown>;
18
- }
19
- }
20
- return data as Record<string, unknown>;
21
- }
22
-
23
- function unwrapList(data: unknown): Record<string, unknown>[] {
24
- if (Array.isArray(data)) return data as Record<string, unknown>[];
25
- if (data && typeof data === "object") {
26
- const d = data as Record<string, unknown>;
27
- for (const k of ["data", "snapshots", "items"]) {
28
- if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
29
- }
30
- }
31
- return [];
32
- }
33
-
34
- export class SnapshotsStandalone {
35
- constructor(private readonly http: HttpClient) {}
36
-
37
- async list(
38
- filters: Record<string, string | number | boolean | undefined> = {},
39
- ): Promise<Record<string, unknown>[]> {
40
- const query = Object.fromEntries(
41
- Object.entries(filters).filter(([, v]) => v !== undefined),
42
- ) as Record<string, string | number | boolean | undefined>;
43
- return unwrapList(await this.http.get<unknown>("/admin/snapshots", query));
44
- }
45
-
46
- async get(snapshotId: string): Promise<Record<string, unknown>> {
47
- return unwrap(
48
- await this.http.get<unknown>(`/admin/snapshots/${snapshotId}`),
49
- );
50
- }
51
- }
@@ -1,221 +0,0 @@
1
- /**
2
- * Storage resource — managed S3-compatible buckets, objects, and presigned URLs.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Branded IDs ──────────────────────────────────────────────────────────────
8
-
9
- export type BucketId = string & { readonly __brand: "BucketId" };
10
-
11
- // ── Resource shapes ──────────────────────────────────────────────────────────
12
-
13
- export interface BucketData {
14
- id: BucketId;
15
- tenant_id: string;
16
- name: string;
17
- region?: string | null;
18
- visibility?: "private" | "public" | string;
19
- quota_bytes?: number | null;
20
- used_bytes?: number | null;
21
- public?: boolean;
22
- object_count?: number | null;
23
- size_bytes?: number | null;
24
- created_at?: string;
25
- updated_at?: string;
26
- [key: string]: unknown;
27
- }
28
-
29
- export interface StorageObjectData {
30
- key: string;
31
- size_bytes?: number;
32
- content_type?: string;
33
- etag?: string | null;
34
- last_modified?: string | null;
35
- [key: string]: unknown;
36
- }
37
-
38
- export interface PresignResult {
39
- url: string;
40
- expires_at?: string;
41
- [key: string]: unknown;
42
- }
43
-
44
- // ── Request payloads ─────────────────────────────────────────────────────────
45
-
46
- export interface BucketCreateParams {
47
- name: string;
48
- region?: string;
49
- visibility?: "private" | "public";
50
- quota_bytes?: number;
51
- public?: boolean;
52
- [key: string]: unknown;
53
- }
54
-
55
- export interface ObjectListParams {
56
- prefix?: string;
57
- maxKeys?: number;
58
- max_keys?: number;
59
- marker?: string;
60
- /** @deprecated use maxKeys/max_keys; kept as a convenience alias. */
61
- limit?: number;
62
- /** @deprecated use marker; kept as a convenience alias. */
63
- cursor?: string;
64
- }
65
-
66
- export interface PresignParams {
67
- key: string;
68
- method?: "GET" | "PUT";
69
- expiresIn?: number;
70
- expires_in?: number;
71
- /** @deprecated use method; kept as a convenience alias. */
72
- operation?: "get" | "put";
73
- /** @deprecated use expiresIn/expires_in; kept as a convenience alias. */
74
- expiresInSec?: number;
75
- /** @deprecated use expiresIn/expires_in; kept as a convenience alias. */
76
- expires_in_sec?: number;
77
- contentType?: string;
78
- content_type?: string;
79
- }
80
-
81
- // ── Helpers ───────────────────────────────────────────────────────────────────
82
-
83
- function unwrap<T>(payload: unknown): T {
84
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
85
- return (payload as { data: T }).data;
86
- }
87
- return payload as T;
88
- }
89
-
90
- function listItems<T>(
91
- payload: unknown,
92
- candidateKeys: string[] = ["data", "buckets", "objects", "items"],
93
- ): T[] {
94
- if (Array.isArray(payload)) return payload;
95
- if (!payload || typeof payload !== "object") return [];
96
- const p = payload as Record<string, unknown>;
97
- if (Array.isArray(p.data)) return p.data as T[];
98
- for (const key of candidateKeys) {
99
- if (Array.isArray(p[key])) return p[key] as T[];
100
- }
101
- return [];
102
- }
103
-
104
- function stripUndefined(
105
- input: Record<string, unknown>,
106
- ): Record<string, unknown> {
107
- return Object.fromEntries(
108
- Object.entries(input).filter(([, v]) => v !== undefined),
109
- );
110
- }
111
-
112
- // ── Main resource ─────────────────────────────────────────────────────────────
113
-
114
- export class Storage {
115
- constructor(private readonly http: HttpClient) {}
116
-
117
- // ── Buckets ────────────────────────────────────────────────────────────────
118
-
119
- async listBuckets(): Promise<BucketData[]> {
120
- const data = await this.http.get<unknown>("/storage/buckets");
121
- return listItems<BucketData>(data);
122
- }
123
-
124
- async createBucket(params: BucketCreateParams): Promise<BucketData> {
125
- const { name, public: isPublic, visibility, ...rest } = params;
126
- const body = stripUndefined({
127
- name,
128
- visibility:
129
- visibility ??
130
- (isPublic === undefined ? undefined : isPublic ? "public" : "private"),
131
- ...rest,
132
- });
133
- const data = await this.http.post<unknown>("/storage/buckets", body);
134
- return unwrap<BucketData>(data);
135
- }
136
-
137
- async getBucket(bucketId: string): Promise<BucketData> {
138
- const data = await this.http.get<unknown>(`/storage/buckets/${bucketId}`);
139
- return unwrap<BucketData>(data);
140
- }
141
-
142
- async deleteBucket(bucketId: string): Promise<void> {
143
- await this.http.delete<unknown>(`/storage/buckets/${bucketId}`);
144
- }
145
-
146
- // ── Objects ────────────────────────────────────────────────────────────────
147
-
148
- async listObjects(
149
- bucketId: string,
150
- params: ObjectListParams = {},
151
- ): Promise<StorageObjectData[]> {
152
- const query = stripUndefined({
153
- prefix: params.prefix,
154
- max_keys: params.max_keys ?? params.maxKeys ?? params.limit,
155
- marker: params.marker ?? params.cursor,
156
- }) as Record<string, string | number | boolean | undefined>;
157
- const data = await this.http.get<unknown>(
158
- `/storage/buckets/${bucketId}/objects`,
159
- query,
160
- );
161
- return listItems<StorageObjectData>(data, ["data", "objects", "items"]);
162
- }
163
-
164
- async putObject(
165
- bucketId: string,
166
- key: string,
167
- content: Uint8Array | ArrayBuffer,
168
- opts: { contentType?: string } = {},
169
- ): Promise<Record<string, unknown>> {
170
- const contentType = opts.contentType ?? "application/octet-stream";
171
- const data = await this.http.request<unknown>(
172
- `/storage/buckets/${bucketId}/objects/${key}`,
173
- {
174
- method: "PUT",
175
- body: content,
176
- headers: { "Content-Type": contentType },
177
- },
178
- );
179
- return (data ?? {}) as Record<string, unknown>;
180
- }
181
-
182
- async getObject(bucketId: string, key: string): Promise<Uint8Array> {
183
- return this.http.getBinary(`/storage/buckets/${bucketId}/objects/${key}`);
184
- }
185
-
186
- async deleteObject(bucketId: string, key: string): Promise<void> {
187
- await this.http.delete<unknown>(
188
- `/storage/buckets/${bucketId}/objects/${key}`,
189
- );
190
- }
191
-
192
- // ── Presigned URLs ─────────────────────────────────────────────────────────
193
-
194
- async presign(
195
- bucketId: string,
196
- params: PresignParams,
197
- ): Promise<PresignResult> {
198
- const operationMethod =
199
- params.operation === "put"
200
- ? "PUT"
201
- : params.operation === "get"
202
- ? "GET"
203
- : undefined;
204
-
205
- const body = stripUndefined({
206
- key: params.key,
207
- method: params.method ?? operationMethod ?? "GET",
208
- expires_in:
209
- params.expiresIn ??
210
- params.expires_in ??
211
- params.expiresInSec ??
212
- params.expires_in_sec ??
213
- 3600,
214
- });
215
- const data = await this.http.post<unknown>(
216
- `/storage/buckets/${bucketId}/presign`,
217
- body,
218
- );
219
- return unwrap<PresignResult>(data);
220
- }
221
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * TenantEvents — tenant-scoped SSE event stream.
3
- * Corresponds to: GET /api/v1/events/stream?types=sandbox.*,webhook.delivered
4
- */
5
-
6
- import type { HttpClient } from "../http.js";
7
-
8
- // ── Resource shapes ──────────────────────────────────────────────────────────
9
-
10
- export interface TenantStreamEvent {
11
- type: string;
12
- [key: string]: unknown;
13
- }
14
-
15
- // ── Main resource ─────────────────────────────────────────────────────────────
16
-
17
- export class TenantEvents {
18
- constructor(private readonly http: HttpClient) {}
19
-
20
- /**
21
- * GET /api/v1/events/stream — tenant-scoped SSE event stream.
22
- *
23
- * @param types - Event type globs to filter. Accepts a comma-separated string
24
- * or an array, e.g. `["sandbox.*", "webhook.delivered"]`.
25
- * Omit to receive all event types.
26
- */
27
- stream(types?: string | string[]): AsyncIterableIterator<TenantStreamEvent> {
28
- const typesParam = Array.isArray(types) ? types.join(",") : types;
29
- const query = typesParam ? `?types=${encodeURIComponent(typesParam)}` : "";
30
- return this.http.stream<TenantStreamEvent>(`/events/stream${query}`);
31
- }
32
- }
@@ -1,148 +0,0 @@
1
- /**
2
- * Tenant — current tenant info and plan/usage.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Resource shapes ──────────────────────────────────────────────────────────
8
-
9
- export interface TenantPlan {
10
- id?: string;
11
- name?: string;
12
- limits?: Record<string, unknown>;
13
- usage?: Record<string, unknown>;
14
- [key: string]: unknown;
15
- }
16
-
17
- export interface PreviewDomainData {
18
- preview_domain?: string | null;
19
- default_domain?: string;
20
- status?: string;
21
- dns_status?: string;
22
- cname_target?: string | null;
23
- dns_instructions?: unknown;
24
- [key: string]: unknown;
25
- }
26
-
27
- export interface TenantBrandingUpdateParams {
28
- product_name?: string;
29
- logo_url?: string;
30
- support_url?: string;
31
- support_email?: string;
32
- primary_color?: string;
33
- background_color?: string;
34
- [key: string]: unknown;
35
- }
36
-
37
- export type BrandingData = TenantBrandingUpdateParams;
38
-
39
- // ── Helpers ───────────────────────────────────────────────────────────────────
40
-
41
- function unwrap<T>(payload: unknown): T {
42
- if (payload && typeof payload === "object") {
43
- const p = payload as Record<string, unknown>;
44
- for (const k of ["data", "tenant", "branding", "items"]) {
45
- if (k in p) return p[k] as T;
46
- }
47
- }
48
- return payload as T;
49
- }
50
-
51
- // ── Sub-resources ────────────────────────────────────────────────────────────
52
-
53
- class PreviewDomain {
54
- constructor(private readonly http: HttpClient) {}
55
-
56
- /** Get the tenant's white-label preview domain settings. */
57
- async get(): Promise<PreviewDomainData> {
58
- const data = await this.http.get<unknown>("/tenant/preview-domain");
59
- return unwrap<PreviewDomainData>(data);
60
- }
61
-
62
- /** Set the tenant's white-label preview domain. */
63
- async set(domain: string): Promise<PreviewDomainData> {
64
- const data = await this.http.put<unknown>("/tenant/preview-domain", {
65
- preview_domain: domain,
66
- });
67
- return unwrap<PreviewDomainData>(data);
68
- }
69
-
70
- /** Re-run DNS verification for the configured preview domain. */
71
- async verify(): Promise<PreviewDomainData> {
72
- const data = await this.http.post<unknown>(
73
- "/tenant/preview-domain/verify",
74
- {},
75
- );
76
- return unwrap<PreviewDomainData>(data);
77
- }
78
-
79
- /** Remove the tenant's custom preview domain. */
80
- async delete(): Promise<void> {
81
- await this.http.delete<unknown>("/tenant/preview-domain");
82
- }
83
- }
84
-
85
- class Branding {
86
- constructor(private readonly http: HttpClient) {}
87
-
88
- /** Get tenant branding used by white-label hosted surfaces. */
89
- async get(): Promise<BrandingData> {
90
- const data = await this.http.get<unknown>("/tenant/branding");
91
- return unwrap<BrandingData>(data);
92
- }
93
-
94
- /** Update tenant branding used by white-label hosted surfaces. */
95
- async set(params: TenantBrandingUpdateParams): Promise<BrandingData> {
96
- const body = Object.fromEntries(
97
- Object.entries(params).filter(([, v]) => v !== undefined),
98
- );
99
- const data = await this.http.put<unknown>("/tenant/branding", {
100
- branding: body,
101
- });
102
- return unwrap<BrandingData>(data);
103
- }
104
-
105
- /** Reset tenant branding to platform defaults. */
106
- async delete(): Promise<void> {
107
- await this.http.delete<unknown>("/tenant/branding");
108
- }
109
- }
110
-
111
- // ── Main resource ─────────────────────────────────────────────────────────────
112
-
113
- export class Tenant {
114
- private readonly http: HttpClient;
115
- readonly preview_domain: PreviewDomain;
116
- readonly branding: Branding;
117
-
118
- /** camelCase alias for SDK consumers that avoid snake_case properties. */
119
- readonly previewDomain: PreviewDomain;
120
-
121
- constructor(http: HttpClient) {
122
- this.http = http;
123
- this.preview_domain = new PreviewDomain(http);
124
- this.previewDomain = this.preview_domain;
125
- this.branding = new Branding(http);
126
- }
127
-
128
- /** Get the current tenant's plan, limits, and live usage counters. */
129
- async current(): Promise<TenantPlan> {
130
- const data = await this.http.get<unknown>("/tenant/plan");
131
- return unwrap<TenantPlan>(data);
132
- }
133
-
134
- /** Convenience alias for `tenant.branding.get()`. */
135
- async getBranding(): Promise<BrandingData> {
136
- return this.branding.get();
137
- }
138
-
139
- /** Convenience alias for `tenant.branding.set(...)`. */
140
- async setBranding(params: TenantBrandingUpdateParams): Promise<BrandingData> {
141
- return this.branding.set(params);
142
- }
143
-
144
- /** Convenience alias for `tenant.branding.delete()`. */
145
- async deleteBranding(): Promise<void> {
146
- await this.branding.delete();
147
- }
148
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * Usage — per-session metering, summary, and reports.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Resource shapes ──────────────────────────────────────────────────────────
8
-
9
- export interface UsageSummary {
10
- period_start?: string;
11
- period_end?: string;
12
- total_credits?: number;
13
- [key: string]: unknown;
14
- }
15
-
16
- export interface UsageSession {
17
- id?: string;
18
- computer_id?: string;
19
- started_at?: string;
20
- ended_at?: string;
21
- credits_used?: number;
22
- [key: string]: unknown;
23
- }
24
-
25
- // ── Request payloads ─────────────────────────────────────────────────────────
26
-
27
- export interface UsageSessionsParams {
28
- computer_id?: string;
29
- limit?: number;
30
- cursor?: string;
31
- [key: string]: string | number | boolean | undefined;
32
- }
33
-
34
- export interface UsageReportParams extends UsageSessionsParams {
35
- period_start?: string;
36
- period_end?: string;
37
- }
38
-
39
- // ── Helpers ───────────────────────────────────────────────────────────────────
40
-
41
- function unwrap<T>(payload: unknown): T {
42
- if (payload && typeof payload === "object") {
43
- const p = payload as Record<string, unknown>;
44
- for (const k of ["data", "usage", "sessions", "summary", "items"]) {
45
- if (k in p) return p[k] as T;
46
- }
47
- }
48
- return payload as T;
49
- }
50
-
51
- function stripUndefined(
52
- input: Record<string, unknown>,
53
- ): Record<string, string | number | boolean | undefined> {
54
- return Object.fromEntries(
55
- Object.entries(input).filter(([, v]) => v !== undefined),
56
- ) as Record<string, string | number | boolean | undefined>;
57
- }
58
-
59
- // ── Main resource ─────────────────────────────────────────────────────────────
60
-
61
- export class Usage {
62
- constructor(private readonly http: HttpClient) {}
63
-
64
- /** Get the current period usage summary. */
65
- async current(): Promise<UsageSummary> {
66
- const data = await this.http.get<unknown>("/usage/summary");
67
- return unwrap<UsageSummary>(data);
68
- }
69
-
70
- /** List per-session metering events. */
71
- async sessions(params: UsageSessionsParams = {}): Promise<UsageSession[]> {
72
- const query = stripUndefined(params as Record<string, unknown>);
73
- const data = await this.http.get<unknown>("/usage/sessions", query);
74
- const result = unwrap<UsageSession[] | unknown>(data);
75
- if (Array.isArray(result)) return result;
76
- return [];
77
- }
78
-
79
- /** Get a usage report for a period. */
80
- async report(params: UsageReportParams = {}): Promise<UsageSummary> {
81
- const query = stripUndefined(params as Record<string, unknown>);
82
- const data = await this.http.get<unknown>("/usage/summary", query);
83
- return unwrap<UsageSummary>(data);
84
- }
85
- }