@neat.is/core 0.6.2-dev.20260723 → 0.6.2

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.
@@ -31,7 +31,7 @@ import {
31
31
  touchLastSeen,
32
32
  upsertObservedEdge,
33
33
  writeAtomically
34
- } from "./chunk-ZZ3VUCWL.js";
34
+ } from "./chunk-AOWANF2K.js";
35
35
  import {
36
36
  assertBindAuthority,
37
37
  buildOtelReceiver,
@@ -160,6 +160,7 @@ function startConnectorPollLoop(connector, ctx, graph, resolveTarget, options =
160
160
  }
161
161
  })();
162
162
  };
163
+ tick();
163
164
  const interval = setInterval(tick, intervalMs);
164
165
  if (typeof interval.unref === "function") interval.unref();
165
166
  return () => {
@@ -762,17 +763,22 @@ function readRailwayToken(credentials) {
762
763
  }
763
764
  return token;
764
765
  }
765
- function projectAccessTokenHeader(token) {
766
- return { "Project-Access-Token": token };
766
+ var RAILWAY_AUTH_STYLES = ["bearer", "project-access-token"];
767
+ function railwayAuthHeader(style, token) {
768
+ return style === "bearer" ? { Authorization: `Bearer ${token}` } : { "Project-Access-Token": token };
767
769
  }
768
- async function railwayGraphQL(apiUrl, token, query, variables, accountKey, fetchImpl) {
770
+ var resolvedRailwayAuthStyle = /* @__PURE__ */ new Map();
771
+ function isRailwayNotAuthorized(err) {
772
+ return err instanceof Error && /not authorized/i.test(err.message);
773
+ }
774
+ async function railwayGraphQLOnce(apiUrl, style, token, query, variables, accountKey, fetchImpl) {
769
775
  const res = await junctionFetch(
770
776
  apiUrl,
771
777
  {
772
778
  method: "POST",
773
779
  headers: {
774
780
  "Content-Type": "application/json",
775
- ...projectAccessTokenHeader(token)
781
+ ...railwayAuthHeader(style, token)
776
782
  },
777
783
  body: JSON.stringify({ query, variables })
778
784
  },
@@ -788,6 +794,26 @@ async function railwayGraphQL(apiUrl, token, query, variables, accountKey, fetch
788
794
  if (!body.data) throw new Error("Railway GraphQL response carried no data");
789
795
  return body.data;
790
796
  }
797
+ async function railwayGraphQL(apiUrl, token, query, variables, accountKey, fetchImpl) {
798
+ const known = resolvedRailwayAuthStyle.get(token);
799
+ const styles = known ? [known] : RAILWAY_AUTH_STYLES;
800
+ let lastNotAuthorized;
801
+ for (let i = 0; i < styles.length; i++) {
802
+ const style = styles[i];
803
+ try {
804
+ const data = await railwayGraphQLOnce(apiUrl, style, token, query, variables, accountKey, fetchImpl);
805
+ resolvedRailwayAuthStyle.set(token, style);
806
+ return data;
807
+ } catch (err) {
808
+ if (isRailwayNotAuthorized(err) && i < styles.length - 1) {
809
+ lastNotAuthorized = err;
810
+ continue;
811
+ }
812
+ throw err;
813
+ }
814
+ }
815
+ throw lastNotAuthorized ?? new Error("Railway GraphQL: no auth style resolved");
816
+ }
791
817
  var HTTP_LOGS_QUERY = `
792
818
  query HttpLogs($deploymentId: String!, $startDate: String, $endDate: String, $limit: Int) {
793
819
  httpLogs(deploymentId: $deploymentId, startDate: $startDate, endDate: $endDate, limit: $limit) {
@@ -1906,6 +1932,27 @@ async function loadConnectorRegistrations(input) {
1906
1932
  }
1907
1933
  return registrations;
1908
1934
  }
1935
+ async function startConnectorPolling(input) {
1936
+ const fileConnectors = input.home ? await loadConnectorRegistrations({
1937
+ project: input.project,
1938
+ graph: input.graph,
1939
+ home: input.home,
1940
+ ...input.onSkip ? { onSkip: input.onSkip } : {}
1941
+ }) : [];
1942
+ const all = [...input.extra ?? [], ...fileConnectors];
1943
+ const stopFns = all.map(
1944
+ (registration) => startConnectorPollLoop(
1945
+ registration.connector,
1946
+ { projectDir: input.projectDir, credentials: registration.credentials },
1947
+ input.graph,
1948
+ registration.resolveTarget,
1949
+ { intervalMs: registration.intervalMs, connectorId: registration.id }
1950
+ )
1951
+ );
1952
+ return () => {
1953
+ for (const stop of stopFns) stop();
1954
+ };
1955
+ }
1909
1956
  function resolvePushEntry(entry, env) {
1910
1957
  const dispatch = PUSH_PROVIDER_DISPATCH[entry.provider];
1911
1958
  if (!dispatch) {
@@ -2167,31 +2214,16 @@ async function bootstrapProject(entry, connectors = [], neatHome) {
2167
2214
  staleEventsPath: paths.staleEventsPath,
2168
2215
  project: entry.name
2169
2216
  });
2170
- const fileConnectors = neatHome ? await loadConnectorRegistrations({
2217
+ const stopConnectors = await startConnectorPolling({
2171
2218
  project: entry.name,
2172
2219
  graph,
2173
- home: neatHome,
2220
+ projectDir: entry.path,
2221
+ ...neatHome ? { home: neatHome } : {},
2222
+ extra: connectors,
2174
2223
  onSkip: (skipped, reason) => console.warn(
2175
2224
  `neatd: connector "${skipped.id}" (${skipped.provider}) skipped for project "${entry.name}" \u2014 ${reason}`
2176
2225
  )
2177
- }) : [];
2178
- const allConnectors = [...connectors, ...fileConnectors];
2179
- const stopFns = allConnectors.map(
2180
- (registration) => startConnectorPollLoop(
2181
- registration.connector,
2182
- { projectDir: entry.path, credentials: registration.credentials },
2183
- graph,
2184
- registration.resolveTarget,
2185
- // `connectorId` is threaded through so every tick lands in the
2186
- // in-process status tracker the connector-status endpoint reads
2187
- // (ADR-136). Undefined for a programmatic registration, which records
2188
- // nothing.
2189
- { intervalMs: registration.intervalMs, connectorId: registration.id }
2190
- )
2191
- );
2192
- const stopConnectors = () => {
2193
- for (const stop of stopFns) stop();
2194
- };
2226
+ });
2195
2227
  await touchLastSeen(entry.name).catch(() => {
2196
2228
  });
2197
2229
  return {
@@ -2753,6 +2785,7 @@ export {
2753
2785
  getProviderFieldSchema,
2754
2786
  knownProviderNames,
2755
2787
  validateConnectorEntry,
2788
+ startConnectorPolling,
2756
2789
  provisionConnector,
2757
2790
  deprovisionConnector,
2758
2791
  readDaemonRecord,
@@ -2765,4 +2798,4 @@ export {
2765
2798
  resolveHost,
2766
2799
  startDaemon
2767
2800
  };
2768
- //# sourceMappingURL=chunk-64JJOXES.js.map
2801
+ //# sourceMappingURL=chunk-MSZ4NALT.js.map