@treeseed/sdk 0.12.13 → 0.12.15

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.
@@ -335,7 +335,7 @@ function buildProfileFromDeployConfig(input) {
335
335
  const configuredRailwayProjectName = typeof service.railway?.projectName === "string" && service.railway.projectName.trim() ? service.railway.projectName.trim() : null;
336
336
  const defaultProjectGroup = service.provider === "railway" || service.railway ? String(serviceKey).startsWith("capacityProvider") && configuredRailwayProjectName ? capacityProviderProjectGroupId(configuredRailwayProjectName) : "treeseed-control-plane" : void 0;
337
337
  const imageRefEnv = railwayImageRefEnvForService(serviceKey);
338
- const imageRef = service.railway?.imageRef ?? (imageRefEnv ? launchEnv[imageRefEnv] ?? null : null) ?? defaultRailwayImageRefForService(serviceKey, input.environment) ?? null;
338
+ const imageRef = service.railway?.imageRef ?? (input.environment === "prod" && imageRefEnv ? launchEnv[imageRefEnv] ?? null : null) ?? defaultRailwayImageRefForService(serviceKey, input.environment) ?? null;
339
339
  const sourcePolicy = railwaySourcePolicy(input, serviceKey, service, imageRef);
340
340
  services.push({
341
341
  id: serviceKey,
@@ -81,6 +81,9 @@ function railwayImageRefEnvForService(serviceKey) {
81
81
  return null;
82
82
  }
83
83
  function defaultRailwayImageRef(serviceKey, scope = "staging", env = process.env) {
84
+ if (normalizeScope(scope) !== "prod" && serviceKey !== "capacityProviderManager" && serviceKey !== "capacityProviderRunner") {
85
+ return null;
86
+ }
84
87
  if (serviceKey === "api") {
85
88
  return envValue("TREESEED_API_IMAGE_REF", env) || null;
86
89
  }
@@ -668,7 +671,8 @@ function configuredRailwayServicesForConfig(tenantRoot, scope, deployConfig, app
668
671
  const runnerIndex = offset + 1;
669
672
  const serviceName = serviceKey === "operationsRunner" ? deriveRailwayOperationsRunnerServiceName(configuredServiceName, runnerIndex) : serviceKey === "capacityProviderRunner" ? deriveRailwayCapacityProviderRunnerServiceName(configuredServiceName, runnerIndex) : configuredServiceName;
670
673
  const configuredImageRefEnv = service.railway?.imageRefEnv ?? railwayImageRefEnvForService(serviceKey);
671
- const imageRef = service.railway?.imageRef ?? (configuredImageRefEnv ? envValue(configuredImageRefEnv, imageRefEnv) || null : null) ?? defaultRailwayImageRef(serviceKey, normalizedScope, imageRefEnv);
674
+ const canUseImageRefEnv = normalizedScope === "prod" || serviceKey === "capacityProviderManager" || serviceKey === "capacityProviderRunner";
675
+ const imageRef = service.railway?.imageRef ?? (canUseImageRefEnv && configuredImageRefEnv ? envValue(configuredImageRefEnv, imageRefEnv) || null : null) ?? defaultRailwayImageRef(serviceKey, normalizedScope, imageRefEnv);
672
676
  const sourcePolicy = resolveRailwayServiceSourcePolicy({
673
677
  tenantRoot,
674
678
  scope: normalizedScope,
@@ -3631,6 +3631,14 @@ function configuredRailwayIacDatabase(input, projectServices, detachVolumeIds =
3631
3631
  detachVolumeIds
3632
3632
  };
3633
3633
  }
3634
+ function railwayIacChangeName(change) {
3635
+ return String(change?.resource?.name ?? change?.previous?.name ?? change?.address ?? change?.path ?? "");
3636
+ }
3637
+ function railwayIacPlanDeletesResource(changeSet, resourceName) {
3638
+ return (changeSet?.changes ?? []).some(
3639
+ (change) => change.kind === "resource.delete" && railwayIacChangeName(change) === resourceName
3640
+ );
3641
+ }
3634
3642
  function activeAttachedRailwayVolumeIds(volumes, serviceId, environmentId, desiredVolumeName) {
3635
3643
  if (!serviceId) {
3636
3644
  return [];
@@ -3821,7 +3829,7 @@ async function syncRailwayEnvironmentForScope(input, { dryRun = false, serviceKe
3821
3829
  }));
3822
3830
  const databaseLiveService = databaseDescriptor ? liveServiceByName.get(databaseDescriptor.serviceName) ?? project.services.find((candidate) => candidate.name === databaseDescriptor.serviceName) ?? null : null;
3823
3831
  const databaseDetachVolumeIds = databaseDescriptor ? activeAttachedRailwayVolumeIds(liveVolumes, databaseLiveService?.id, environment.id, `${databaseDescriptor.serviceName}-volume`) : [];
3824
- const databaseForIac = databaseDescriptor ? { ...databaseDescriptor, detachVolumeIds: databaseDetachVolumeIds, useNativePostgres: Boolean(databaseLiveService) } : null;
3832
+ const databaseForIac = databaseDescriptor ? { ...databaseDescriptor, detachVolumeIds: databaseDetachVolumeIds, useNativePostgres: false } : null;
3825
3833
  const token = String(topology.env.TREESEED_RAILWAY_API_TOKEN ?? topology.env.RAILWAY_API_TOKEN ?? "").trim();
3826
3834
  if (!token) {
3827
3835
  throw new Error(`Railway IaC reconciliation requires TREESEED_RAILWAY_API_TOKEN for ${project.name}/${environment.name}.`);
@@ -3848,24 +3856,48 @@ async function syncRailwayEnvironmentForScope(input, { dryRun = false, serviceKe
3848
3856
  renderRailwayIacProject,
3849
3857
  validateRailwayIacChangeSet
3850
3858
  } = await import("./providers/railway-iac.js");
3851
- const rendered = renderRailwayIacProject(iacInput);
3859
+ let effectiveIacInput = iacInput;
3860
+ let rendered = renderRailwayIacProject(effectiveIacInput);
3852
3861
  try {
3853
3862
  traceRailwayReconcile(topology.env, "sync:iac-plan", `${project.name}/${environment.name}:${rendered.serviceNames.join(",")}:volumes=${rendered.volumeNames.join(",")}`);
3854
- const plan = await planRailwayIacProject(iacInput, rendered);
3863
+ let plan = await planRailwayIacProject(effectiveIacInput, rendered);
3855
3864
  if (!plan.ok) {
3856
3865
  const diagnostics = plan.diagnostics.map((entry) => entry.message).filter(Boolean).join("; ");
3857
3866
  throw new Error(`Railway IaC plan failed for ${project.name}/${environment.name}${diagnostics ? `: ${diagnostics}` : "."}`);
3858
3867
  }
3859
- const validation = validateRailwayIacChangeSet(plan.changeSet, {
3868
+ let validation = validateRailwayIacChangeSet(plan.changeSet, {
3860
3869
  services: rendered.serviceNames,
3861
3870
  volumes: rendered.volumeNames,
3862
3871
  database: rendered.databaseName,
3863
3872
  scope
3864
3873
  });
3874
+ if (!validation.ok && effectiveIacInput.database && !effectiveIacInput.database.useNativePostgres && railwayIacPlanDeletesResource(plan.changeSet, effectiveIacInput.database.serviceName)) {
3875
+ traceRailwayReconcile(topology.env, "sync:iac-native-postgres-adopt", `${project.name}/${environment.name}:${effectiveIacInput.database.serviceName}`);
3876
+ cleanupRailwayIacRender(rendered);
3877
+ effectiveIacInput = {
3878
+ ...effectiveIacInput,
3879
+ database: {
3880
+ ...effectiveIacInput.database,
3881
+ useNativePostgres: true
3882
+ }
3883
+ };
3884
+ rendered = renderRailwayIacProject(effectiveIacInput);
3885
+ plan = await planRailwayIacProject(effectiveIacInput, rendered);
3886
+ if (!plan.ok) {
3887
+ const diagnostics = plan.diagnostics.map((entry) => entry.message).filter(Boolean).join("; ");
3888
+ throw new Error(`Railway IaC plan failed for ${project.name}/${environment.name}${diagnostics ? `: ${diagnostics}` : "."}`);
3889
+ }
3890
+ validation = validateRailwayIacChangeSet(plan.changeSet, {
3891
+ services: rendered.serviceNames,
3892
+ volumes: rendered.volumeNames,
3893
+ database: rendered.databaseName,
3894
+ scope
3895
+ });
3896
+ }
3865
3897
  if (!validation.ok) {
3866
3898
  throw new Error(`Railway IaC plan rejected for ${project.name}/${environment.name}: ${validation.blockedReasons.join("; ")}`);
3867
3899
  }
3868
- const apply = await applyRailwayIacProject(iacInput, rendered);
3900
+ const apply = await applyRailwayIacProject(effectiveIacInput, rendered);
3869
3901
  if (!apply.ok) {
3870
3902
  const diagnostics = apply.diagnostics.map((entry) => entry.message).filter(Boolean).join("; ");
3871
3903
  throw new Error(`Railway IaC apply failed for ${project.name}/${environment.name}${diagnostics ? `: ${diagnostics}` : "."}`);
@@ -4422,7 +4454,12 @@ function collectRailwayEnvironmentSync(input, valuesOverlay = {}) {
4422
4454
  ...serviceVariables,
4423
4455
  ...serviceRefVariables,
4424
4456
  ...Object.fromEntries(entriesForService("railway-var", serviceKey)),
4425
- ...serviceKey === "operationsRunner" ? { TREESEED_MANAGER_ID: scope } : {},
4457
+ ...serviceKey === "operationsRunner" ? {
4458
+ TREESEED_MANAGER_ID: scope,
4459
+ TREESEED_PLATFORM_RUNNER_ID: configuredService?.runnerId ?? configuredService?.serviceName ?? "treeseed-api-operations-runner-01",
4460
+ TREESEED_PLATFORM_RUNNER_DATA_DIR: configuredService?.volumeMountPath ?? "/data",
4461
+ TREESEED_PLATFORM_RUNNER_ENVIRONMENT: scope === "prod" ? "production" : scope
4462
+ } : {},
4426
4463
  ...serviceKey === "api" ? apiOnlyVariables : {},
4427
4464
  ...capacityVariables
4428
4465
  }
@@ -1,7 +1,8 @@
1
1
  import type { TreeseedDesiredUnit, TreeseedReconcileTarget } from './contracts.js';
2
- export declare function deriveTreeseedDesiredUnits({ tenantRoot, target, }: {
2
+ export declare function deriveTreeseedDesiredUnits({ tenantRoot, target, env, }: {
3
3
  tenantRoot: string;
4
4
  target: TreeseedReconcileTarget;
5
+ env?: NodeJS.ProcessEnv;
5
6
  }): {
6
7
  deployConfig: import("../platform/contracts.js").TreeseedDeployConfig;
7
8
  legacyState: any;
@@ -26,9 +26,10 @@ function isPublicTreeDxNodeServiceKey(serviceKey) {
26
26
  }
27
27
  function deriveTreeseedDesiredUnits({
28
28
  tenantRoot,
29
- target
29
+ target,
30
+ env = process.env
30
31
  }) {
31
- const deployConfig = loadTreeseedPlatformConfig({ tenantRoot, environment: target.kind === "persistent" ? target.scope : "staging", env: process.env }).deployConfig;
32
+ const deployConfig = loadTreeseedPlatformConfig({ tenantRoot, environment: target.kind === "persistent" ? target.scope : "staging", env }).deployConfig;
32
33
  const legacyState = loadDeployState(tenantRoot, deployConfig, { target });
33
34
  const identity = legacyState.identity ?? resolveTreeseedResourceIdentity(deployConfig, target);
34
35
  const units = [];
@@ -27,7 +27,7 @@ function formatVerificationFailure(verification) {
27
27
  return details.length > 0 ? `Verification failed (${details.join(" | ")})` : "Verification failed.";
28
28
  }
29
29
  function createRunContext(tenantRoot, target, launchEnv, write, dryRun = false, session) {
30
- const { deployConfig } = deriveTreeseedDesiredUnits({ tenantRoot, target });
30
+ const { deployConfig } = deriveTreeseedDesiredUnits({ tenantRoot, target, env: launchEnv });
31
31
  return {
32
32
  tenantRoot,
33
33
  target,
@@ -199,7 +199,7 @@ async function refreshTreeseedUnits({
199
199
  units: explicitUnits,
200
200
  write
201
201
  }) {
202
- const derived = deriveTreeseedDesiredUnits({ tenantRoot, target });
202
+ const derived = deriveTreeseedDesiredUnits({ tenantRoot, target, env });
203
203
  const baseUnits = explicitUnits ?? filterTreeseedDesiredUnitsByBootstrapSystems(derived.units, systems);
204
204
  const units = filterUnitsBySelector(baseUnits, selector);
205
205
  const deployConfig = derived.deployConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.12.13",
3
+ "version": "0.12.15",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {