@treeseed/sdk 0.6.46 → 0.6.48

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.
@@ -17,6 +17,7 @@ import {
17
17
  listRailwayServices,
18
18
  listRailwayVolumes,
19
19
  normalizeRailwayEnvironmentName,
20
+ railwayGraphqlRequest,
20
21
  resolveRailwayApiToken,
21
22
  resolveRailwayApiUrl,
22
23
  resolveRailwayWorkspace,
@@ -392,47 +393,50 @@ function runRailway(args, { cwd, capture = false, allowFailure = false, input, e
392
393
  async function waitForRailwayManagedDeploymentsSettled(tenantRoot, scope, {
393
394
  services = configuredRailwayServices(tenantRoot, scope),
394
395
  env = process.env,
395
- timeoutMs = 18e4,
396
+ timeoutMs = 6e5,
396
397
  pollMs = 15e3
397
398
  } = {}) {
398
399
  const deadline = Date.now() + timeoutMs;
399
- const environment = resolveRailwayEnvironmentForScope(scope);
400
400
  const projectId = services.find((service) => typeof service.projectId === "string" && service.projectId.trim())?.projectId ?? null;
401
- if (projectId) {
402
- runRailway(["link", "--project", projectId, "--environment", environment, "--json"], {
403
- cwd: tenantRoot,
404
- capture: true,
405
- allowFailure: true,
406
- env
407
- });
401
+ if (!projectId) {
402
+ return {
403
+ ok: false,
404
+ checks: services.map((service) => ({
405
+ type: "deployment-status",
406
+ service: service.key,
407
+ serviceName: service.serviceName,
408
+ environment: resolveRailwayEnvironmentForScope(scope),
409
+ ok: false,
410
+ status: "missing_project",
411
+ message: `Railway deployment status for ${service.serviceName} cannot be checked without a project id.`
412
+ }))
413
+ };
408
414
  }
409
415
  let checks = [];
410
416
  let lastError = null;
411
417
  for (; ; ) {
418
+ lastError = null;
412
419
  try {
413
- const result = runRailway(["status", "--json"], {
414
- cwd: tenantRoot,
415
- capture: true,
420
+ const statusPayload = await fetchRailwayProjectDeploymentStatus({
421
+ projectId,
416
422
  env
417
423
  });
418
- const payload = parseRailwayJsonOutput(result.stdout);
419
- checks = collectRailwayDeploymentStatusChecks(payload, scope, services);
420
- lastError = null;
421
- if (checks.every((entry) => entry.ok === true)) {
422
- return { ok: true, checks };
423
- }
424
+ checks = collectRailwayDeploymentStatusChecks(statusPayload, scope, services);
424
425
  } catch (error) {
425
426
  lastError = error;
426
427
  checks = services.map((service) => ({
427
428
  type: "deployment-status",
428
429
  service: service.key,
429
430
  serviceName: service.serviceName,
430
- environment,
431
+ environment: resolveRailwayEnvironmentForScope(scope),
431
432
  ok: false,
432
433
  status: "status_error",
433
434
  message: error instanceof Error ? error.message : String(error)
434
435
  }));
435
436
  }
437
+ if (checks.every((entry) => entry.ok === true)) {
438
+ return { ok: true, checks };
439
+ }
436
440
  if (Date.now() >= deadline) {
437
441
  return {
438
442
  ok: false,
@@ -443,6 +447,48 @@ async function waitForRailwayManagedDeploymentsSettled(tenantRoot, scope, {
443
447
  await sleep(pollMs);
444
448
  }
445
449
  }
450
+ async function fetchRailwayProjectDeploymentStatus({ projectId, env = process.env }) {
451
+ const payload = await railwayGraphqlRequest({
452
+ query: `
453
+ query TreeseedRailwayDeploymentStatus($projectId: String!) {
454
+ project(id: $projectId) {
455
+ id
456
+ environments(first: 50) {
457
+ edges {
458
+ node {
459
+ id
460
+ name
461
+ serviceInstances {
462
+ edges {
463
+ node {
464
+ id
465
+ serviceId
466
+ serviceName
467
+ latestDeployment {
468
+ id
469
+ status
470
+ createdAt
471
+ deploymentStopped
472
+ meta
473
+ instances {
474
+ id
475
+ status
476
+ }
477
+ }
478
+ }
479
+ }
480
+ }
481
+ }
482
+ }
483
+ }
484
+ }
485
+ }
486
+ `.trim(),
487
+ variables: { projectId },
488
+ env
489
+ });
490
+ return payload.data?.project ?? null;
491
+ }
446
492
  function setRailwaySecretVariable({ cwd, service, environment, key, value, env = process.env, capture = false, allowFailure = false }) {
447
493
  const effectiveEnv = buildRailwayCommandEnv({
448
494
  ...process.env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.6.46",
3
+ "version": "0.6.48",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {