@treeseed/sdk 0.6.0 → 0.6.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.
@@ -155,28 +155,51 @@ function providerCache(input, key, loader, forceRefresh = false) {
155
155
  input.context.session.set(key, value);
156
156
  return value;
157
157
  }
158
+ function normalizeEnvironmentValues(env) {
159
+ return Object.fromEntries(
160
+ Object.entries(env ?? {}).filter((entry) => typeof entry[1] === "string").map(([key, value]) => [key, value])
161
+ );
162
+ }
163
+ function resolveReconcileEnvironmentValues(input, scope) {
164
+ if (scope === "local") {
165
+ return resolveTreeseedMachineEnvironmentValues(input.context.tenantRoot, scope);
166
+ }
167
+ const values = {
168
+ ...normalizeEnvironmentValues(process.env),
169
+ ...normalizeEnvironmentValues(input.context.launchEnv)
170
+ };
171
+ const launchRailwayAlias = input.context.launchEnv.RAILWAY_API_KEY;
172
+ if (!input.context.launchEnv.RAILWAY_API_TOKEN && typeof launchRailwayAlias === "string" && launchRailwayAlias.length > 0) {
173
+ values.RAILWAY_API_TOKEN = launchRailwayAlias;
174
+ } else if (!values.RAILWAY_API_TOKEN && values.RAILWAY_API_KEY) {
175
+ values.RAILWAY_API_TOKEN = values.RAILWAY_API_KEY;
176
+ }
177
+ return values;
178
+ }
158
179
  function buildCloudflareEnv(input) {
159
180
  const scope = scopeFromTarget(toDeployTarget(input.context.target));
160
- const machineValues = resolveTreeseedMachineEnvironmentValues(input.context.tenantRoot, scope);
181
+ const values = resolveReconcileEnvironmentValues(input, scope);
161
182
  return {
162
- CLOUDFLARE_ACCOUNT_ID: machineValues.CLOUDFLARE_ACCOUNT_ID ?? input.context.launchEnv.CLOUDFLARE_ACCOUNT_ID ?? process.env.CLOUDFLARE_ACCOUNT_ID ?? resolveConfiguredCloudflareAccountId(input.context.deployConfig),
163
- CLOUDFLARE_API_TOKEN: machineValues.CLOUDFLARE_API_TOKEN ?? input.context.launchEnv.CLOUDFLARE_API_TOKEN ?? process.env.CLOUDFLARE_API_TOKEN ?? ""
183
+ CLOUDFLARE_ACCOUNT_ID: values.CLOUDFLARE_ACCOUNT_ID ?? input.context.launchEnv.CLOUDFLARE_ACCOUNT_ID ?? process.env.CLOUDFLARE_ACCOUNT_ID ?? resolveConfiguredCloudflareAccountId(input.context.deployConfig),
184
+ CLOUDFLARE_API_TOKEN: values.CLOUDFLARE_API_TOKEN ?? input.context.launchEnv.CLOUDFLARE_API_TOKEN ?? process.env.CLOUDFLARE_API_TOKEN ?? ""
164
185
  };
165
186
  }
166
187
  function hasLiveResourceId(value) {
167
188
  return typeof value === "string" && value.length > 0 && !value.startsWith("dryrun-") && !value.startsWith("local-") && !value.endsWith("-id") && !value.endsWith("-preview-id");
168
189
  }
169
190
  function buildRailwayEnv(input, scope) {
170
- const machineValues = resolveTreeseedMachineEnvironmentValues(input.context.tenantRoot, scope);
191
+ const values = resolveReconcileEnvironmentValues(input, scope);
171
192
  const token = [
172
- machineValues.RAILWAY_API_TOKEN,
193
+ values.RAILWAY_API_TOKEN,
173
194
  input.context.launchEnv.RAILWAY_API_TOKEN,
174
- process.env.RAILWAY_API_TOKEN
195
+ input.context.launchEnv.RAILWAY_API_KEY,
196
+ process.env.RAILWAY_API_TOKEN,
197
+ process.env.RAILWAY_API_KEY
175
198
  ].find((value) => typeof value === "string" && value.trim().length > 0)?.trim() ?? "";
176
199
  return {
177
200
  RAILWAY_API_TOKEN: token,
178
- TREESEED_RAILWAY_API_URL: machineValues.TREESEED_RAILWAY_API_URL ?? input.context.launchEnv.TREESEED_RAILWAY_API_URL ?? process.env.TREESEED_RAILWAY_API_URL ?? "",
179
- TREESEED_RAILWAY_WORKSPACE: machineValues.TREESEED_RAILWAY_WORKSPACE ?? input.context.launchEnv.TREESEED_RAILWAY_WORKSPACE ?? process.env.TREESEED_RAILWAY_WORKSPACE ?? ""
201
+ TREESEED_RAILWAY_API_URL: values.TREESEED_RAILWAY_API_URL ?? input.context.launchEnv.TREESEED_RAILWAY_API_URL ?? process.env.TREESEED_RAILWAY_API_URL ?? "",
202
+ TREESEED_RAILWAY_WORKSPACE: values.TREESEED_RAILWAY_WORKSPACE ?? input.context.launchEnv.TREESEED_RAILWAY_WORKSPACE ?? process.env.TREESEED_RAILWAY_WORKSPACE ?? ""
180
203
  };
181
204
  }
182
205
  function findCloudflareQueueByName(input, env, expectedName, { attempts = 6, delayMs = 350 } = {}) {
@@ -434,7 +457,7 @@ ${result.stdout ?? ""}`;
434
457
  function collectCloudflareEnvironmentSync(input) {
435
458
  const target = toDeployTarget(input.context.target);
436
459
  const scope = scopeFromTarget(target);
437
- const values = resolveTreeseedMachineEnvironmentValues(input.context.tenantRoot, scope);
460
+ const values = resolveReconcileEnvironmentValues(input, scope);
438
461
  const registry = collectTreeseedEnvironmentContext(input.context.tenantRoot);
439
462
  const state = loadDeployState(input.context.tenantRoot, input.context.deployConfig, { target });
440
463
  const generatedSecrets = buildSecretMap(input.context.deployConfig, state);
@@ -1463,7 +1486,7 @@ async function observeRailwayUnit(input, { refresh = false } = {}) {
1463
1486
  }
1464
1487
  function collectRailwayEnvironmentSync(input) {
1465
1488
  const scope = input.context.target.kind === "persistent" ? input.context.target.scope : "staging";
1466
- const values = resolveTreeseedMachineEnvironmentValues(input.context.tenantRoot, scope);
1489
+ const values = resolveReconcileEnvironmentValues(input, scope);
1467
1490
  const registry = collectTreeseedEnvironmentContext(input.context.tenantRoot);
1468
1491
  const state = loadDeployState(input.context.tenantRoot, input.context.deployConfig, { target: toDeployTarget(input.context.target) });
1469
1492
  const secrets = Object.fromEntries(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {