@neat.is/core 0.9.18-dev.20260917 → 0.9.18-dev.20260918

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.
package/dist/index.d.cts CHANGED
@@ -564,6 +564,7 @@ interface ProjectSlot {
564
564
  stopPersist: () => void;
565
565
  stopStaleness: () => void;
566
566
  stopConnectors: () => void;
567
+ stopHostedConnectors: () => void;
567
568
  stopK8sSubstrate: () => void;
568
569
  detachEvents: () => void;
569
570
  status: 'active' | 'broken';
package/dist/index.d.ts CHANGED
@@ -564,6 +564,7 @@ interface ProjectSlot {
564
564
  stopPersist: () => void;
565
565
  stopStaleness: () => void;
566
566
  stopConnectors: () => void;
567
+ stopHostedConnectors: () => void;
567
568
  stopK8sSubstrate: () => void;
568
569
  detachEvents: () => void;
569
570
  status: 'active' | 'broken';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  routeSpanToProject,
3
3
  startDaemon
4
- } from "./chunk-NV4WWJSU.js";
4
+ } from "./chunk-MGQSR6QZ.js";
5
5
  import {
6
6
  ProjectNameCollisionError,
7
7
  addProject,
@@ -37,7 +37,7 @@ import {
37
37
  thresholdForEdgeType,
38
38
  touchLastSeen,
39
39
  writeAtomically
40
- } from "./chunk-SSLPBQWY.js";
40
+ } from "./chunk-KIV7OB2K.js";
41
41
  import {
42
42
  startOtelGrpcReceiver
43
43
  } from "./chunk-ERE47MCR.js";
package/dist/neatd.cjs CHANGED
@@ -19063,7 +19063,8 @@ function startConnectorPollLoop(connector, ctx, graph, resolveTarget, options =
19063
19063
  void (async () => {
19064
19064
  const tickStartedAt = (/* @__PURE__ */ new Date()).toISOString();
19065
19065
  try {
19066
- const result = await runConnectorPoll(connector, { ...ctx, since }, graph, resolveTarget);
19066
+ const credentials = options.refreshCredentials ? await options.refreshCredentials() : ctx.credentials;
19067
+ const result = await runConnectorPoll(connector, { ...ctx, credentials, since }, graph, resolveTarget);
19067
19068
  since = tickStartedAt;
19068
19069
  if (connectorId) {
19069
19070
  recordConnectorPoll(connectorId, {
@@ -23296,6 +23297,122 @@ async function reconcileFrontierSurfaces(graph, errorsPath) {
23296
23297
  stageHangSurfaces(graph, incidents);
23297
23298
  }
23298
23299
 
23300
+ // src/connectors/hosted.ts
23301
+ init_cjs_shims();
23302
+ var CREDENTIAL_REFRESH_SKEW_MS = 6e4;
23303
+ var CP_REQUEST_TIMEOUT_MS = 1e4;
23304
+ async function cpGet(path80, deps) {
23305
+ const f = deps.fetchImpl ?? fetch;
23306
+ const res = await f(`${deps.cpUrl.replace(/\/+$/, "")}${path80}`, {
23307
+ headers: { authorization: `Bearer ${deps.daemonToken}`, accept: "application/json" },
23308
+ signal: AbortSignal.timeout(CP_REQUEST_TIMEOUT_MS)
23309
+ });
23310
+ if (!res.ok) throw new Error(`control plane ${path80} \u2192 HTTP ${res.status}`);
23311
+ return await res.json();
23312
+ }
23313
+ function credentialRecord(provider, cred) {
23314
+ switch (provider) {
23315
+ case "supabase":
23316
+ return { managementToken: cred.accessToken };
23317
+ default:
23318
+ return { token: cred.accessToken };
23319
+ }
23320
+ }
23321
+ function hostedOptions(provider, summary, serviceName) {
23322
+ switch (provider) {
23323
+ case "supabase": {
23324
+ const ref = summary.projectRef;
23325
+ if (!ref) return null;
23326
+ return { apiProjectRef: ref, nodeRef: `${ref}.supabase.co`, serviceName };
23327
+ }
23328
+ default:
23329
+ return null;
23330
+ }
23331
+ }
23332
+ function createHostedCredentialSource(provider, deps) {
23333
+ let cached = null;
23334
+ return async () => {
23335
+ if (cached && cached.expiresAtMs - CREDENTIAL_REFRESH_SKEW_MS > Date.now()) return cached.record;
23336
+ const cred = await cpGet(
23337
+ `/internal/projects/${deps.projectId}/connections/${provider}/credential`,
23338
+ deps
23339
+ );
23340
+ const record = credentialRecord(provider, cred);
23341
+ const parsed = cred.expiresAt ? Date.parse(cred.expiresAt) : Number.NaN;
23342
+ cached = { record, expiresAtMs: Number.isFinite(parsed) ? parsed : Number.POSITIVE_INFINITY };
23343
+ return record;
23344
+ };
23345
+ }
23346
+ async function startHostedConnectors(input) {
23347
+ const { deps, graph, projectDir, project, errorsPath, onSkip } = input;
23348
+ const startLoop = input.startLoop ?? startConnectorPollLoop;
23349
+ let connections;
23350
+ try {
23351
+ connections = await cpGet(`/internal/projects/${deps.projectId}/connections`, deps);
23352
+ } catch (err) {
23353
+ onSkip?.("(all)", `control plane connection list unreadable \u2014 ${err.message}`);
23354
+ return () => {
23355
+ };
23356
+ }
23357
+ if (!Array.isArray(connections)) return () => {
23358
+ };
23359
+ const stops = [];
23360
+ for (const c of connections) {
23361
+ const dispatch = PROVIDER_DISPATCH[c.provider];
23362
+ if (!dispatch) {
23363
+ onSkip?.(c.provider, "no pull connector for this provider");
23364
+ continue;
23365
+ }
23366
+ if (c.needsProjectSelection || !c.projectRef) {
23367
+ onSkip?.(c.provider, "no project selected yet \u2014 not pullable");
23368
+ continue;
23369
+ }
23370
+ const options = hostedOptions(c.provider, c, project);
23371
+ if (!options) {
23372
+ onSkip?.(c.provider, "no hosted option mapping for this provider");
23373
+ continue;
23374
+ }
23375
+ let built;
23376
+ try {
23377
+ built = dispatch.build(graph, options);
23378
+ } catch (err) {
23379
+ onSkip?.(c.provider, err.message);
23380
+ continue;
23381
+ }
23382
+ stops.push(
23383
+ startLoop(
23384
+ built.connector,
23385
+ { projectDir, project, credentials: {}, ...errorsPath ? { errorsPath } : {} },
23386
+ graph,
23387
+ built.resolveTarget,
23388
+ {
23389
+ connectorId: `hosted:${c.provider}`,
23390
+ refreshCredentials: createHostedCredentialSource(c.provider, deps)
23391
+ }
23392
+ )
23393
+ );
23394
+ }
23395
+ return () => {
23396
+ for (const stop of stops) stop();
23397
+ };
23398
+ }
23399
+ async function maybeStartHostedConnectors(input) {
23400
+ const env = input.env ?? process.env;
23401
+ const cpUrl = env.NEAT_CP_URL;
23402
+ const projectId = env.NEAT_CP_PROJECT_ID;
23403
+ const daemonToken = env.NEAT_AUTH_TOKEN;
23404
+ if (!cpUrl || !projectId || !daemonToken) return () => {
23405
+ };
23406
+ return startHostedConnectors({
23407
+ deps: { cpUrl, projectId, daemonToken, ...input.fetchImpl ? { fetchImpl: input.fetchImpl } : {} },
23408
+ graph: input.graph,
23409
+ projectDir: input.projectDir,
23410
+ project: input.project,
23411
+ ...input.errorsPath ? { errorsPath: input.errorsPath } : {},
23412
+ ...input.onSkip ? { onSkip: input.onSkip } : {}
23413
+ });
23414
+ }
23415
+
23299
23416
  // src/connectors/kubernetes/index.ts
23300
23417
  init_cjs_shims();
23301
23418
 
@@ -23872,6 +23989,10 @@ function teardownSlot(slot) {
23872
23989
  slot.stopConnectors();
23873
23990
  } catch {
23874
23991
  }
23992
+ try {
23993
+ slot.stopHostedConnectors();
23994
+ } catch {
23995
+ }
23875
23996
  try {
23876
23997
  slot.stopK8sSubstrate();
23877
23998
  } catch {
@@ -23960,6 +24081,8 @@ async function bootstrapProject(entry2, connectors = [], neatHome4) {
23960
24081
  },
23961
24082
  stopConnectors: () => {
23962
24083
  },
24084
+ stopHostedConnectors: () => {
24085
+ },
23963
24086
  stopK8sSubstrate: () => {
23964
24087
  },
23965
24088
  detachEvents: () => {
@@ -23998,6 +24121,13 @@ async function bootstrapProject(entry2, connectors = [], neatHome4) {
23998
24121
  `neatd: connector "${skipped.id}" (${skipped.provider}) skipped for project "${entry2.name}" \u2014 ${reason}`
23999
24122
  )
24000
24123
  });
24124
+ const stopHostedConnectors = await maybeStartHostedConnectors({
24125
+ project: entry2.name,
24126
+ graph,
24127
+ projectDir: entry2.path,
24128
+ errorsPath: paths.errorsPath,
24129
+ onSkip: (provider, reason) => console.warn(`neatd: hosted connector "${provider}" skipped for project "${entry2.name}" \u2014 ${reason}`)
24130
+ });
24001
24131
  const stopK8sSubstrate = await startK8sSubstratePolling({
24002
24132
  project: entry2.name,
24003
24133
  graph,
@@ -24016,6 +24146,7 @@ async function bootstrapProject(entry2, connectors = [], neatHome4) {
24016
24146
  stopPersist,
24017
24147
  stopStaleness,
24018
24148
  stopConnectors,
24149
+ stopHostedConnectors,
24019
24150
  stopK8sSubstrate,
24020
24151
  detachEvents,
24021
24152
  status: "active"