@miosa/sdk 1.1.0 → 1.2.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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { randomUUID, createHmac, timingSafeEqual } from 'crypto';
1
+ import { randomUUID } from 'crypto';
2
2
  import EventEmitter from 'events';
3
3
 
4
4
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -662,11 +662,10 @@ var ApiKeys = class {
662
662
  return listItems(data);
663
663
  }
664
664
  async create(params) {
665
- const { idempotencyKey: ikey, expiresAt, workspaceId, ...rest } = params;
665
+ const { idempotencyKey: ikey, expiresAt, ...rest } = params;
666
666
  const body = stripUndefined2({
667
667
  ...rest,
668
- expires_at: expiresAt ?? rest.expires_at,
669
- workspace_id: workspaceId ?? rest.workspace_id
668
+ expires_at: expiresAt ?? rest.expires_at
670
669
  });
671
670
  const data = await this.http.request("/api-keys", {
672
671
  method: "POST",
@@ -2987,20 +2986,24 @@ var Computer = class _Computer {
2987
2986
  * ```ts
2988
2987
  * await computer.exec.bash("npm run dev &");
2989
2988
  * const url = computer.previewUrl(3000);
2990
- * // => https://3000-<slug>.sandbox.miosa.ai
2989
+ * // => https://3000-<slug>.sandbox.<tenant-domain>
2991
2990
  * ```
2992
2991
  *
2993
2992
  * Works for any TCP HTTP listener. Public (no auth required); anyone with
2994
2993
  * the URL can see it. Served over the ingress proxy so it inherits the
2995
- * wildcard TLS cert — no per-sandbox certs to manage.
2994
+ * tenant's white-label preview domain — no per-sandbox certs to manage.
2996
2995
  */
2997
2996
  previewUrl(port, path = "/") {
2998
2997
  const p = path.startsWith("/") ? path : `/${path}`;
2999
- return `https://${port}-${this.slug}.sandbox.miosa.ai${p}`;
2998
+ return `https://${port}-${this.slug}.sandbox.${this.previewDomain}${p}`;
3000
2999
  }
3001
3000
  /** Root preview URL — serves whatever is on the default app port. */
3002
3001
  get publicUrl() {
3003
- return `https://${this.slug}.sandbox.miosa.ai`;
3002
+ return `https://${this.slug}.sandbox.${this.previewDomain}`;
3003
+ }
3004
+ /** Tenant's preview/base domain, white-label aware. */
3005
+ get previewDomain() {
3006
+ return this.data.preview_domain || "miosa.app";
3004
3007
  }
3005
3008
  // ─── Lifecycle ─────────────────────────────────────────────────────────────
3006
3009
  /** Start the computer. */
@@ -3791,7 +3794,6 @@ var Deployments = class {
3791
3794
  auto_deploy: params.autoDeploy ?? params.auto_deploy,
3792
3795
  database: params.database,
3793
3796
  metadata: params.metadata,
3794
- target_region: params.targetRegion ?? params.target_region,
3795
3797
  ...attributionBody(params)
3796
3798
  });
3797
3799
  const data = await this.http.request("/deployments", {
@@ -3886,11 +3888,9 @@ var Deployments = class {
3886
3888
  );
3887
3889
  return unwrap23(data);
3888
3890
  }
3889
- async listEnv(deploymentId, opts = {}) {
3890
- const query = stripUndefined10({ environment: opts.environment });
3891
+ async listEnv(deploymentId) {
3891
3892
  const data = await this.http.get(
3892
- `/deployments/${deploymentId}/env`,
3893
- Object.keys(query).length ? query : void 0
3893
+ `/deployments/${deploymentId}/env`
3894
3894
  );
3895
3895
  return listItems4(data);
3896
3896
  }
@@ -6705,65 +6705,17 @@ var OrgInvites = class {
6705
6705
  function unwrap41(payload) {
6706
6706
  if (payload && typeof payload === "object") {
6707
6707
  const p = payload;
6708
- for (const k of ["data", "tenant", "branding", "preview_domain", "items"]) {
6708
+ for (const k of ["data", "tenant", "items"]) {
6709
6709
  if (k in p) return p[k];
6710
6710
  }
6711
6711
  }
6712
6712
  return payload;
6713
6713
  }
6714
- var PreviewDomain = class {
6715
- constructor(http) {
6716
- this.http = http;
6717
- }
6718
- http;
6719
- /** GET /api/v1/tenant/preview-domain → {domain, verified_at, cname_target} */
6720
- async get() {
6721
- return unwrap41(await this.http.get("/tenant/preview-domain"));
6722
- }
6723
- /** PUT /api/v1/tenant/preview-domain — set the preview domain. */
6724
- async set(domain) {
6725
- return unwrap41(
6726
- await this.http.put("/tenant/preview-domain", { domain })
6727
- );
6728
- }
6729
- /** POST /api/v1/tenant/preview-domain/verify → {verified, target, records} */
6730
- async verify() {
6731
- return unwrap41(
6732
- await this.http.post("/tenant/preview-domain/verify", {})
6733
- );
6734
- }
6735
- /** DELETE /api/v1/tenant/preview-domain */
6736
- async delete() {
6737
- await this.http.delete("/tenant/preview-domain");
6738
- }
6739
- };
6740
- var Branding = class {
6741
- constructor(http) {
6742
- this.http = http;
6743
- }
6744
- http;
6745
- /** GET /api/v1/tenant/branding */
6746
- async get() {
6747
- return unwrap41(await this.http.get("/tenant/branding"));
6748
- }
6749
- /** PUT /api/v1/tenant/branding — keys: product_name, logo_url, support_url, support_email, primary_color, background_color */
6750
- async set(branding) {
6751
- return unwrap41(await this.http.put("/tenant/branding", branding));
6752
- }
6753
- /** DELETE /api/v1/tenant/branding */
6754
- async delete() {
6755
- await this.http.delete("/tenant/branding");
6756
- }
6757
- };
6758
6714
  var Tenant = class {
6759
6715
  constructor(http) {
6760
6716
  this.http = http;
6761
- this.preview_domain = new PreviewDomain(http);
6762
- this.branding = new Branding(http);
6763
6717
  }
6764
6718
  http;
6765
- preview_domain;
6766
- branding;
6767
6719
  /** Get the current tenant's plan, limits, and live usage counters. */
6768
6720
  async current() {
6769
6721
  const data = await this.http.get("/tenant/plan");
@@ -6866,29 +6818,6 @@ var Volumes = class {
6866
6818
  await this.http.delete(`/volumes/${volumeId}`);
6867
6819
  }
6868
6820
  };
6869
- var MAX_TIMESTAMP_AGE_MS = 5 * 60 * 1e3;
6870
- function verifySignature(payload, signatureHeader, secret) {
6871
- const parts = {};
6872
- for (const part of signatureHeader.split(",")) {
6873
- const idx = part.indexOf("=");
6874
- if (idx > 0) parts[part.slice(0, idx).trim()] = part.slice(idx + 1).trim();
6875
- }
6876
- const tsStr = parts["t"];
6877
- const sig = parts["v1"];
6878
- if (!tsStr || !sig) return false;
6879
- const ts = parseInt(tsStr, 10);
6880
- if (isNaN(ts)) return false;
6881
- if (Date.now() - ts * 1e3 > MAX_TIMESTAMP_AGE_MS) {
6882
- throw new Error(`Webhook timestamp is too old: ${ts}`);
6883
- }
6884
- const body = payload instanceof Uint8Array ? payload : Buffer.from(payload, "utf-8");
6885
- const signed = Buffer.concat([Buffer.from(`${tsStr}.`, "utf-8"), body]);
6886
- const expected = createHmac("sha256", secret).update(signed).digest("hex");
6887
- return timingSafeEqual(
6888
- Buffer.from(expected, "utf-8"),
6889
- Buffer.from(sig, "utf-8")
6890
- );
6891
- }
6892
6821
  function unwrap44(payload) {
6893
6822
  if (payload && typeof payload === "object" && "data" in payload) {
6894
6823
  return payload.data;
@@ -6965,18 +6894,6 @@ var Webhooks = class {
6965
6894
  "items"
6966
6895
  ]);
6967
6896
  }
6968
- /**
6969
- * Verify an incoming ``X-Miosa-Signature`` header.
6970
- *
6971
- * Header format: ``t=<unix_ts>,v1=<hex_hmac>``
6972
- * HMAC body: ``<t>.<raw_payload>``
6973
- *
6974
- * Throws if timestamp is older than 5 minutes.
6975
- * Returns true if signature matches.
6976
- */
6977
- static verifySignature(payload, signatureHeader, secret) {
6978
- return verifySignature(payload, signatureHeader, secret);
6979
- }
6980
6897
  };
6981
6898
 
6982
6899
  // src/resources/workspace-invites.ts
@@ -7129,192 +7046,11 @@ var WorkspaceMembers = class {
7129
7046
  }
7130
7047
  };
7131
7048
 
7132
- // src/resources/workspaces.ts
7133
- function unwrap45(payload) {
7134
- if (payload && typeof payload === "object" && "data" in payload) {
7135
- return payload.data;
7136
- }
7137
- return payload;
7138
- }
7139
- function listItems17(payload, candidateKeys = ["data", "items"]) {
7140
- if (Array.isArray(payload)) return payload;
7141
- if (!payload || typeof payload !== "object") return [];
7142
- const p = payload;
7143
- if (Array.isArray(p.data)) return p.data;
7144
- for (const key of candidateKeys) {
7145
- if (Array.isArray(p[key])) return p[key];
7146
- }
7147
- return [];
7148
- }
7149
- var Workspaces = class {
7150
- http;
7151
- constructor(http) {
7152
- this.http = http;
7153
- }
7154
- /**
7155
- * Create a new workspace.
7156
- */
7157
- async create(params) {
7158
- const payload = await this.http.post("/workspaces", params);
7159
- return unwrap45(payload);
7160
- }
7161
- /**
7162
- * List all workspaces visible to the current credential.
7163
- */
7164
- async list() {
7165
- const payload = await this.http.get("/workspaces");
7166
- if (payload && typeof payload === "object" && "workspaces" in payload) {
7167
- const p = payload;
7168
- return p["workspaces"] ?? [];
7169
- }
7170
- return listItems17(payload, ["data", "workspaces", "items"]);
7171
- }
7172
- /**
7173
- * Get a single workspace by ID.
7174
- */
7175
- async get(id) {
7176
- const payload = await this.http.get(`/workspaces/${id}`);
7177
- return unwrap45(payload);
7178
- }
7179
- /**
7180
- * Update a workspace's metadata.
7181
- */
7182
- async update(id, params) {
7183
- const payload = await this.http.patch(`/workspaces/${id}`, params);
7184
- return unwrap45(payload);
7185
- }
7186
- /**
7187
- * Delete a workspace. Does not delete member computers.
7188
- */
7189
- async delete(id) {
7190
- await this.http.delete(`/workspaces/${id}`);
7191
- }
7192
- /**
7193
- * Update workspace-level settings.
7194
- */
7195
- async updateSettings(id, settings) {
7196
- const payload = await this.http.put(
7197
- `/workspaces/${id}/settings`,
7198
- settings
7199
- );
7200
- return unwrap45(payload);
7201
- }
7202
- /**
7203
- * List all computers that belong to the given workspace.
7204
- */
7205
- async listComputers(id) {
7206
- const payload = await this.http.get(`/workspaces/${id}/computers`);
7207
- const items = listItems17(payload, [
7208
- "data",
7209
- "computers",
7210
- "items"
7211
- ]);
7212
- return items.map((d) => new Computer(this.http, d));
7213
- }
7214
- /**
7215
- * List all sandboxes that belong to this workspace.
7216
- */
7217
- async listSandboxes(id) {
7218
- const payload = await this.http.get(`/workspaces/${id}/sandboxes`);
7219
- return listItems17(payload, [
7220
- "data",
7221
- "sandboxes",
7222
- "items"
7223
- ]);
7224
- }
7225
- /**
7226
- * List all deployments that belong to this workspace.
7227
- */
7228
- async listDeployments(id) {
7229
- const payload = await this.http.get(
7230
- `/workspaces/${id}/deployments`
7231
- );
7232
- return listItems17(payload, [
7233
- "data",
7234
- "deployments",
7235
- "items"
7236
- ]);
7237
- }
7238
- /**
7239
- * List all managed databases that belong to this workspace.
7240
- */
7241
- async listDatabases(id) {
7242
- const payload = await this.http.get(`/workspaces/${id}/databases`);
7243
- return listItems17(payload, [
7244
- "data",
7245
- "databases",
7246
- "items"
7247
- ]);
7248
- }
7249
- /**
7250
- * List all projects that belong to this workspace.
7251
- */
7252
- async listProjects(id) {
7253
- const payload = await this.http.get(`/workspaces/${id}/projects`);
7254
- return listItems17(payload, [
7255
- "data",
7256
- "projects",
7257
- "items"
7258
- ]);
7259
- }
7260
- /**
7261
- * Return aggregate resource stats for this workspace.
7262
- */
7263
- async stats(id) {
7264
- const payload = await this.http.get(`/workspaces/${id}/stats`);
7265
- return unwrap45(payload);
7266
- }
7267
- /**
7268
- * Return metered usage data for this workspace.
7269
- */
7270
- async usage(id) {
7271
- const payload = await this.http.get(`/workspaces/${id}/usage`);
7272
- return unwrap45(payload);
7273
- }
7274
- /**
7275
- * Return activity feed for this workspace.
7276
- */
7277
- async activity(id) {
7278
- const payload = await this.http.get(`/workspaces/${id}/activity`);
7279
- return listItems17(payload, [
7280
- "data",
7281
- "activity",
7282
- "events",
7283
- "items"
7284
- ]);
7285
- }
7286
- /**
7287
- * List computer templates available in this workspace.
7288
- */
7289
- async listComputerTemplates(id) {
7290
- const payload = await this.http.get(
7291
- `/workspaces/${id}/computer-templates`
7292
- );
7293
- return listItems17(payload, [
7294
- "data",
7295
- "templates",
7296
- "items"
7297
- ]);
7298
- }
7299
- /**
7300
- * Create a computer template scoped to this workspace.
7301
- */
7302
- async createComputerTemplate(id, params) {
7303
- const payload = await this.http.post(
7304
- `/workspaces/${id}/computer-templates`,
7305
- params
7306
- );
7307
- return unwrap45(payload);
7308
- }
7309
- };
7310
-
7311
7049
  // src/client.ts
7312
7050
  var DEFAULT_BASE_URL = "https://api.miosa.ai/api/v1";
7313
7051
  var DEFAULT_TIMEOUT2 = 3e4;
7314
7052
  var DEFAULT_MAX_RETRIES2 = 3;
7315
7053
  var Miosa = class {
7316
- /** Workspace CRUD — create, list, get, update, delete, and sub-resource queries. */
7317
- workspaces;
7318
7054
  /** Per-workspace user roster — list, add, update role, remove. */
7319
7055
  workspaceMembers;
7320
7056
  /**
@@ -7437,7 +7173,6 @@ var Miosa = class {
7437
7173
  timeout: config.timeout ?? DEFAULT_TIMEOUT2,
7438
7174
  maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES2
7439
7175
  });
7440
- this.workspaces = new Workspaces(this.http);
7441
7176
  this.workspaceMembers = new WorkspaceMembers(this.http);
7442
7177
  this.workspaceInvites = new WorkspaceInvites(this.http);
7443
7178
  this.orgInvites = new OrgInvites(this.http);
@@ -7486,6 +7221,6 @@ var Miosa = class {
7486
7221
  }
7487
7222
  };
7488
7223
 
7489
- export { Admin, Analytics, ApiKeys, AuditLog, AuthError, Benchmarks, BuilderSessions, Channels, Checkpoints, CommandCenter, Community, Completions, Computer, ComputerAudit, ComputerAutoStop, ComputerEnv, ComputerInbox, ComputerLogs, ComputerNetwork, ComputerOsa, ComputerPorts, ComputerSecrets, ComputerTerminal, ComputerVolumes, Computers, Credits, CronJobs, Dashboard, Databases, DeploymentDomains, DeploymentReleases, DeploymentRuntimeInstances, DeploymentVersions, Deployments, Desktop, EgressAudit, EgressNetwork, EgressSecrets, Email, EmailCampaigns, EmailInbox, EmailTemplates, Embeddings, Exec, ExternalKeys, Files, FlatCustomDomains, Functions, HealthChecks, InsufficientCreditsError, Integrations, Mcp, Miosa, MiosaError, Models, NetworkError, NetworkPolicy, NotFoundError, OAuthFlow, OpenComputers, OrgInvites, ProjectAuth, ProjectIntegrations, ProviderDefaults, RateLimitError, Regions, SANDBOX_TEMPLATE, Sandbox, SandboxArtifacts, SandboxAudit, SandboxCommands, SandboxEnv, SandboxEvents, SandboxFiles, SandboxNetwork, SandboxPreview, SandboxPreviews, SandboxSecrets, SandboxTags, SandboxTemplates, SandboxTerminal, Sandboxes, ScopedFs, Settings, SnapshotsStandalone, Storage, Tenant, TimeoutError, Usage, ValidationError, Volumes, Webhooks, WorkspaceInvites, WorkspaceMembers, Workspaces };
7224
+ export { Admin, Analytics, ApiKeys, AuditLog, AuthError, Benchmarks, BuilderSessions, Channels, Checkpoints, CommandCenter, Community, Completions, Computer, ComputerAudit, ComputerAutoStop, ComputerEnv, ComputerInbox, ComputerLogs, ComputerNetwork, ComputerOsa, ComputerPorts, ComputerSecrets, ComputerTerminal, ComputerVolumes, Computers, Credits, CronJobs, Dashboard, Databases, DeploymentDomains, DeploymentReleases, DeploymentRuntimeInstances, DeploymentVersions, Deployments, Desktop, EgressAudit, EgressNetwork, EgressSecrets, Email, EmailCampaigns, EmailInbox, EmailTemplates, Embeddings, Exec, ExternalKeys, Files, FlatCustomDomains, Functions, HealthChecks, InsufficientCreditsError, Integrations, Mcp, Miosa, MiosaError, Models, NetworkError, NetworkPolicy, NotFoundError, OAuthFlow, OpenComputers, OrgInvites, ProjectAuth, ProjectIntegrations, ProviderDefaults, RateLimitError, Regions, SANDBOX_TEMPLATE, Sandbox, SandboxArtifacts, SandboxAudit, SandboxCommands, SandboxEnv, SandboxEvents, SandboxFiles, SandboxNetwork, SandboxPreview, SandboxPreviews, SandboxSecrets, SandboxTags, SandboxTemplates, SandboxTerminal, Sandboxes, ScopedFs, Settings, SnapshotsStandalone, Storage, Tenant, TimeoutError, Usage, ValidationError, Volumes, Webhooks, WorkspaceInvites, WorkspaceMembers };
7490
7225
  //# sourceMappingURL=index.js.map
7491
7226
  //# sourceMappingURL=index.js.map