deepspace 0.28.2 → 0.29.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/cli.js CHANGED
@@ -301,6 +301,49 @@ function apiFetchReadWithRetry(baseUrl, token, path) {
301
301
  function isTransientFailure(error) {
302
302
  return error instanceof ApiError && (error.status === 0 || error.status === 408 || error.status === 429 || error.status >= 500);
303
303
  }
304
+ async function fetchIntegrationCatalog(baseUrl, opts = {}) {
305
+ const path = opts.summary ? "/api/integrations?summary=1" : "/api/integrations";
306
+ let res;
307
+ try {
308
+ res = await fetch(`${baseUrl}${path}`, { signal: AbortSignal.timeout(15e3) });
309
+ } catch (err) {
310
+ throw new ApiError(
311
+ `Could not fetch the integration catalog: ${err instanceof Error ? err.message : String(err)}`,
312
+ 0,
313
+ "catalog_unavailable",
314
+ path
315
+ );
316
+ }
317
+ if (!res.ok) {
318
+ throw new ApiError(
319
+ `Failed to fetch integration catalog (${res.status})`,
320
+ res.status,
321
+ "catalog_unavailable",
322
+ path
323
+ );
324
+ }
325
+ let value;
326
+ try {
327
+ value = await res.json();
328
+ } catch {
329
+ throw new ApiError(
330
+ "The integration catalog returned invalid JSON.",
331
+ res.status,
332
+ "invalid_catalog",
333
+ path
334
+ );
335
+ }
336
+ const integrations = value?.integrations;
337
+ if (!integrations || typeof integrations !== "object" || Array.isArray(integrations)) {
338
+ throw new ApiError(
339
+ "The integration catalog returned an invalid shape.",
340
+ res.status,
341
+ "invalid_catalog",
342
+ path
343
+ );
344
+ }
345
+ return value;
346
+ }
304
347
 
305
348
  // src/cli/lib/cli-errors.ts
306
349
  var InputError = class extends Error {
@@ -664,9 +707,13 @@ function appDomainForEnv(env) {
664
707
  return env === "production" ? "app.space" : env === "staging" ? "spacestest.com" : null;
665
708
  }
666
709
  var PLATFORM_URLS = DEEPSPACE_ENV === "production" ? PROD_URLS : DEEPSPACE_ENV === "staging" ? STAGING_URLS : INVALID_URLS;
710
+ var PLANE_URLS = {
711
+ production: PROD_URLS,
712
+ staging: STAGING_URLS
713
+ };
667
714
  var PLANE_AUTH_URLS = {
668
- production: PROD_URLS.auth,
669
- staging: STAGING_URLS.auth
715
+ production: PLANE_URLS.production.auth,
716
+ staging: PLANE_URLS.staging.auth
670
717
  };
671
718
  function effectivePlatformUrls(env = process.env) {
672
719
  return {
@@ -8150,6 +8197,19 @@ import { setTimeout as delay } from "timers/promises";
8150
8197
 
8151
8198
  // src/shared/log-events.ts
8152
8199
  var LOG_LEVELS = ["debug", "log", "info", "warn", "error"];
8200
+ function logEventText(e) {
8201
+ if (e.eventType === "exception" && e.exception) {
8202
+ const where = e.request ? ` \u2014 ${e.request.method} ${e.request.path}` : "";
8203
+ return `${e.exception.name}: ${e.exception.message}${where}`;
8204
+ }
8205
+ if (e.eventType === "request" && e.request) {
8206
+ const status3 = e.request.status !== void 0 ? ` ${e.request.status}` : "";
8207
+ const outcome = e.outcome && e.outcome !== "ok" ? ` (${e.outcome})` : "";
8208
+ return `${e.request.method} ${e.request.path}${status3}${outcome}`;
8209
+ }
8210
+ return e.message;
8211
+ }
8212
+ var MAX_LOG_TEXT_LENGTH = 8 * 1024;
8153
8213
 
8154
8214
  // src/cli/commands/logs.ts
8155
8215
  var DEPLOY_URL7 = process.env.DEEPSPACE_DEPLOY_URL ?? PLATFORM_URLS.deploy;
@@ -8161,6 +8221,9 @@ var LOG_RETENTION_DAYS = 7;
8161
8221
  function followInitialLimit(limit, maxLimit) {
8162
8222
  return limit ?? maxLimit;
8163
8223
  }
8224
+ function fatalFollowStatus(status3) {
8225
+ return [400, 401, 403, 404].includes(status3);
8226
+ }
8164
8227
  function nextPollSince(cursor, floor, lagMs = FOLLOW_LAG_MS) {
8165
8228
  return Math.max(cursor - lagMs, floor);
8166
8229
  }
@@ -8232,12 +8295,12 @@ function formatTime(ts, now) {
8232
8295
  }
8233
8296
  function formatEvent(e, color, now = Date.now()) {
8234
8297
  const time = paint("2", formatTime(e.timestamp, now), color);
8298
+ const text2 = displayLines(logEventText(e));
8235
8299
  let tag;
8236
8300
  let body;
8237
8301
  if (e.eventType === "exception" && e.exception) {
8238
8302
  tag = paint("31", "ERROR", color);
8239
- const where = e.request ? ` \u2014 ${e.request.method} ${e.request.path}` : "";
8240
- body = displayLines(`${e.exception.name}: ${e.exception.message}${where}`);
8303
+ body = text2;
8241
8304
  if (e.exception.stack) {
8242
8305
  const lines = e.exception.stack.split("\n");
8243
8306
  const firstIsHeader = lines.length > 0 && !/^\s*at\s/.test(lines[0]) && lines[0].includes(e.exception.message);
@@ -8246,17 +8309,14 @@ function formatEvent(e, color, now = Date.now()) {
8246
8309
  }
8247
8310
  } else if (e.eventType === "request" && e.request) {
8248
8311
  tag = paint("36", "REQ ", color);
8249
- const status3 = e.request.status !== void 0 ? ` ${e.request.status}` : "";
8250
- const outcome = e.outcome && e.outcome !== "ok" ? ` (${e.outcome})` : "";
8251
- body = displayLines(`${e.request.method} ${e.request.path}${status3}${outcome}`);
8312
+ body = text2;
8252
8313
  } else {
8253
8314
  const style = LEVEL_STYLE[e.level];
8254
8315
  tag = (e.level.toUpperCase() + " ").slice(0, 5);
8255
8316
  if (style) tag = paint(style, tag, color);
8256
- body = style ? paint(style, displayLines(e.message), color) : displayLines(e.message);
8317
+ body = style ? paint(style, text2, color) : text2;
8257
8318
  }
8258
- const client = e.source === "client" ? paint("35", "CLIENT", color) + " " : "";
8259
- return `${time} ${client}${tag} ${body}`;
8319
+ return `${time} ${tag} ${body}`;
8260
8320
  }
8261
8321
  var sleep3 = (ms, signal) => delay(ms, void 0, { signal });
8262
8322
  var logs_default = defineCommand4({
@@ -8295,7 +8355,7 @@ var logs_default = defineCommand4({
8295
8355
  },
8296
8356
  search: {
8297
8357
  type: "string",
8298
- description: "Only events whose message contains this text",
8358
+ description: "Only events whose rendered text contains this (case-insensitive)",
8299
8359
  required: false
8300
8360
  },
8301
8361
  limit: {
@@ -8363,6 +8423,13 @@ var logs_default = defineCommand4({
8363
8423
  );
8364
8424
  }
8365
8425
  };
8426
+ const noteTruncation = (humanMessage) => {
8427
+ if (args.json) {
8428
+ process.stdout.write(JSON.stringify({ type: "meta", truncated: true }) + "\n");
8429
+ } else {
8430
+ console.error(humanMessage);
8431
+ }
8432
+ };
8366
8433
  const first = await fetchPage(initialSince, args.follow ? followLimit : limit, token);
8367
8434
  if (args.follow && args.json) {
8368
8435
  process.stdout.write(
@@ -8394,16 +8461,9 @@ var logs_default = defineCommand4({
8394
8461
  );
8395
8462
  }
8396
8463
  } else if (first.truncated) {
8397
- if (args.json)
8398
- process.stdout.write(JSON.stringify({ type: "meta", truncated: true }) + "\n");
8399
- else if (args.search)
8400
- console.error(
8401
- `(showing the newest ${first.events.length} matches \u2014 search scans at most the newest 500 level-filtered events per fetch; narrow with --since/--level or raise --limit)`
8402
- );
8403
- else
8404
- console.error(
8405
- `(showing the newest ${first.events.length} events \u2014 narrow with --since/--level)`
8406
- );
8464
+ noteTruncation(
8465
+ args.search ? `(showing the newest ${first.events.length} matches \u2014 search scans at most the newest 500 level-filtered events per fetch; narrow with --since/--level or raise --limit)` : `(showing the newest ${first.events.length} events \u2014 narrow with --since/--level)`
8466
+ );
8407
8467
  }
8408
8468
  return;
8409
8469
  }
@@ -8420,17 +8480,13 @@ var logs_default = defineCommand4({
8420
8480
  let warnedTruncated = false;
8421
8481
  if (first.truncated) {
8422
8482
  warnedTruncated = true;
8423
- if (args.json) {
8424
- process.stdout.write(JSON.stringify({ type: "meta", truncated: true }) + "\n");
8425
- } else {
8426
- console.error(
8427
- paint(
8428
- "33",
8429
- args.search ? `(search scanned only the newest ${MAX_LIMIT} level-filtered events in the initial ${windowLabel} window \u2014 older matches may be omitted; narrow with --since/--level)` : `(more than ${followLimit} events in the initial ${windowLabel} window \u2014 some older events not shown; narrow with --since/--level)`,
8430
- stderrColor()
8431
- )
8432
- );
8433
- }
8483
+ noteTruncation(
8484
+ paint(
8485
+ "33",
8486
+ args.search ? `(search scanned only the newest ${MAX_LIMIT} level-filtered events in the initial ${windowLabel} window \u2014 older matches may be omitted; narrow with --since/--level)` : `(more than ${followLimit} events in the initial ${windowLabel} window \u2014 some older events not shown; narrow with --since/--level)`,
8487
+ stderrColor()
8488
+ )
8489
+ );
8434
8490
  }
8435
8491
  for (; ; ) {
8436
8492
  try {
@@ -8450,7 +8506,7 @@ var logs_default = defineCommand4({
8450
8506
  );
8451
8507
  } catch (err) {
8452
8508
  if (tail.signal.aborted) return;
8453
- if (err instanceof ApiError && [401, 403, 404].includes(err.status)) throw err;
8509
+ if (err instanceof ApiError && fatalFollowStatus(err.status)) throw err;
8454
8510
  backoff = Math.min(backoff ? backoff * 2 : MIN_POLL_MS, 3e4);
8455
8511
  const msg = err instanceof Error ? err.message : String(err);
8456
8512
  console.error(
@@ -8465,17 +8521,13 @@ var logs_default = defineCommand4({
8465
8521
  const realDrop = fresh.length >= followLimit || Boolean(args.search && page.truncated);
8466
8522
  if (realDrop && !warnedTruncated) {
8467
8523
  warnedTruncated = true;
8468
- if (args.json) {
8469
- process.stdout.write(JSON.stringify({ type: "meta", truncated: true }) + "\n");
8470
- } else {
8471
- console.error(
8472
- paint(
8473
- "33",
8474
- args.search ? `(search scanned only the newest ${MAX_LIMIT} level-filtered events this poll \u2014 older matches may be omitted; narrow with --level)` : `(burst exceeded ${followLimit} events/poll \u2014 some may be dropped; narrow with --level)`,
8475
- stderrColor()
8476
- )
8477
- );
8478
- }
8524
+ noteTruncation(
8525
+ paint(
8526
+ "33",
8527
+ args.search ? `(search scanned only the newest ${MAX_LIMIT} level-filtered events this poll \u2014 older matches may be omitted; narrow with --level)` : `(burst exceeded ${followLimit} events/poll \u2014 some may be dropped; narrow with --level)`,
8528
+ stderrColor()
8529
+ )
8530
+ );
8479
8531
  } else if (!realDrop) {
8480
8532
  warnedTruncated = false;
8481
8533
  }
@@ -10699,12 +10751,12 @@ async function resolveBody(opts) {
10699
10751
  return raw;
10700
10752
  }
10701
10753
  async function fetchCatalog(opts = {}) {
10702
- const url = opts.summary ? `${API_URL7}/api/integrations?summary=1` : `${API_URL7}/api/integrations`;
10703
- const res = await fetch(url);
10704
- if (!res.ok) {
10705
- throw new Refusal(`Failed to fetch integration catalog (${res.status})`, "catalog_unavailable");
10754
+ try {
10755
+ return await fetchIntegrationCatalog(API_URL7, { summary: opts.summary });
10756
+ } catch (err) {
10757
+ if (err instanceof ApiError) throw new Refusal(err.message, err.code ?? "catalog_unavailable");
10758
+ throw err;
10706
10759
  }
10707
- return await res.json();
10708
10760
  }
10709
10761
  function findEndpoint(catalog, integration, endpoint) {
10710
10762
  const endpoints = catalog.integrations[integration];
@@ -10788,9 +10840,13 @@ function requireEndpoint(catalog, integration, endpoint) {
10788
10840
  const available = catalog.integrations[integration];
10789
10841
  if (!available) {
10790
10842
  const names = Object.keys(catalog.integrations).sort().join(", ");
10791
- throw new Refusal(`Unknown integration '${integration}'. Available: ${names}`, "unknown_integration", {
10792
- action: cliAction("deepspace", "integrations", "list")
10793
- });
10843
+ throw new Refusal(
10844
+ `Unknown integration '${integration}'. Available: ${names}`,
10845
+ "unknown_integration",
10846
+ {
10847
+ action: cliAction("deepspace", "integrations", "list")
10848
+ }
10849
+ );
10794
10850
  }
10795
10851
  const endpoints = available.map((e) => e.endpoint).join(", ");
10796
10852
  throw new Refusal(
@@ -10806,9 +10862,7 @@ async function runInfo(args) {
10806
10862
  if (!args.json) {
10807
10863
  console.log(`${integration}/${endpoint}`);
10808
10864
  if (info2.description) console.log(` ${info2.description}`);
10809
- console.log(
10810
- ` billing: ${priceLabel(info2.billing)}`
10811
- );
10865
+ console.log(` billing: ${priceLabel(info2.billing)}`);
10812
10866
  if (info2.requiresOAuth) {
10813
10867
  console.log(
10814
10868
  " Requires OAuth: without a connected account, a call succeeds with data { requiresOAuth: true, authUrl } \u2014 open the authUrl, then retry."
@@ -15851,7 +15905,7 @@ import { join as join28, resolve as resolve22 } from "path";
15851
15905
  // package.json
15852
15906
  var package_default = {
15853
15907
  name: "deepspace",
15854
- version: "0.28.2",
15908
+ version: "0.29.1",
15855
15909
  engines: {
15856
15910
  node: ">=22.15.0 <23 || >=24 <25 || >=26 <27"
15857
15911
  },