@indigoai-us/hq-cloud 6.11.5 → 6.11.6

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.
Files changed (81) hide show
  1. package/dist/bin/sync-runner.d.ts +16 -16
  2. package/dist/bin/sync-runner.d.ts.map +1 -1
  3. package/dist/bin/sync-runner.js +50 -41
  4. package/dist/bin/sync-runner.js.map +1 -1
  5. package/dist/bin/sync-runner.test.js +107 -33
  6. package/dist/bin/sync-runner.test.js.map +1 -1
  7. package/dist/context.d.ts +6 -0
  8. package/dist/context.d.ts.map +1 -1
  9. package/dist/context.js +57 -17
  10. package/dist/context.js.map +1 -1
  11. package/dist/context.test.js +113 -1
  12. package/dist/context.test.js.map +1 -1
  13. package/dist/entity-resolver.test.js +3 -3
  14. package/dist/entity-resolver.test.js.map +1 -1
  15. package/dist/object-io.d.ts.map +1 -1
  16. package/dist/object-io.js +10 -0
  17. package/dist/object-io.js.map +1 -1
  18. package/dist/signals/get.d.ts.map +1 -1
  19. package/dist/signals/get.js +7 -11
  20. package/dist/signals/get.js.map +1 -1
  21. package/dist/signals/get.test.js +65 -1
  22. package/dist/signals/get.test.js.map +1 -1
  23. package/dist/signals/internals.d.ts +47 -3
  24. package/dist/signals/internals.d.ts.map +1 -1
  25. package/dist/signals/internals.js +110 -4
  26. package/dist/signals/internals.js.map +1 -1
  27. package/dist/signals/list.d.ts.map +1 -1
  28. package/dist/signals/list.js +16 -23
  29. package/dist/signals/list.js.map +1 -1
  30. package/dist/signals/list.test.js +84 -1
  31. package/dist/signals/list.test.js.map +1 -1
  32. package/dist/signals/types.d.ts +18 -1
  33. package/dist/signals/types.d.ts.map +1 -1
  34. package/dist/sources/get.d.ts.map +1 -1
  35. package/dist/sources/get.js +10 -22
  36. package/dist/sources/get.js.map +1 -1
  37. package/dist/sources/get.test.js +85 -1
  38. package/dist/sources/get.test.js.map +1 -1
  39. package/dist/sources/internals.d.ts +50 -3
  40. package/dist/sources/internals.d.ts.map +1 -1
  41. package/dist/sources/internals.js +113 -4
  42. package/dist/sources/internals.js.map +1 -1
  43. package/dist/sources/list.d.ts.map +1 -1
  44. package/dist/sources/list.js +16 -23
  45. package/dist/sources/list.js.map +1 -1
  46. package/dist/sources/list.test.js +101 -1
  47. package/dist/sources/list.test.js.map +1 -1
  48. package/dist/sources/types.d.ts +18 -1
  49. package/dist/sources/types.d.ts.map +1 -1
  50. package/dist/sync/event-sync.d.ts +6 -7
  51. package/dist/sync/event-sync.d.ts.map +1 -1
  52. package/dist/sync/event-sync.js +6 -7
  53. package/dist/sync/event-sync.js.map +1 -1
  54. package/dist/types.d.ts +33 -3
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/version.d.ts +14 -0
  57. package/dist/version.d.ts.map +1 -0
  58. package/dist/version.js +20 -0
  59. package/dist/version.js.map +1 -0
  60. package/package.json +1 -1
  61. package/src/bin/sync-runner.test.ts +130 -41
  62. package/src/bin/sync-runner.ts +55 -48
  63. package/src/context.test.ts +139 -1
  64. package/src/context.ts +59 -17
  65. package/src/entity-resolver.test.ts +3 -3
  66. package/src/object-io.ts +12 -0
  67. package/src/signals/get.test.ts +83 -1
  68. package/src/signals/get.ts +9 -13
  69. package/src/signals/internals.ts +153 -4
  70. package/src/signals/list.test.ts +114 -1
  71. package/src/signals/list.ts +16 -29
  72. package/src/signals/types.ts +18 -1
  73. package/src/sources/get.test.ts +104 -1
  74. package/src/sources/get.ts +12 -24
  75. package/src/sources/internals.ts +156 -4
  76. package/src/sources/list.test.ts +132 -1
  77. package/src/sources/list.ts +16 -29
  78. package/src/sources/types.ts +18 -1
  79. package/src/sync/event-sync.ts +6 -7
  80. package/src/types.ts +33 -3
  81. package/src/version.ts +24 -0
@@ -1,15 +1,37 @@
1
1
  /**
2
2
  * Internal helpers shared between sources/list.ts and sources/get.ts.
3
3
  *
4
- * The S3 client factory hook exists so tests can inject an in-memory stub
5
- * without standing up vi.mock for @aws-sdk/client-s3. Production code never
6
- * calls the setter.
4
+ * Two transports back the read surface:
5
+ * - presigned-URL (HQ-59): when a vault client is supplied AND the entity is a
6
+ * company vault (cmp_*), reads go through the vault `list`/`presign`
7
+ * endpoints — the client never talks to S3 directly. This is the path every
8
+ * company read should take going forward.
9
+ * - direct S3 (legacy / personal): no vault client, or a personal vault
10
+ * (prs_*, whose membership-less creds 403 the membership-gated presign
11
+ * endpoints). Goes through `getS3Client`, whose factory hook lets tests
12
+ * inject an in-memory stub without vi.mock.
7
13
  */
8
14
 
9
- import { S3Client } from "@aws-sdk/client-s3";
15
+ import {
16
+ S3Client,
17
+ GetObjectCommand,
18
+ ListObjectsV2Command,
19
+ } from "@aws-sdk/client-s3";
10
20
  import type { EntityContext } from "../types.js";
21
+ import { PresignObjectIO, type PresignTransportClient } from "../object-io.js";
11
22
 
12
23
  function defaultFactory(ctx: EntityContext): S3Client {
24
+ if (!ctx.credentials) {
25
+ // The direct-S3 read path needs STS creds. A credential-less context only
26
+ // exists on the presign path (HQ-59 company vend-skip), which reads via the
27
+ // vault list/presign endpoints, not this S3 client — so arriving here with
28
+ // no creds is a routing bug. Fail loudly rather than 403 opaquely later.
29
+ throw new Error(
30
+ `Sources S3 read for ${ctx.uid} requires STS credentials but got a ` +
31
+ `presign-only context; company presign reads must go through the ` +
32
+ `vault transport, not getS3Client.`,
33
+ );
34
+ }
13
35
  return new S3Client({
14
36
  region: ctx.region,
15
37
  credentials: {
@@ -44,3 +66,133 @@ export async function streamToString(body: unknown): Promise<string> {
44
66
  }
45
67
  return Buffer.concat(chunks).toString("utf-8");
46
68
  }
69
+
70
+ // ---------------------------------------------------------------------------
71
+ // Transport seam (presign for cmp_, direct-S3 otherwise)
72
+ // ---------------------------------------------------------------------------
73
+
74
+ /** Common shape of every reader's options: an entity + an optional vault client. */
75
+ export interface ReaderTransportOpts {
76
+ entity: EntityContext;
77
+ /**
78
+ * Presign-capable vault client. When supplied and the entity is a company
79
+ * vault (cmp_*), reads use the presigned-URL transport instead of direct S3.
80
+ */
81
+ vault?: PresignTransportClient;
82
+ }
83
+
84
+ /** Lightweight listed object (transport-agnostic). */
85
+ export interface ListedKey {
86
+ key: string;
87
+ size: number;
88
+ lastModified: Date;
89
+ }
90
+
91
+ /** True when this read should use the presigned-URL transport. */
92
+ export function usePresign(opts: ReaderTransportOpts): boolean {
93
+ return opts.vault != null && opts.entity.uid.startsWith("cmp_");
94
+ }
95
+
96
+ /** A not-found error normalized to the S3 `NoSuchKey` shape callers test for. */
97
+ function noSuchKeyError(key: string): Error {
98
+ return Object.assign(new Error(`No such key: ${key}`), { name: "NoSuchKey" });
99
+ }
100
+
101
+ function isNotFound(err: unknown): boolean {
102
+ if (!err || typeof err !== "object") return false;
103
+ const name = (err as { name?: unknown }).name;
104
+ return (
105
+ name === "NoSuchKey" || name === "NoSuchKeyException" || name === "NotFound"
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Read an object's UTF-8 text. Throws a `NoSuchKey`-named error when the object
111
+ * is absent (both transports), so callers' existing not-found checks work
112
+ * unchanged.
113
+ */
114
+ export async function readObjectText(
115
+ opts: ReaderTransportOpts,
116
+ key: string,
117
+ ): Promise<string> {
118
+ if (usePresign(opts)) {
119
+ const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
120
+ try {
121
+ const { body } = await io.getObject(key);
122
+ return body.toString("utf-8");
123
+ } catch (err) {
124
+ if (isNotFound(err)) throw noSuchKeyError(key);
125
+ throw err;
126
+ }
127
+ }
128
+ const client = getS3Client(opts.entity);
129
+ const res = await client.send(
130
+ new GetObjectCommand({ Bucket: opts.entity.bucketName, Key: key }),
131
+ );
132
+ return streamToString(res.Body);
133
+ }
134
+
135
+ /** Like {@link readObjectText} but returns null when the object is absent. */
136
+ export async function tryReadObjectText(
137
+ opts: ReaderTransportOpts,
138
+ key: string,
139
+ ): Promise<string | null> {
140
+ try {
141
+ return await readObjectText(opts, key);
142
+ } catch (err) {
143
+ if (isNotFound(err)) return null;
144
+ throw err;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * List one page of objects under `prefix`.
150
+ *
151
+ * Under the presigned transport the vault `list` endpoint is ACL-filtered and
152
+ * controls page size server-side, so `limit` is advisory — paginate via the
153
+ * returned `nextToken` (the opaque vault cursor) until it is undefined. Under
154
+ * direct S3, `limit` maps to `MaxKeys`.
155
+ */
156
+ export async function listObjects(
157
+ opts: ReaderTransportOpts,
158
+ prefix: string,
159
+ page: { limit?: number; continuationToken?: string },
160
+ ): Promise<{ contents: ListedKey[]; nextToken?: string }> {
161
+ if (usePresign(opts)) {
162
+ const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
163
+ const res = await io.listObjects({
164
+ prefix,
165
+ continuationToken: page.continuationToken,
166
+ });
167
+ return {
168
+ contents: res.objects.map((o) => ({
169
+ key: o.key,
170
+ size: o.size,
171
+ lastModified: o.lastModified,
172
+ })),
173
+ nextToken: res.nextContinuationToken,
174
+ };
175
+ }
176
+ const client = getS3Client(opts.entity);
177
+ const res = await client.send(
178
+ new ListObjectsV2Command({
179
+ Bucket: opts.entity.bucketName,
180
+ Prefix: prefix,
181
+ MaxKeys: page.limit,
182
+ ContinuationToken: page.continuationToken,
183
+ }),
184
+ );
185
+ const contents: ListedKey[] = [];
186
+ for (const obj of res.Contents ?? []) {
187
+ if (!obj.Key) continue;
188
+ contents.push({
189
+ key: obj.Key,
190
+ size: obj.Size ?? 0,
191
+ lastModified: obj.LastModified ?? new Date(0),
192
+ });
193
+ }
194
+ return {
195
+ contents,
196
+ nextToken: res.IsTruncated ? res.NextContinuationToken : undefined,
197
+ };
198
+ }
@@ -5,7 +5,7 @@
5
5
  * hook so we don't have to stand up vi.mock for @aws-sdk/client-s3.
6
6
  */
7
7
 
8
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
8
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
9
9
  import {
10
10
  GetObjectCommand,
11
11
  ListObjectsV2Command,
@@ -16,6 +16,8 @@ import {
16
16
  _setSourcesS3Factory,
17
17
  _resetSourcesS3Factory,
18
18
  } from "./internals.js";
19
+ import type { PresignTransportClient } from "../object-io.js";
20
+ import type { VaultListedObject } from "../vault-client.js";
19
21
  import type { EntityContext } from "../types.js";
20
22
  import { InvalidSourceChannelError } from "../schemas/source-channels.js";
21
23
 
@@ -245,3 +247,132 @@ describe("listSources", () => {
245
247
  expect(observed.commands).toHaveLength(0);
246
248
  });
247
249
  });
250
+
251
+ // ---------------------------------------------------------------------------
252
+ // Presigned transport (vault client + company vault) — HQ-59
253
+ // ---------------------------------------------------------------------------
254
+
255
+ interface PresignVaultStub {
256
+ vault: PresignTransportClient;
257
+ listCalls: Array<{ prefix?: string; cursor?: string }>;
258
+ }
259
+
260
+ /**
261
+ * Vault stub for the list path: `listFiles` returns the configured ACL-filtered
262
+ * page (the server is the ACL boundary — only readable keys come back) + an
263
+ * opaque cursor; `presign`+fetch serve per-entry frontmatter GETs.
264
+ */
265
+ function makePresignVault(
266
+ page: { objects: VaultListedObject[]; cursor: string | null },
267
+ contents: Record<string, string> = {},
268
+ ): PresignVaultStub {
269
+ const listCalls: Array<{ prefix?: string; cursor?: string }> = [];
270
+ vi.stubGlobal(
271
+ "fetch",
272
+ vi.fn(async (url: string) => {
273
+ const key = new URL(url).searchParams.get("key") ?? "";
274
+ const c = contents[key];
275
+ if (c === undefined) return new Response(null, { status: 404 });
276
+ return new Response(Buffer.from(c, "utf-8"), { status: 200 });
277
+ }),
278
+ );
279
+ const vault: PresignTransportClient = {
280
+ presign: async (input) => ({
281
+ results: input.keys.map((k) => ({
282
+ key: k.key,
283
+ op: k.op ?? input.op ?? "get",
284
+ url: `https://signed.example/?key=${encodeURIComponent(k.key)}`,
285
+ })),
286
+ expiresAt: "2099-01-01T00:00:00.000Z",
287
+ }),
288
+ listFiles: async (_company, prefix, cursor) => {
289
+ listCalls.push({ prefix, cursor });
290
+ return {
291
+ objects: page.objects,
292
+ cursor: page.cursor,
293
+ truncated: page.cursor != null,
294
+ };
295
+ },
296
+ };
297
+ return { vault, listCalls };
298
+ }
299
+
300
+ function listed(key: string): VaultListedObject {
301
+ return {
302
+ key,
303
+ size: 10,
304
+ lastModified: "2026-02-01T00:00:00.000Z",
305
+ etag: "etag",
306
+ permission: "read",
307
+ };
308
+ }
309
+
310
+ describe("listSources — presigned transport (vault + cmp_)", () => {
311
+ afterEach(() => vi.unstubAllGlobals());
312
+
313
+ it("lists via the ACL-filtered vault endpoint and never touches S3", async () => {
314
+ _setSourcesS3Factory(
315
+ () =>
316
+ ({
317
+ send: async () => {
318
+ throw new Error("S3 must not be used on the presign path");
319
+ },
320
+ }) as unknown as S3Client,
321
+ );
322
+ const { vault, listCalls } = makePresignVault({
323
+ objects: [listed("sources/meetings/a.md"), listed("sources/meetings/a.raw.json")],
324
+ cursor: null,
325
+ });
326
+
327
+ const res = await listSources({ entity: ENTITY, channel: "meeting", vault });
328
+
329
+ // .raw.json sibling is skipped; only the .md entry surfaces.
330
+ expect(res.entries.map((e) => e.sourceId)).toEqual(["a"]);
331
+ expect(res.entries[0].key).toBe("sources/meetings/a.md");
332
+ expect(res.nextToken).toBeUndefined();
333
+ // listFiles was called with the channel prefix (ACL filtering is server-side).
334
+ expect(listCalls[0].prefix).toBe("sources/meetings/");
335
+ });
336
+
337
+ it("surfaces the opaque vault cursor as nextToken (advisory limit)", async () => {
338
+ const { vault } = makePresignVault({
339
+ objects: [listed("sources/meetings/a.md")],
340
+ cursor: "OPAQUE_CURSOR",
341
+ });
342
+ const res = await listSources({
343
+ entity: ENTITY,
344
+ channel: "meeting",
345
+ limit: 1,
346
+ vault,
347
+ });
348
+ expect(res.nextToken).toBe("OPAQUE_CURSOR");
349
+ });
350
+
351
+ it("includeFrontmatter parses each entry via a presigned GET", async () => {
352
+ const { vault } = makePresignVault(
353
+ { objects: [listed("sources/meetings/a.md")], cursor: null },
354
+ { "sources/meetings/a.md": MEETING_MD },
355
+ );
356
+ const res = await listSources({
357
+ entity: ENTITY,
358
+ channel: "meeting",
359
+ includeFrontmatter: true,
360
+ vault,
361
+ });
362
+ expect(res.entries[0].frontmatter).toMatchObject({ title: "Hello" });
363
+ });
364
+
365
+ it("forwards the continuationToken as the vault cursor", async () => {
366
+ const { vault, listCalls } = makePresignVault({
367
+ objects: [],
368
+ cursor: null,
369
+ });
370
+ await listSources({
371
+ entity: ENTITY,
372
+ channel: "meeting",
373
+ continuationToken: "RESUME_HERE",
374
+ vault,
375
+ });
376
+ expect(listCalls[0].cursor).toBe("RESUME_HERE");
377
+ });
378
+ });
@@ -6,12 +6,8 @@
6
6
  * the summary (callers fetch them via getSource({ includeRaw: true })).
7
7
  */
8
8
 
9
- import {
10
- GetObjectCommand,
11
- ListObjectsV2Command,
12
- } from "@aws-sdk/client-s3";
13
9
  import { assertSourceChannel, sourcePathSegment } from "../schemas/source-channels.js";
14
- import { getS3Client, streamToString } from "./internals.js";
10
+ import { listObjects, readObjectText } from "./internals.js";
15
11
  import { parseFrontmatter } from "./parse.js";
16
12
  import type {
17
13
  ListSourcesOptions,
@@ -40,46 +36,37 @@ function deriveSourceId(
40
36
  }
41
37
 
42
38
  export async function listSources(opts: ListSourcesOptions): Promise<ListSourcesResult> {
43
- // Validate channel BEFORE any S3 call (acceptance criterion).
39
+ // Validate channel BEFORE any read (acceptance criterion).
44
40
  assertSourceChannel(opts.channel);
45
41
 
46
- const client = getS3Client(opts.entity);
47
42
  // Use the canonical path segment from the schema; channel "meeting" maps
48
43
  // to the plural "meetings/" prefix the sources-pipeline writes to.
49
44
  const prefix = `sources/${sourcePathSegment(opts.channel)}/`;
50
45
 
51
- const response = await client.send(
52
- new ListObjectsV2Command({
53
- Bucket: opts.entity.bucketName,
54
- Prefix: prefix,
55
- MaxKeys: opts.limit,
56
- ContinuationToken: opts.continuationToken,
57
- }),
58
- );
46
+ // Presign transport ACL-filters server-side and controls page size, so
47
+ // `limit` is advisory there; under direct S3 it maps to MaxKeys. Paginate via
48
+ // the returned nextToken regardless of transport.
49
+ const page = await listObjects(opts, prefix, {
50
+ limit: opts.limit,
51
+ continuationToken: opts.continuationToken,
52
+ });
59
53
 
60
54
  const entries: SourceSummary[] = [];
61
- for (const obj of response.Contents ?? []) {
62
- if (!obj.Key) continue;
63
- const derived = deriveSourceId(obj.Key, prefix);
55
+ for (const obj of page.contents) {
56
+ const derived = deriveSourceId(obj.key, prefix);
64
57
  if (!derived || derived.isRawSibling) continue;
65
58
 
66
59
  const summary: SourceSummary = {
67
60
  sourceId: derived.sourceId,
68
61
  channel: opts.channel,
69
- key: obj.Key,
70
- lastModified: obj.LastModified ?? new Date(0),
71
- size: obj.Size ?? 0,
62
+ key: obj.key,
63
+ lastModified: obj.lastModified,
64
+ size: obj.size,
72
65
  };
73
66
 
74
67
  if (opts.includeFrontmatter) {
75
68
  try {
76
- const get = await client.send(
77
- new GetObjectCommand({
78
- Bucket: opts.entity.bucketName,
79
- Key: obj.Key,
80
- }),
81
- );
82
- const text = await streamToString(get.Body);
69
+ const text = await readObjectText(opts, obj.key);
83
70
  const fm = parseFrontmatter(text);
84
71
  if (fm) summary.frontmatter = fm;
85
72
  } catch {
@@ -92,6 +79,6 @@ export async function listSources(opts: ListSourcesOptions): Promise<ListSources
92
79
 
93
80
  return {
94
81
  entries,
95
- nextToken: response.IsTruncated ? response.NextContinuationToken : undefined,
82
+ nextToken: page.nextToken,
96
83
  };
97
84
  }
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import type { SourceChannel } from "../schemas/source-channels.js";
9
+ import type { PresignTransportClient } from "../object-io.js";
9
10
 
10
11
  /**
11
12
  * Lightweight summary returned by listSources(). `frontmatter` is only
@@ -44,12 +45,23 @@ export interface SourceDocument {
44
45
  export interface ListSourcesOptions {
45
46
  entity: import("../types.js").EntityContext;
46
47
  channel: SourceChannel;
47
- /** Max keys per page; defaults to S3 default (1000). */
48
+ /**
49
+ * Max keys per page. Under direct S3 this maps to `MaxKeys`; under the
50
+ * presigned transport ({@link vault} + a company vault) it is advisory — the
51
+ * vault `list` endpoint controls page size server-side. Defaults to the S3
52
+ * default (1000) on the direct path.
53
+ */
48
54
  limit?: number;
49
55
  /** Opaque continuation token returned by a prior page. */
50
56
  continuationToken?: string;
51
57
  /** When true, fetches+parses each entry's frontmatter (extra GETs). */
52
58
  includeFrontmatter?: boolean;
59
+ /**
60
+ * Presign-capable vault client. When supplied and {@link entity} is a company
61
+ * vault (cmp_*), reads use the presigned-URL transport (ACL-filtered, no
62
+ * direct S3). Personal vaults and the absent-client path stay on direct S3.
63
+ */
64
+ vault?: PresignTransportClient;
53
65
  }
54
66
 
55
67
  export interface ListSourcesResult {
@@ -64,4 +76,9 @@ export interface GetSourceOptions {
64
76
  sourceId: string;
65
77
  /** When true, also fetches the `.raw.json` sibling. */
66
78
  includeRaw?: boolean;
79
+ /**
80
+ * Presign-capable vault client. When supplied and {@link entity} is a company
81
+ * vault (cmp_*), reads use the presigned-URL transport (no direct S3).
82
+ */
83
+ vault?: PresignTransportClient;
67
84
  }
@@ -7,9 +7,8 @@
7
7
  * runner's receiver seam defaults to {@link NoopPushReceiver}. This module is
8
8
  * the connective tissue that turns both on for enrolled accounts:
9
9
  *
10
- * - {@link resolveEventSync} — the rollout gate. EXACT-email allowlist
11
- * (mirrors `resolvePresignTransport`'s shape in sync-runner.ts, but full
12
- * address, not domain suffix) + `HQ_SYNC_EVENT_SYNC` env override in both
10
+ * - {@link resolveEventSync} — the rollout gate. EXACT-email allowlist (full
11
+ * address, not a domain suffix) + `HQ_SYNC_EVENT_SYNC` env override in both
13
12
  * directions. ONE gate governs publish AND receive so a device is never
14
13
  * publish-only or receive-only in a half-rolled state.
15
14
  * - {@link subscribeSyncReceive} — `POST /v1/sync/subscribe` (US-015/US-016):
@@ -58,8 +57,8 @@ import type { TreeChangeBatch } from "../watcher.js";
58
57
  * single-account Phase 3 rollout (2026-06-10) targets the operator's own
59
58
  * devices; `xhassaan@getindigo.ai` and `hassaan@getindigo.ai.evil.com` must
60
59
  * never match. Broadening later is an entry here, then a domain set, then a
61
- * GA default-on switch (the path the presigned-URL transport already took in
62
- * `resolvePresignTransport`).
60
+ * GA default-on switch (the same rollout path the presigned-URL sync transport
61
+ * already took to GA).
63
62
  */
64
63
  export const EVENT_SYNC_ROLLOUT_EMAILS: ReadonlySet<string> = new Set([
65
64
  "hassaan@getindigo.ai",
@@ -68,8 +67,8 @@ export const EVENT_SYNC_ROLLOUT_EMAILS: ReadonlySet<string> = new Set([
68
67
  /**
69
68
  * Decide whether this session runs event-driven sync (publish + receive).
70
69
  *
71
- * Mirrors `resolvePresignTransport` precedence: `HQ_SYNC_EVENT_SYNC`
72
- * overrides in both directions (`1`/`true`/`yes`/`on` → force on,
70
+ * Env-override-in-both-directions precedence: `HQ_SYNC_EVENT_SYNC`
71
+ * overrides (`1`/`true`/`yes`/`on` → force on,
73
72
  * `0`/`false`/`no`/`off` → force off) so unenrolled testers can exercise it
74
73
  * and enrolled accounts can be rolled back without a release. An unset/blank
75
74
  * override falls through to the exact-email check; an unrecognized override
package/src/types.ts CHANGED
@@ -155,9 +155,26 @@ export interface EntityContext {
155
155
  bucketName: string;
156
156
  /** AWS region */
157
157
  region: string;
158
- /** STS-scoped credentials */
159
- credentials: VaultCredentials;
160
- /** When the credentials expire (ISO 8601) */
158
+ /**
159
+ * STS-scoped credentials.
160
+ *
161
+ * Absent for presign-only COMPANY contexts (HQ-59): when a run uses the
162
+ * presigned-URL transport for company vaults (`companyVaultUsesPresign`),
163
+ * `resolveEntityContext` skips the `POST /sts/vend` call entirely — the
164
+ * presign transport authorizes each object server-side and never reads these
165
+ * creds, and a compliant sync-runner must NOT hit the company vend route
166
+ * (the route-presence signal the hq-pro min-version gate keys on). The only
167
+ * reader of these creds is the direct-S3 (`S3SdkObjectIO`) path, which is
168
+ * used for personal vaults (`prs_*`, still vended) and pre-presign clients —
169
+ * never for a `cmp_*` context built on the presign path. That path throws
170
+ * loudly if it ever receives a credential-less context.
171
+ */
172
+ credentials?: VaultCredentials;
173
+ /**
174
+ * When the credentials expire (ISO 8601). For a presign-only company context
175
+ * (no STS vend) this is a far-future sentinel so `isExpiringSoon` is always
176
+ * false and no auto-refresh ever re-vends the skipped company route.
177
+ */
161
178
  expiresAt: string;
162
179
  }
163
180
 
@@ -209,6 +226,19 @@ export interface VaultServiceConfig {
209
226
  * Optional for back-compat, but all first-party clients should pass it.
210
227
  */
211
228
  clientInfo?: ClientInfo;
229
+ /**
230
+ * When true, COMPANY vaults (`cmp_*`) use the presigned-URL transport, so
231
+ * `resolveEntityContext` SKIPS `POST /sts/vend` for them and returns a
232
+ * credential-less context with a far-future `expiresAt` (HQ-59). Set by the
233
+ * sync-runner exactly when it installs the presign transport factory, so the
234
+ * vend-skip and the transport choice can never diverge. Personal vaults
235
+ * (`prs_*`) are unaffected — they always vend self via `/sts/vend-self`.
236
+ *
237
+ * Leaving this unset (the default) preserves the historical behavior: every
238
+ * context vends STS creds. Non-runner callers (standalone `hq sync`, hq-cli)
239
+ * that keep the direct-S3 path for company vaults must NOT set this.
240
+ */
241
+ companyVaultUsesPresign?: boolean;
212
242
  }
213
243
 
214
244
  // ── Conflict index (consumed by /resolve-conflicts) ─────────────────────────
package/src/version.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The hq-cloud package version, read once at module load.
3
+ *
4
+ * Mirrors hq-cli's `cli-version.ts` pattern: resolve the version from the
5
+ * package.json at runtime via `import.meta.url` (rootDir-safe — no JSON import
6
+ * that would trip `tsc`'s rootDir, and resolves correctly from both `src/`
7
+ * during tests and `dist/` at runtime). Used to stamp `clientInfo.version` on
8
+ * the sync-runner's vault requests so the company-vend min-version gate (HQ-59,
9
+ * hq-pro) can tell a compliant (>= 6.11.6) sync-runner from a pre-6.11.6
10
+ * straggler. This is the hq-cloud package version — the version the gate
11
+ * compares against its floor — NOT the hq-sync desktop app version.
12
+ */
13
+
14
+ import { readFileSync } from "node:fs";
15
+ import { fileURLToPath } from "node:url";
16
+ import path from "node:path";
17
+
18
+ const here = path.dirname(fileURLToPath(import.meta.url));
19
+ // src/version.ts → dist/version.js; one level up from either is the package root.
20
+ const pkg = JSON.parse(
21
+ readFileSync(path.resolve(here, "..", "package.json"), "utf-8"),
22
+ ) as { name: string; version: string };
23
+
24
+ export const HQ_CLOUD_VERSION: string = pkg.version;