@indigoai-us/hq-cloud 5.26.0 → 5.28.0
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/.github/workflows/ci.yml +34 -0
- package/dist/bin/sync-runner.d.ts +38 -0
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +75 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/sync/feature-flags.d.ts +136 -0
- package/dist/sync/feature-flags.d.ts.map +1 -0
- package/dist/sync/feature-flags.js +160 -0
- package/dist/sync/feature-flags.js.map +1 -0
- package/dist/sync/feature-flags.test.d.ts +24 -0
- package/dist/sync/feature-flags.test.d.ts.map +1 -0
- package/dist/sync/feature-flags.test.js +330 -0
- package/dist/sync/feature-flags.test.js.map +1 -0
- package/dist/sync/index.d.ts +10 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +5 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/logger.d.ts +61 -0
- package/dist/sync/logger.d.ts.map +1 -0
- package/dist/sync/logger.js +51 -0
- package/dist/sync/logger.js.map +1 -0
- package/dist/sync/logger.test.d.ts +19 -0
- package/dist/sync/logger.test.d.ts.map +1 -0
- package/dist/sync/logger.test.js +199 -0
- package/dist/sync/logger.test.js.map +1 -0
- package/dist/sync/metrics.d.ts +89 -0
- package/dist/sync/metrics.d.ts.map +1 -0
- package/dist/sync/metrics.js +105 -0
- package/dist/sync/metrics.js.map +1 -0
- package/dist/sync/metrics.test.d.ts +19 -0
- package/dist/sync/metrics.test.d.ts.map +1 -0
- package/dist/sync/metrics.test.js +280 -0
- package/dist/sync/metrics.test.js.map +1 -0
- package/dist/sync/push-receiver.d.ts +442 -0
- package/dist/sync/push-receiver.d.ts.map +1 -0
- package/dist/sync/push-receiver.js +782 -0
- package/dist/sync/push-receiver.js.map +1 -0
- package/dist/sync/push-receiver.test.d.ts +25 -0
- package/dist/sync/push-receiver.test.d.ts.map +1 -0
- package/dist/sync/push-receiver.test.js +477 -0
- package/dist/sync/push-receiver.test.js.map +1 -0
- package/dist/sync/push-transport.d.ts +84 -1
- package/dist/sync/push-transport.d.ts.map +1 -1
- package/dist/sync/push-transport.js +84 -0
- package/dist/sync/push-transport.js.map +1 -1
- package/dist/watcher.d.ts +127 -11
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +294 -57
- package/dist/watcher.js.map +1 -1
- package/package.json +9 -5
- package/src/bin/sync-runner.ts +102 -1
- package/src/index.ts +21 -0
- package/src/sync/feature-flags.test.ts +392 -0
- package/src/sync/feature-flags.ts +229 -0
- package/src/sync/index.ts +57 -2
- package/src/sync/logger.test.ts +241 -0
- package/src/sync/logger.ts +79 -0
- package/src/sync/metrics.test.ts +380 -0
- package/src/sync/metrics.ts +158 -0
- package/src/sync/push-receiver.test.ts +545 -0
- package/src/sync/push-receiver.ts +1077 -0
- package/src/sync/push-transport.ts +148 -1
- package/src/watcher.ts +408 -51
- package/test/e2e/sync/cross-tenant-isolation.test.ts +502 -0
- package/test/e2e/watcher-real-chokidar.test.ts +105 -0
- package/test/e2e/watcher-recursive-backend.test.ts +115 -0
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* @indigoai-us/hq-cloud (Path B) per project event-driven-sync-menubar US-007.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import type
|
|
34
|
+
import { encodePushEvent, type PushEvent } from "./push-event.js";
|
|
35
35
|
|
|
36
36
|
export interface PushTransport {
|
|
37
37
|
/** Open sockets, refresh tokens. Awaited before the watcher starts. */
|
|
@@ -82,3 +82,150 @@ export class NoopPushTransport implements PushTransport {
|
|
|
82
82
|
this._connected = false;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
// ─── HttpPushTransport ───────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Minimal fetch surface so tests can inject a mocked `fetch` without pulling
|
|
90
|
+
* in DOM/undici types. Matches the subset of the global `fetch` we use.
|
|
91
|
+
*/
|
|
92
|
+
export type FetchLike = (
|
|
93
|
+
input: string,
|
|
94
|
+
init?: {
|
|
95
|
+
method?: string;
|
|
96
|
+
headers?: Record<string, string>;
|
|
97
|
+
body?: string;
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
},
|
|
100
|
+
) => Promise<{ ok: boolean; status: number; text(): Promise<string> }>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Async getter for the current Cognito access token. Long-running daemons MUST
|
|
104
|
+
* pass a getter (not a captured string) so each publish resolves the freshest
|
|
105
|
+
* token — mirrors {@link VaultServiceConfig.authToken} semantics in types.ts.
|
|
106
|
+
* A static string is also accepted for short-lived tools and tests.
|
|
107
|
+
*/
|
|
108
|
+
export type AuthTokenSource = string | (() => string | Promise<string>);
|
|
109
|
+
|
|
110
|
+
export interface HttpPushTransportOptions {
|
|
111
|
+
/**
|
|
112
|
+
* Vault API base URL (e.g. `https://vault-api.example.com`). The same
|
|
113
|
+
* `apiUrl` the runner already resolves for VaultClient. Trailing slashes
|
|
114
|
+
* are stripped. Required — config/env-driven, no hard-coded default.
|
|
115
|
+
*/
|
|
116
|
+
apiUrl: string;
|
|
117
|
+
/**
|
|
118
|
+
* Endpoint path the PushEvent is POSTed to. Defaults to `/sync/push`
|
|
119
|
+
* (matches the deployed hq-pro endpoint from US-006). Override for testing
|
|
120
|
+
* or future endpoint moves.
|
|
121
|
+
*/
|
|
122
|
+
pushPath?: string;
|
|
123
|
+
/** Cognito JWT — static string OR async getter. See {@link AuthTokenSource}. */
|
|
124
|
+
authToken: AuthTokenSource;
|
|
125
|
+
/**
|
|
126
|
+
* Optional extra headers (e.g. client identification) merged onto every
|
|
127
|
+
* request. Authorization + Content-Type are always set by the transport.
|
|
128
|
+
*/
|
|
129
|
+
headers?: Record<string, string>;
|
|
130
|
+
/**
|
|
131
|
+
* Per-request timeout in milliseconds. Default 10_000. On timeout the
|
|
132
|
+
* publish rejects — the daemon treats a rejected publish as a transient
|
|
133
|
+
* miss (the cadence poll still covers it) and MUST NOT crash.
|
|
134
|
+
*/
|
|
135
|
+
timeoutMs?: number;
|
|
136
|
+
/** Injectable fetch (tests). Defaults to the global `fetch`. */
|
|
137
|
+
fetchImpl?: FetchLike;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Real client `PushTransport` that POSTs encoded PushEvents to the deployed
|
|
142
|
+
* `/sync/push` endpoint, authenticating with the menubar's existing Cognito
|
|
143
|
+
* bearer token — the same auth path VaultClient uses (Authorization: Bearer
|
|
144
|
+
* <accessToken>, token resolved per-request via the supplied getter so it
|
|
145
|
+
* self-heals across refreshes).
|
|
146
|
+
*
|
|
147
|
+
* Failure posture
|
|
148
|
+
* ───────────────
|
|
149
|
+
* `publish()` rejects on a network error, a non-2xx response, or a timeout.
|
|
150
|
+
* The DAEMON is responsible for not letting that rejection crash it — the
|
|
151
|
+
* watcher's emit path catches publish errors and logs them; the periodic
|
|
152
|
+
* cadence poll remains the safety net that eventually ships the change. This
|
|
153
|
+
* transport never swallows errors itself, so callers retain full visibility.
|
|
154
|
+
*
|
|
155
|
+
* `connected` flips true on `start()` and false on `dispose()`. It is purely
|
|
156
|
+
* advisory (HTTP is connectionless); the health endpoint may read it but it
|
|
157
|
+
* carries no delivery guarantee.
|
|
158
|
+
*/
|
|
159
|
+
export class HttpPushTransport implements PushTransport {
|
|
160
|
+
private readonly apiUrl: string;
|
|
161
|
+
private readonly pushPath: string;
|
|
162
|
+
private readonly getAuthToken: () => Promise<string>;
|
|
163
|
+
private readonly extraHeaders: Record<string, string>;
|
|
164
|
+
private readonly timeoutMs: number;
|
|
165
|
+
private readonly fetchImpl: FetchLike;
|
|
166
|
+
private _connected = false;
|
|
167
|
+
|
|
168
|
+
constructor(opts: HttpPushTransportOptions) {
|
|
169
|
+
if (!opts.apiUrl || opts.apiUrl.trim() === "") {
|
|
170
|
+
throw new Error("HttpPushTransport: apiUrl is required");
|
|
171
|
+
}
|
|
172
|
+
this.apiUrl = opts.apiUrl.replace(/\/+$/, "");
|
|
173
|
+
const path = opts.pushPath ?? "/sync/push";
|
|
174
|
+
this.pushPath = path.startsWith("/") ? path : `/${path}`;
|
|
175
|
+
const tok = opts.authToken;
|
|
176
|
+
// Normalize string|getter into a single async getter (mirrors VaultClient).
|
|
177
|
+
this.getAuthToken =
|
|
178
|
+
typeof tok === "function" ? async () => tok() : async () => tok;
|
|
179
|
+
this.extraHeaders = opts.headers ?? {};
|
|
180
|
+
this.timeoutMs = opts.timeoutMs ?? 10_000;
|
|
181
|
+
// Bind so a destructured global fetch keeps its receiver.
|
|
182
|
+
this.fetchImpl =
|
|
183
|
+
opts.fetchImpl ??
|
|
184
|
+
((input, init) => (globalThis.fetch as unknown as FetchLike)(input, init));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
get connected(): boolean {
|
|
188
|
+
return this._connected;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async start(): Promise<void> {
|
|
192
|
+
this._connected = true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async publish(event: PushEvent): Promise<void> {
|
|
196
|
+
// Validate-on-encode (US-007 contract) — a malformed event throws a typed
|
|
197
|
+
// PushEventDecodeError BEFORE we hit the network.
|
|
198
|
+
const body = encodePushEvent(event);
|
|
199
|
+
const token = await this.getAuthToken();
|
|
200
|
+
|
|
201
|
+
const controller = new AbortController();
|
|
202
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
203
|
+
try {
|
|
204
|
+
const res = await this.fetchImpl(`${this.apiUrl}${this.pushPath}`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
...this.extraHeaders,
|
|
208
|
+
Authorization: `Bearer ${token}`,
|
|
209
|
+
"Content-Type": "application/json",
|
|
210
|
+
Accept: "application/json",
|
|
211
|
+
},
|
|
212
|
+
body,
|
|
213
|
+
signal: controller.signal,
|
|
214
|
+
});
|
|
215
|
+
if (!res.ok) {
|
|
216
|
+
const text = await res.text().catch(() => "");
|
|
217
|
+
throw new Error(
|
|
218
|
+
`HttpPushTransport: POST ${this.pushPath} failed (${res.status})${
|
|
219
|
+
text ? `: ${text}` : ""
|
|
220
|
+
}`,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
} finally {
|
|
224
|
+
clearTimeout(timer);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async dispose(): Promise<void> {
|
|
229
|
+
this._connected = false;
|
|
230
|
+
}
|
|
231
|
+
}
|