@treeseed/sdk 0.12.25 → 0.12.26

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.
@@ -60,6 +60,7 @@ import {
60
60
  getRailwayServiceInstance,
61
61
  getRailwayProject,
62
62
  listRailwayCustomDomains,
63
+ listRailwayServiceDomains,
63
64
  listRailwayEnvironments,
64
65
  listRailwayProjects,
65
66
  listRailwayServices,
@@ -2374,6 +2375,52 @@ async function ensureRailwayCustomDomain(input, service, domain, env, identifier
2374
2375
  }
2375
2376
  return ensured.domain;
2376
2377
  }
2378
+ async function observeRailwayCustomDomainLive(input, domain) {
2379
+ if (!domain) {
2380
+ return null;
2381
+ }
2382
+ const scope = input.context.target.kind === "persistent" ? input.context.target.scope : "staging";
2383
+ const serviceKey = String(input.unit.metadata.serviceKey ?? "api").trim();
2384
+ const topology = await resolveRailwayTopologyForScope(input, scope, {
2385
+ refresh: true,
2386
+ serviceKeys: [serviceKey],
2387
+ includeInstances: false,
2388
+ includeVariables: false
2389
+ });
2390
+ const entry = topology.services.get(serviceKey) ?? null;
2391
+ const identifiers = {
2392
+ projectId: entry?.project?.id ?? null,
2393
+ environmentId: entry?.environment?.id ?? null,
2394
+ serviceId: entry?.service?.id ?? null
2395
+ };
2396
+ if (!identifiers.projectId || !identifiers.environmentId || !identifiers.serviceId) {
2397
+ return null;
2398
+ }
2399
+ const [customDomains, serviceDomains] = await Promise.all([
2400
+ listRailwayCustomDomains({
2401
+ projectId: identifiers.projectId,
2402
+ environmentId: identifiers.environmentId,
2403
+ serviceId: identifiers.serviceId,
2404
+ env: topology.env
2405
+ }),
2406
+ listRailwayServiceDomains({
2407
+ projectId: identifiers.projectId,
2408
+ environmentId: identifiers.environmentId,
2409
+ serviceId: identifiers.serviceId,
2410
+ env: topology.env
2411
+ })
2412
+ ]);
2413
+ const customDomain = customDomains.find((entry2) => entry2.domain === domain) ?? null;
2414
+ if (!customDomain) {
2415
+ return null;
2416
+ }
2417
+ const serviceDomain = serviceDomains.find((entry2) => entry2.kind === "service") ?? null;
2418
+ const normalized = normalizeRailwayDomainPayload({
2419
+ ...customDomain,
2420
+ serviceDomain: serviceDomain?.domain ?? null
2421
+ });
2422
+ return normalized?.domain ? normalized : customDomain;
2423
+ }
2377
2424
  function collectCloudflareEnvironmentSync(input) {
2378
2425
  const target = toDeployTarget(input.context.target);
2379
2426
  const scope = scopeFromTarget(target);
@@ -4680,7 +4727,7 @@ function resolveDesiredDnsRecords(input) {
4680
4727
  }
4681
4728
  return desiredRecords;
4682
4729
  }
4683
- function observeCustomDomainUnit(input) {
4730
+ async function observeCustomDomainUnit(input) {
4684
4731
  switch (input.unit.unitType) {
4685
4732
  case "custom-domain:web": {
4686
4733
  const env = buildCloudflareEnv(input);
@@ -4703,7 +4750,7 @@ function observeCustomDomainUnit(input) {
4703
4750
  }
4704
4751
  case "custom-domain:api": {
4705
4752
  const domain = String(input.unit.spec.domain ?? "").trim();
4706
- const live = getCustomDomainState(input, "railway", domain) ?? input.persistedState?.lastObservedState ?? input.persistedState?.lastReconciledState ?? null;
4753
+ const live = getCustomDomainState(input, "railway", domain) ?? await observeRailwayCustomDomainLive(input, domain) ?? input.persistedState?.lastObservedState ?? input.persistedState?.lastReconciledState ?? null;
4707
4754
  if (live?.domain) {
4708
4755
  storeCustomDomainState(input, "railway", domain, live);
4709
4756
  }
@@ -4746,7 +4793,7 @@ function observeDnsRecordUnit(input) {
4746
4793
  warnings: desiredRecords.length === 0 ? ["No desired DNS records were available for verification."] : []
4747
4794
  };
4748
4795
  }
4749
- function verifyCustomDomainUnit(input) {
4796
+ async function verifyCustomDomainUnit(input) {
4750
4797
  switch (input.unit.unitType) {
4751
4798
  case "custom-domain:web": {
4752
4799
  const domain = String(input.unit.spec.domain ?? "").trim();
@@ -4764,7 +4811,7 @@ function verifyCustomDomainUnit(input) {
4764
4811
  }
4765
4812
  case "custom-domain:api": {
4766
4813
  const domain = String(input.unit.spec.domain ?? "").trim();
4767
- const live = getCustomDomainState(input, "railway", domain) ?? getPersistedCustomDomainState(input, "railway", domain) ?? input.persistedState?.lastObservedState ?? input.persistedState?.lastReconciledState ?? null;
4814
+ const live = getCustomDomainState(input, "railway", domain) ?? await observeRailwayCustomDomainLive(input, domain) ?? getPersistedCustomDomainState(input, "railway", domain) ?? input.persistedState?.lastObservedState ?? input.persistedState?.lastReconciledState ?? null;
4768
4815
  const dnsRecords = Array.isArray(live?.dnsRecords) ? live.dnsRecords : [];
4769
4816
  const certificateStatus = typeof live?.certificateStatus === "string" ? live.certificateStatus.trim().toUpperCase() : null;
4770
4817
  const verified = live?.verified === true;
@@ -4854,7 +4901,7 @@ async function reconcileCustomDomainUnit(input, diff) {
4854
4901
  const projectName = String(input.unit.spec.projectName ?? "").trim();
4855
4902
  const state = ensureCloudflarePagesDomain(env, projectName, domain) ?? { domain };
4856
4903
  storeCustomDomainState(input, "cloudflare", domain, state);
4857
- const observed = observeCustomDomainUnit(input);
4904
+ const observed = await observeCustomDomainUnit(input);
4858
4905
  return {
4859
4906
  unit: input.unit,
4860
4907
  observed,
@@ -4891,7 +4938,7 @@ async function reconcileCustomDomainUnit(input, diff) {
4891
4938
  }
4892
4939
  );
4893
4940
  storeCustomDomainState(input, "railway", String(input.unit.spec.domain ?? "").trim(), state);
4894
- const observed = observeCustomDomainUnit(input);
4941
+ const observed = await observeCustomDomainUnit(input);
4895
4942
  return {
4896
4943
  unit: input.unit,
4897
4944
  observed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.12.25",
3
+ "version": "0.12.26",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {