@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.
- package/README.md +75 -3
- package/dist/index.d.ts +323 -175
- package/dist/index.js +441 -386
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/src/client.ts +0 -293
- package/src/errors.ts +0 -136
- package/src/http.test.ts +0 -374
- package/src/http.ts +0 -390
- package/src/index.ts +0 -564
- package/src/resources/admin.ts +0 -359
- package/src/resources/analytics.ts +0 -60
- package/src/resources/api-keys.ts +0 -135
- package/src/resources/audit-log.ts +0 -64
- package/src/resources/benchmarks.ts +0 -104
- package/src/resources/builder-sessions.ts +0 -75
- package/src/resources/channels.ts +0 -143
- package/src/resources/checkpoints.ts +0 -225
- package/src/resources/command-center.ts +0 -73
- package/src/resources/community.ts +0 -103
- package/src/resources/completions.ts +0 -104
- package/src/resources/computer-auto-stop.ts +0 -43
- package/src/resources/computer-env.ts +0 -76
- package/src/resources/computer-logs.ts +0 -50
- package/src/resources/computer-osa.ts +0 -76
- package/src/resources/computer-ports.ts +0 -91
- package/src/resources/computer-terminal.ts +0 -61
- package/src/resources/computer-volumes.ts +0 -64
- package/src/resources/computer.ts +0 -551
- package/src/resources/computers.ts +0 -75
- package/src/resources/credits.ts +0 -43
- package/src/resources/cron-jobs.ts +0 -191
- package/src/resources/custom_domains.ts +0 -123
- package/src/resources/dashboard.ts +0 -49
- package/src/resources/databases.ts +0 -218
- package/src/resources/deployments.test.ts +0 -194
- package/src/resources/deployments.ts +0 -1060
- package/src/resources/desktop.ts +0 -134
- package/src/resources/docker-deploy.test.ts +0 -102
- package/src/resources/docker-deploy.ts +0 -183
- package/src/resources/egress.test.ts +0 -318
- package/src/resources/egressAudit.ts +0 -245
- package/src/resources/egressNetwork.ts +0 -450
- package/src/resources/egressSecrets.ts +0 -577
- package/src/resources/email.ts +0 -212
- package/src/resources/embeddings.ts +0 -36
- package/src/resources/events.ts +0 -296
- package/src/resources/exec.ts +0 -319
- package/src/resources/external-keys.ts +0 -79
- package/src/resources/files.test.ts +0 -339
- package/src/resources/files.ts +0 -220
- package/src/resources/flat-custom-domains.ts +0 -127
- package/src/resources/functions.ts +0 -178
- package/src/resources/governance.test.ts +0 -355
- package/src/resources/governance.ts +0 -528
- package/src/resources/health-checks.ts +0 -165
- package/src/resources/integrations.ts +0 -183
- package/src/resources/mcp.ts +0 -70
- package/src/resources/models.ts +0 -45
- package/src/resources/network_policy.ts +0 -73
- package/src/resources/open-computers/agents.ts +0 -91
- package/src/resources/open-computers/apps.ts +0 -102
- package/src/resources/open-computers/clusters.ts +0 -88
- package/src/resources/open-computers/desktop.ts +0 -34
- package/src/resources/open-computers/files.ts +0 -97
- package/src/resources/open-computers/hosts.ts +0 -85
- package/src/resources/open-computers/index.ts +0 -98
- package/src/resources/open-computers/jobs.ts +0 -75
- package/src/resources/open-computers/open_computers.test.ts +0 -288
- package/src/resources/open-computers/secrets.ts +0 -115
- package/src/resources/open-computers/terminal.ts +0 -33
- package/src/resources/open-computers/tunnels.ts +0 -87
- package/src/resources/open-computers/types.ts +0 -343
- package/src/resources/open-computers/workspaces.ts +0 -135
- package/src/resources/org-invites.ts +0 -189
- package/src/resources/phase1.test.ts +0 -187
- package/src/resources/project-auth.ts +0 -142
- package/src/resources/project-integrations.ts +0 -133
- package/src/resources/provider-defaults.ts +0 -89
- package/src/resources/quotas.ts +0 -77
- package/src/resources/regions.ts +0 -94
- package/src/resources/sandbox-processes.ts +0 -112
- package/src/resources/sandbox-shares.ts +0 -83
- package/src/resources/sandbox-templates.ts +0 -195
- package/src/resources/sandboxes.live.test.ts +0 -92
- package/src/resources/sandboxes.test.ts +0 -653
- package/src/resources/sandboxes.ts +0 -1433
- package/src/resources/settings.ts +0 -143
- package/src/resources/snapshots-standalone.ts +0 -51
- package/src/resources/storage.ts +0 -221
- package/src/resources/tenant-events.ts +0 -32
- package/src/resources/tenant.ts +0 -148
- package/src/resources/usage.ts +0 -85
- package/src/resources/volumes.ts +0 -117
- package/src/resources/webhooks.ts +0 -224
- package/src/resources/workspace-invites.ts +0 -188
- package/src/resources/workspace-members.test.ts +0 -121
- package/src/resources/workspace-members.ts +0 -143
- package/src/resources/workspaces.ts +0 -285
- package/src/types.ts +0 -463
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miosa/sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "TypeScript SDK for the MIOSA API — cloud VM desktop infrastructure for AI agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "MIOSA <hello@miosa.ai>",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
32
|
-
"src",
|
|
33
32
|
"README.md"
|
|
34
33
|
],
|
|
35
34
|
"scripts": {
|
package/src/client.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from "./http.js";
|
|
2
|
-
import { Admin } from "./resources/admin.js";
|
|
3
|
-
import { Analytics } from "./resources/analytics.js";
|
|
4
|
-
import { ApiKeys } from "./resources/api-keys.js";
|
|
5
|
-
import { AuditLog } from "./resources/audit-log.js";
|
|
6
|
-
import { Benchmarks } from "./resources/benchmarks.js";
|
|
7
|
-
import { BuilderSessions } from "./resources/builder-sessions.js";
|
|
8
|
-
import { Channels } from "./resources/channels.js";
|
|
9
|
-
import { CommandCenter } from "./resources/command-center.js";
|
|
10
|
-
import { Community } from "./resources/community.js";
|
|
11
|
-
import { Completions } from "./resources/completions.js";
|
|
12
|
-
import { Computers } from "./resources/computers.js";
|
|
13
|
-
import { Credits } from "./resources/credits.js";
|
|
14
|
-
import { CronJobs } from "./resources/cron-jobs.js";
|
|
15
|
-
import { Dashboard } from "./resources/dashboard.js";
|
|
16
|
-
import { Databases } from "./resources/databases.js";
|
|
17
|
-
import { Deployments } from "./resources/deployments.js";
|
|
18
|
-
import { DockerDeploy } from "./resources/docker-deploy.js";
|
|
19
|
-
import { EgressAudit } from "./resources/egressAudit.js";
|
|
20
|
-
import { EgressNetwork } from "./resources/egressNetwork.js";
|
|
21
|
-
import { EgressSecrets } from "./resources/egressSecrets.js";
|
|
22
|
-
import { Email } from "./resources/email.js";
|
|
23
|
-
import { Embeddings } from "./resources/embeddings.js";
|
|
24
|
-
import { ExternalKeys } from "./resources/external-keys.js";
|
|
25
|
-
import { FlatCustomDomains } from "./resources/flat-custom-domains.js";
|
|
26
|
-
import { Functions } from "./resources/functions.js";
|
|
27
|
-
import { HealthChecks } from "./resources/health-checks.js";
|
|
28
|
-
import { Integrations } from "./resources/integrations.js";
|
|
29
|
-
import { Mcp } from "./resources/mcp.js";
|
|
30
|
-
import { Models } from "./resources/models.js";
|
|
31
|
-
import { OpenComputers } from "./resources/open-computers/index.js";
|
|
32
|
-
import { ProjectAuth } from "./resources/project-auth.js";
|
|
33
|
-
import { ProjectIntegrations } from "./resources/project-integrations.js";
|
|
34
|
-
import { ProviderDefaults } from "./resources/provider-defaults.js";
|
|
35
|
-
import { Regions } from "./resources/regions.js";
|
|
36
|
-
import { Sandboxes } from "./resources/sandboxes.js";
|
|
37
|
-
import { SandboxTemplates } from "./resources/sandbox-templates.js";
|
|
38
|
-
import { Settings } from "./resources/settings.js";
|
|
39
|
-
import { SnapshotsStandalone } from "./resources/snapshots-standalone.js";
|
|
40
|
-
import { Storage } from "./resources/storage.js";
|
|
41
|
-
import { OrgInvites } from "./resources/org-invites.js";
|
|
42
|
-
import { Tenant } from "./resources/tenant.js";
|
|
43
|
-
import { Usage } from "./resources/usage.js";
|
|
44
|
-
import { Volumes } from "./resources/volumes.js";
|
|
45
|
-
import { Webhooks } from "./resources/webhooks.js";
|
|
46
|
-
import { WorkspaceInvites } from "./resources/workspace-invites.js";
|
|
47
|
-
import { WorkspaceMembers } from "./resources/workspace-members.js";
|
|
48
|
-
import type { MiosaClientConfig } from "./types.js";
|
|
49
|
-
|
|
50
|
-
const DEFAULT_BASE_URL = "https://api.miosa.ai/api/v1";
|
|
51
|
-
const DEFAULT_TIMEOUT = 30_000;
|
|
52
|
-
const DEFAULT_MAX_RETRIES = 3;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The top-level MIOSA client.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { Miosa } from '@miosa/sdk';
|
|
60
|
-
*
|
|
61
|
-
* const miosa = new Miosa({ apiKey: 'msk_u_...' });
|
|
62
|
-
*
|
|
63
|
-
* const computer = await miosa.computers.create({ name: 'my-agent' });
|
|
64
|
-
* await computer.start();
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export class Miosa {
|
|
68
|
-
/** Per-workspace user roster — list, add, update role, remove. */
|
|
69
|
-
readonly workspaceMembers: WorkspaceMembers;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Workspace invite flow — create invite, list, revoke, preview, accept.
|
|
73
|
-
* Sending to an email already in the org adds the user directly.
|
|
74
|
-
*/
|
|
75
|
-
readonly workspaceInvites: WorkspaceInvites;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Org invite flow — create invite, list, revoke, preview, accept.
|
|
79
|
-
* Requires admin/owner role for write operations.
|
|
80
|
-
*/
|
|
81
|
-
readonly orgInvites: OrgInvites;
|
|
82
|
-
|
|
83
|
-
/** Current tenant plan, limits, and live usage counters. */
|
|
84
|
-
readonly tenant: Tenant;
|
|
85
|
-
|
|
86
|
-
/** Datacenter regions, compute sizes, pricing, community templates. */
|
|
87
|
-
readonly regions: Regions;
|
|
88
|
-
|
|
89
|
-
/** Tenant settings — workspace config, branding, BYOK provider keys. */
|
|
90
|
-
readonly settings: Settings;
|
|
91
|
-
|
|
92
|
-
/** Aggregated platform dashboard and health overview. */
|
|
93
|
-
readonly dashboard: Dashboard;
|
|
94
|
-
|
|
95
|
-
/** Admin-scoped analytics overview and timeseries metrics. */
|
|
96
|
-
readonly analytics: Analytics;
|
|
97
|
-
|
|
98
|
-
/** Admin-scoped audit log event stream. */
|
|
99
|
-
readonly auditLog: AuditLog;
|
|
100
|
-
|
|
101
|
-
/** Current-period usage summary, sessions, and report queries. */
|
|
102
|
-
readonly usage: Usage;
|
|
103
|
-
|
|
104
|
-
/** Notification channels — Slack, Discord, email, etc. */
|
|
105
|
-
readonly channels: Channels;
|
|
106
|
-
|
|
107
|
-
/** OAuth integrations — GitHub, Slack, Linear, Discord. */
|
|
108
|
-
readonly integrations: Integrations;
|
|
109
|
-
|
|
110
|
-
/** Per-project integrations (Stripe, Resend, Twilio, etc.). */
|
|
111
|
-
readonly projectIntegrations: ProjectIntegrations;
|
|
112
|
-
|
|
113
|
-
/** Built-in auth for generated apps inside sandboxes/deployments. */
|
|
114
|
-
readonly projectAuth: ProjectAuth;
|
|
115
|
-
|
|
116
|
-
/** BYOK encrypted per-user provider keys. */
|
|
117
|
-
readonly externalKeys: ExternalKeys;
|
|
118
|
-
|
|
119
|
-
/** Model Context Protocol — JSON-RPC dispatch + streaming channel. */
|
|
120
|
-
readonly mcp: Mcp;
|
|
121
|
-
|
|
122
|
-
/** Computer management — create, list, get, delete. */
|
|
123
|
-
readonly computers: Computers;
|
|
124
|
-
|
|
125
|
-
/** Sandboxes — native code-execution environments under `/sandboxes`. */
|
|
126
|
-
readonly sandboxes: Sandboxes;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Deployments — publish from a sandbox to a stable production URL.
|
|
130
|
-
* Versions, releases, rollback, custom domains.
|
|
131
|
-
*/
|
|
132
|
-
readonly deployments: Deployments;
|
|
133
|
-
|
|
134
|
-
/** Docker Deploy appliance hosts — one always-on workspace host, many apps. */
|
|
135
|
-
readonly dockerDeploy: DockerDeploy;
|
|
136
|
-
|
|
137
|
-
/** Credit balance and usage. */
|
|
138
|
-
readonly credits: Credits;
|
|
139
|
-
|
|
140
|
-
/** Admin surface (`/api/v1/admin/*`) — requires an admin credential. */
|
|
141
|
-
readonly admin: Admin;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* OpenComputers — BYOC host management: register your own machines and use
|
|
145
|
-
* them like cloud computers (jobs, files, tunnels, AI agents, clusters).
|
|
146
|
-
*/
|
|
147
|
-
readonly openComputers: OpenComputers;
|
|
148
|
-
|
|
149
|
-
/** Managed Postgres databases — lifecycle, credentials, logs. */
|
|
150
|
-
readonly databases: Databases;
|
|
151
|
-
|
|
152
|
-
/** Managed object storage — buckets, objects, presigned URLs. */
|
|
153
|
-
readonly storage: Storage;
|
|
154
|
-
|
|
155
|
-
/** Persistent block storage volumes. */
|
|
156
|
-
readonly volumes: Volumes;
|
|
157
|
-
|
|
158
|
-
/** Tenant-scoped custom domains across all resources. */
|
|
159
|
-
readonly customDomains: FlatCustomDomains;
|
|
160
|
-
|
|
161
|
-
/** Serverless edge functions — CRUD and invoke. */
|
|
162
|
-
readonly functions: Functions;
|
|
163
|
-
|
|
164
|
-
/** Scheduled cron jobs — CRUD, pause/resume, execution history. */
|
|
165
|
-
readonly cronJobs: CronJobs;
|
|
166
|
-
|
|
167
|
-
/** Uptime health checks. */
|
|
168
|
-
readonly healthChecks: HealthChecks;
|
|
169
|
-
|
|
170
|
-
/** Outgoing tenant webhooks — CRUD, test, delivery history. */
|
|
171
|
-
readonly webhooks: Webhooks;
|
|
172
|
-
|
|
173
|
-
/** Sandbox templates — CRUD, build-spec schema, builds. */
|
|
174
|
-
readonly sandboxTemplates: SandboxTemplates;
|
|
175
|
-
|
|
176
|
-
/** API key management — list, create, delete. */
|
|
177
|
-
readonly apiKeys: ApiKeys;
|
|
178
|
-
|
|
179
|
-
// ── P3 / P4 resources ──────────────────────────────────────────────────────
|
|
180
|
-
|
|
181
|
-
/** Available LLM models via the intelligence gateway. */
|
|
182
|
-
readonly models: Models;
|
|
183
|
-
|
|
184
|
-
/** OpenAI-compatible text + chat completions (supports SSE streaming). */
|
|
185
|
-
readonly completions: Completions;
|
|
186
|
-
|
|
187
|
-
/** OpenAI-compatible embedding vectors. */
|
|
188
|
-
readonly embeddings: Embeddings;
|
|
189
|
-
|
|
190
|
-
/** Admin: fleet-wide + per-tenant LLM provider routing defaults. */
|
|
191
|
-
readonly providerDefaults: ProviderDefaults;
|
|
192
|
-
|
|
193
|
-
/** Admin: trigger + inspect platform benchmark runs. */
|
|
194
|
-
readonly benchmarks: Benchmarks;
|
|
195
|
-
|
|
196
|
-
/** Read-only views of the Optimal AI agent fleet. */
|
|
197
|
-
readonly commandCenter: CommandCenter;
|
|
198
|
-
|
|
199
|
-
/** Community template + agent catalog. */
|
|
200
|
-
readonly community: Community;
|
|
201
|
-
|
|
202
|
-
/** Admin email campaigns, templates, and inbox. */
|
|
203
|
-
readonly email: Email;
|
|
204
|
-
|
|
205
|
-
/** Builder UI session metadata. */
|
|
206
|
-
readonly builderSessions: BuilderSessions;
|
|
207
|
-
|
|
208
|
-
/** Admin: fleet-wide snapshot index. */
|
|
209
|
-
readonly snapshotsStandalone: SnapshotsStandalone;
|
|
210
|
-
|
|
211
|
-
// ── Egress (security) namespaces ───────────────────────────────────────────
|
|
212
|
-
|
|
213
|
-
/** Encrypted secret + OAuth credential vault (`/egress/secrets`). */
|
|
214
|
-
readonly secrets: EgressSecrets;
|
|
215
|
-
|
|
216
|
-
/** Egress allowlist + policies — host-level firewall (`/egress/policies`). */
|
|
217
|
-
readonly network: EgressNetwork;
|
|
218
|
-
|
|
219
|
-
/** Egress audit log — every outbound request, paginated query + tail. */
|
|
220
|
-
readonly audit: EgressAudit;
|
|
221
|
-
|
|
222
|
-
private readonly http: HttpClient;
|
|
223
|
-
|
|
224
|
-
constructor(config: MiosaClientConfig) {
|
|
225
|
-
if (!config.apiKey) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
'Miosa: apiKey is required. Pass { apiKey: "msk_u_..." } or set MIOSA_API_KEY.',
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (!config.apiKey.startsWith("msk_")) {
|
|
232
|
-
// Soft warning — allow non-standard keys in tests / self-hosted
|
|
233
|
-
console.warn(
|
|
234
|
-
'[miosa] Warning: API key does not start with "msk_". Double-check your key.',
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
this.http = new HttpClient({
|
|
239
|
-
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
240
|
-
apiKey: config.apiKey,
|
|
241
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
242
|
-
maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
this.workspaceMembers = new WorkspaceMembers(this.http);
|
|
246
|
-
this.workspaceInvites = new WorkspaceInvites(this.http);
|
|
247
|
-
this.orgInvites = new OrgInvites(this.http);
|
|
248
|
-
this.tenant = new Tenant(this.http);
|
|
249
|
-
this.regions = new Regions(this.http);
|
|
250
|
-
this.settings = new Settings(this.http);
|
|
251
|
-
this.dashboard = new Dashboard(this.http);
|
|
252
|
-
this.analytics = new Analytics(this.http);
|
|
253
|
-
this.auditLog = new AuditLog(this.http);
|
|
254
|
-
this.usage = new Usage(this.http);
|
|
255
|
-
this.channels = new Channels(this.http);
|
|
256
|
-
this.integrations = new Integrations(this.http);
|
|
257
|
-
this.projectIntegrations = new ProjectIntegrations(this.http);
|
|
258
|
-
this.projectAuth = new ProjectAuth(this.http);
|
|
259
|
-
this.externalKeys = new ExternalKeys(this.http);
|
|
260
|
-
this.mcp = new Mcp(this.http);
|
|
261
|
-
this.computers = new Computers(this.http);
|
|
262
|
-
this.sandboxes = new Sandboxes(this.http);
|
|
263
|
-
this.deployments = new Deployments(this.http);
|
|
264
|
-
this.dockerDeploy = new DockerDeploy(this.http);
|
|
265
|
-
this.credits = new Credits(this.http);
|
|
266
|
-
this.admin = new Admin(this.http);
|
|
267
|
-
this.openComputers = new OpenComputers(this.http);
|
|
268
|
-
this.databases = new Databases(this.http);
|
|
269
|
-
this.storage = new Storage(this.http);
|
|
270
|
-
this.volumes = new Volumes(this.http);
|
|
271
|
-
this.customDomains = new FlatCustomDomains(this.http);
|
|
272
|
-
this.functions = new Functions(this.http);
|
|
273
|
-
this.cronJobs = new CronJobs(this.http);
|
|
274
|
-
this.healthChecks = new HealthChecks(this.http);
|
|
275
|
-
this.webhooks = new Webhooks(this.http);
|
|
276
|
-
this.sandboxTemplates = new SandboxTemplates(this.http);
|
|
277
|
-
this.apiKeys = new ApiKeys(this.http);
|
|
278
|
-
this.models = new Models(this.http);
|
|
279
|
-
this.completions = new Completions(this.http);
|
|
280
|
-
this.embeddings = new Embeddings(this.http);
|
|
281
|
-
this.providerDefaults = new ProviderDefaults(this.http);
|
|
282
|
-
this.benchmarks = new Benchmarks(this.http);
|
|
283
|
-
this.commandCenter = new CommandCenter(this.http);
|
|
284
|
-
this.community = new Community(this.http);
|
|
285
|
-
this.email = new Email(this.http);
|
|
286
|
-
this.builderSessions = new BuilderSessions(this.http);
|
|
287
|
-
this.snapshotsStandalone = new SnapshotsStandalone(this.http);
|
|
288
|
-
// Egress (security) namespaces
|
|
289
|
-
this.secrets = new EgressSecrets(this.http);
|
|
290
|
-
this.network = new EgressNetwork(this.http);
|
|
291
|
-
this.audit = new EgressAudit(this.http);
|
|
292
|
-
}
|
|
293
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
export interface MiosaErrorBody {
|
|
2
|
-
error?: {
|
|
3
|
-
code?: string;
|
|
4
|
-
message?: string;
|
|
5
|
-
details?: unknown;
|
|
6
|
-
};
|
|
7
|
-
message?: string;
|
|
8
|
-
code?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class MiosaError extends Error {
|
|
12
|
-
readonly status: number;
|
|
13
|
-
readonly code: string;
|
|
14
|
-
readonly details: unknown;
|
|
15
|
-
readonly requestId: string | undefined;
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
message: string,
|
|
19
|
-
status: number,
|
|
20
|
-
code: string,
|
|
21
|
-
details?: unknown,
|
|
22
|
-
requestId?: string,
|
|
23
|
-
) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.name = "MiosaError";
|
|
26
|
-
this.status = status;
|
|
27
|
-
this.code = code;
|
|
28
|
-
this.details = details;
|
|
29
|
-
this.requestId = requestId;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static fromResponse(
|
|
33
|
-
status: number,
|
|
34
|
-
body: MiosaErrorBody,
|
|
35
|
-
requestId?: string,
|
|
36
|
-
): MiosaError {
|
|
37
|
-
const message = body.error?.message ?? body.message ?? `HTTP ${status}`;
|
|
38
|
-
const code = body.error?.code ?? body.code ?? "UNKNOWN_ERROR";
|
|
39
|
-
const details = body.error?.details;
|
|
40
|
-
|
|
41
|
-
if (status === 401 || status === 403) {
|
|
42
|
-
return new AuthError(message, status, code, details, requestId);
|
|
43
|
-
}
|
|
44
|
-
if (status === 404) {
|
|
45
|
-
return new NotFoundError(message, code, details, requestId);
|
|
46
|
-
}
|
|
47
|
-
if (status === 429) {
|
|
48
|
-
return new RateLimitError(message, details, requestId);
|
|
49
|
-
}
|
|
50
|
-
if (status === 402) {
|
|
51
|
-
return new InsufficientCreditsError(message, details, requestId);
|
|
52
|
-
}
|
|
53
|
-
if (status >= 400 && status < 500) {
|
|
54
|
-
return new ValidationError(message, status, code, details, requestId);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return new MiosaError(message, status, code, details, requestId);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class AuthError extends MiosaError {
|
|
62
|
-
constructor(
|
|
63
|
-
message: string,
|
|
64
|
-
status: number = 401,
|
|
65
|
-
code: string = "UNAUTHORIZED",
|
|
66
|
-
details?: unknown,
|
|
67
|
-
requestId?: string,
|
|
68
|
-
) {
|
|
69
|
-
super(message, status, code, details, requestId);
|
|
70
|
-
this.name = "AuthError";
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class NotFoundError extends MiosaError {
|
|
75
|
-
constructor(
|
|
76
|
-
message: string,
|
|
77
|
-
code: string = "NOT_FOUND",
|
|
78
|
-
details?: unknown,
|
|
79
|
-
requestId?: string,
|
|
80
|
-
) {
|
|
81
|
-
super(message, 404, code, details, requestId);
|
|
82
|
-
this.name = "NotFoundError";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export class RateLimitError extends MiosaError {
|
|
87
|
-
readonly retryAfter: number | undefined;
|
|
88
|
-
|
|
89
|
-
constructor(
|
|
90
|
-
message: string,
|
|
91
|
-
details?: unknown,
|
|
92
|
-
requestId?: string,
|
|
93
|
-
retryAfter?: number,
|
|
94
|
-
) {
|
|
95
|
-
super(message, 429, "RATE_LIMITED", details, requestId);
|
|
96
|
-
this.name = "RateLimitError";
|
|
97
|
-
this.retryAfter = retryAfter;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export class InsufficientCreditsError extends MiosaError {
|
|
102
|
-
constructor(message: string, details?: unknown, requestId?: string) {
|
|
103
|
-
super(message, 402, "INSUFFICIENT_CREDITS", details, requestId);
|
|
104
|
-
this.name = "InsufficientCreditsError";
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export class ValidationError extends MiosaError {
|
|
109
|
-
constructor(
|
|
110
|
-
message: string,
|
|
111
|
-
status: number,
|
|
112
|
-
code: string = "VALIDATION_ERROR",
|
|
113
|
-
details?: unknown,
|
|
114
|
-
requestId?: string,
|
|
115
|
-
) {
|
|
116
|
-
super(message, status, code, details, requestId);
|
|
117
|
-
this.name = "ValidationError";
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export class TimeoutError extends MiosaError {
|
|
122
|
-
constructor(message: string = "Request timed out") {
|
|
123
|
-
super(message, 408, "TIMEOUT");
|
|
124
|
-
this.name = "TimeoutError";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export class NetworkError extends MiosaError {
|
|
129
|
-
readonly cause: Error;
|
|
130
|
-
|
|
131
|
-
constructor(message: string, cause: Error) {
|
|
132
|
-
super(message, 0, "NETWORK_ERROR");
|
|
133
|
-
this.name = "NetworkError";
|
|
134
|
-
this.cause = cause;
|
|
135
|
-
}
|
|
136
|
-
}
|