@indigoai-us/hq-cloud 6.11.4 → 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.
- package/dist/bin/sync-runner.d.ts +16 -16
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +50 -41
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +107 -33
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/context.d.ts +6 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +57 -17
- package/dist/context.js.map +1 -1
- package/dist/context.test.js +113 -1
- package/dist/context.test.js.map +1 -1
- package/dist/entity-resolver.test.js +3 -3
- package/dist/entity-resolver.test.js.map +1 -1
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +10 -0
- package/dist/object-io.js.map +1 -1
- package/dist/personal-vault-exclusions.d.ts.map +1 -1
- package/dist/personal-vault-exclusions.js +11 -0
- package/dist/personal-vault-exclusions.js.map +1 -1
- package/dist/personal-vault-exclusions.test.js +5 -0
- package/dist/personal-vault-exclusions.test.js.map +1 -1
- package/dist/signals/get.d.ts.map +1 -1
- package/dist/signals/get.js +7 -11
- package/dist/signals/get.js.map +1 -1
- package/dist/signals/get.test.js +65 -1
- package/dist/signals/get.test.js.map +1 -1
- package/dist/signals/internals.d.ts +47 -3
- package/dist/signals/internals.d.ts.map +1 -1
- package/dist/signals/internals.js +110 -4
- package/dist/signals/internals.js.map +1 -1
- package/dist/signals/list.d.ts.map +1 -1
- package/dist/signals/list.js +16 -23
- package/dist/signals/list.js.map +1 -1
- package/dist/signals/list.test.js +84 -1
- package/dist/signals/list.test.js.map +1 -1
- package/dist/signals/types.d.ts +18 -1
- package/dist/signals/types.d.ts.map +1 -1
- package/dist/sources/get.d.ts.map +1 -1
- package/dist/sources/get.js +10 -22
- package/dist/sources/get.js.map +1 -1
- package/dist/sources/get.test.js +85 -1
- package/dist/sources/get.test.js.map +1 -1
- package/dist/sources/internals.d.ts +50 -3
- package/dist/sources/internals.d.ts.map +1 -1
- package/dist/sources/internals.js +113 -4
- package/dist/sources/internals.js.map +1 -1
- package/dist/sources/list.d.ts.map +1 -1
- package/dist/sources/list.js +16 -23
- package/dist/sources/list.js.map +1 -1
- package/dist/sources/list.test.js +101 -1
- package/dist/sources/list.test.js.map +1 -1
- package/dist/sources/types.d.ts +18 -1
- package/dist/sources/types.d.ts.map +1 -1
- package/dist/sync/event-sync.d.ts +6 -7
- package/dist/sync/event-sync.d.ts.map +1 -1
- package/dist/sync/event-sync.js +6 -7
- package/dist/sync/event-sync.js.map +1 -1
- package/dist/types.d.ts +33 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +20 -0
- package/dist/version.js.map +1 -0
- package/package.json +1 -1
- package/src/bin/sync-runner.test.ts +130 -41
- package/src/bin/sync-runner.ts +55 -48
- package/src/context.test.ts +139 -1
- package/src/context.ts +59 -17
- package/src/entity-resolver.test.ts +3 -3
- package/src/object-io.ts +12 -0
- package/src/personal-vault-exclusions.test.ts +5 -0
- package/src/personal-vault-exclusions.ts +11 -0
- package/src/signals/get.test.ts +83 -1
- package/src/signals/get.ts +9 -13
- package/src/signals/internals.ts +153 -4
- package/src/signals/list.test.ts +114 -1
- package/src/signals/list.ts +16 -29
- package/src/signals/types.ts +18 -1
- package/src/sources/get.test.ts +104 -1
- package/src/sources/get.ts +12 -24
- package/src/sources/internals.ts +156 -4
- package/src/sources/list.test.ts +132 -1
- package/src/sources/list.ts +16 -29
- package/src/sources/types.ts +18 -1
- package/src/sync/event-sync.ts +6 -7
- package/src/types.ts +33 -3
- package/src/version.ts +24 -0
|
@@ -188,6 +188,17 @@ export const PERSONAL_VAULT_DEFAULT_EXCLUSIONS: readonly PersonalVaultExclusion[
|
|
|
188
188
|
pattern: "**/node_modules/**",
|
|
189
189
|
test: (p) => hasSegment(p, "node_modules"),
|
|
190
190
|
},
|
|
191
|
+
{
|
|
192
|
+
// pnpm's content-addressed store. Tens of thousands of cache files that
|
|
193
|
+
// regenerate on `pnpm install` — never personal data, pure churn. The
|
|
194
|
+
// company sync already ignores it (DEFAULT_IGNORES `.pnpm-store/`); the
|
|
195
|
+
// personal vault used a separate exclusion list that missed it, so the
|
|
196
|
+
// cache round-tripped to the vault and dominated the personal sync count.
|
|
197
|
+
id: "pnpm-store",
|
|
198
|
+
category: "build-output",
|
|
199
|
+
pattern: "**/.pnpm-store/**",
|
|
200
|
+
test: (p) => hasSegment(p, ".pnpm-store"),
|
|
201
|
+
},
|
|
191
202
|
{
|
|
192
203
|
id: "dist-dir",
|
|
193
204
|
category: "build-output",
|
package/src/signals/get.test.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Unit tests for signals/get.ts.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
5
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
6
6
|
import { GetObjectCommand, type S3Client } from "@aws-sdk/client-s3";
|
|
7
7
|
import { getSignal, SignalNotFoundError } from "./get.js";
|
|
8
8
|
import {
|
|
9
9
|
_setSignalsS3Factory,
|
|
10
10
|
_resetSignalsS3Factory,
|
|
11
11
|
} from "./internals.js";
|
|
12
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
12
13
|
import type { EntityContext } from "../types.js";
|
|
13
14
|
import { InvalidSignalTypeError } from "../schemas/signal-types.js";
|
|
14
15
|
|
|
@@ -202,3 +203,84 @@ Body.
|
|
|
202
203
|
expect(doc.entityRefs).toEqual(["kept@example.com"]);
|
|
203
204
|
});
|
|
204
205
|
});
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Presigned transport (vault client + company vault) — HQ-59
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
function makePresignVault(objects: Record<string, string>): PresignTransportClient {
|
|
212
|
+
vi.stubGlobal(
|
|
213
|
+
"fetch",
|
|
214
|
+
vi.fn(async (url: string) => {
|
|
215
|
+
const key = new URL(url).searchParams.get("key") ?? "";
|
|
216
|
+
const content = objects[key];
|
|
217
|
+
if (content === undefined) return new Response(null, { status: 404 });
|
|
218
|
+
return new Response(Buffer.from(content, "utf-8"), { status: 200 });
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
return {
|
|
222
|
+
presign: async (input) => ({
|
|
223
|
+
results: input.keys.map((k) => ({
|
|
224
|
+
key: k.key,
|
|
225
|
+
op: k.op ?? input.op ?? "get",
|
|
226
|
+
url: `https://signed.example/?key=${encodeURIComponent(k.key)}`,
|
|
227
|
+
})),
|
|
228
|
+
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
229
|
+
}),
|
|
230
|
+
listFiles: async () => ({ objects: [], cursor: null, truncated: false }),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
describe("getSignal — presigned transport (vault + cmp_)", () => {
|
|
235
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
236
|
+
|
|
237
|
+
it("reads via presign (no S3) and surfaces typed cross-refs", async () => {
|
|
238
|
+
_setSignalsS3Factory(
|
|
239
|
+
() =>
|
|
240
|
+
({
|
|
241
|
+
send: async () => {
|
|
242
|
+
throw new Error("S3 must not be used on the presign path");
|
|
243
|
+
},
|
|
244
|
+
}) as unknown as S3Client,
|
|
245
|
+
);
|
|
246
|
+
const vault = makePresignVault({ "signals/action_item/foo.md": ACTION_ITEM_MD });
|
|
247
|
+
|
|
248
|
+
const doc = await getSignal({
|
|
249
|
+
entity: ENTITY,
|
|
250
|
+
signalType: "action_item",
|
|
251
|
+
signalId: "foo",
|
|
252
|
+
vault,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(doc.sourceRef).toBe("abc-meeting-001");
|
|
256
|
+
expect(doc.entityRefs).toEqual(["stefan@indigoai.us", "corey@indigoai.us"]);
|
|
257
|
+
expect(doc.body).toContain("Stefan will review");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("maps a presign 404 to SignalNotFoundError", async () => {
|
|
261
|
+
const vault = makePresignVault({});
|
|
262
|
+
await expect(
|
|
263
|
+
getSignal({
|
|
264
|
+
entity: ENTITY,
|
|
265
|
+
signalType: "action_item",
|
|
266
|
+
signalId: "missing",
|
|
267
|
+
vault,
|
|
268
|
+
}),
|
|
269
|
+
).rejects.toBeInstanceOf(SignalNotFoundError);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("personal vault (prs_) ignores the vault client and stays on direct S3", async () => {
|
|
273
|
+
installStub({ "signals/action_item/foo.md": ACTION_ITEM_MD });
|
|
274
|
+
const vault = makePresignVault({});
|
|
275
|
+
const personal: EntityContext = { ...ENTITY, uid: "prs_me" };
|
|
276
|
+
|
|
277
|
+
const doc = await getSignal({
|
|
278
|
+
entity: personal,
|
|
279
|
+
signalType: "action_item",
|
|
280
|
+
signalId: "foo",
|
|
281
|
+
vault,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(doc.body).toContain("Stefan will review");
|
|
285
|
+
});
|
|
286
|
+
});
|
package/src/signals/get.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* `entityRefs` surfaced as typed fields.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
8
7
|
import { assertSignalType } from "../schemas/signal-types.js";
|
|
9
|
-
import {
|
|
8
|
+
import { readObjectText } from "./internals.js";
|
|
10
9
|
import { parseMarkdown } from "./parse.js";
|
|
11
10
|
import type { GetSignalOptions, SignalDocument } from "./types.js";
|
|
12
11
|
|
|
@@ -20,8 +19,12 @@ export class SignalNotFoundError extends Error {
|
|
|
20
19
|
function isNoSuchKey(err: unknown): boolean {
|
|
21
20
|
if (!err || typeof err !== "object") return false;
|
|
22
21
|
const name = (err as { name?: unknown }).name;
|
|
23
|
-
//
|
|
24
|
-
|
|
22
|
+
// The transport normalizes a missing object to a `NoSuchKey`-named error on
|
|
23
|
+
// both the S3 and presigned paths (a presign 404 → NoSuchKey). `NotFound` is
|
|
24
|
+
// kept for defense in depth (S3 HEAD-style errors).
|
|
25
|
+
return (
|
|
26
|
+
name === "NoSuchKey" || name === "NoSuchKeyException" || name === "NotFound"
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
function asStringArray(value: unknown): string[] | undefined {
|
|
@@ -34,21 +37,14 @@ function asStringArray(value: unknown): string[] | undefined {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
export async function getSignal(opts: GetSignalOptions): Promise<SignalDocument> {
|
|
37
|
-
// Validate signalType BEFORE any
|
|
40
|
+
// Validate signalType BEFORE any read (acceptance criterion + agent-mitigation).
|
|
38
41
|
assertSignalType(opts.signalType);
|
|
39
42
|
|
|
40
|
-
const client = getS3Client(opts.entity);
|
|
41
43
|
const key = `signals/${opts.signalType}/${opts.signalId}.md`;
|
|
42
44
|
|
|
43
45
|
let body: string;
|
|
44
46
|
try {
|
|
45
|
-
|
|
46
|
-
new GetObjectCommand({
|
|
47
|
-
Bucket: opts.entity.bucketName,
|
|
48
|
-
Key: key,
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
body = await streamToString(response.Body);
|
|
47
|
+
body = await readObjectText(opts, key);
|
|
52
48
|
} catch (err) {
|
|
53
49
|
if (isNoSuchKey(err)) {
|
|
54
50
|
throw new SignalNotFoundError(key);
|
package/src/signals/internals.ts
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal helpers shared between signals/list.ts and signals/get.ts.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Two transports back the read surface (see sources/internals.ts for the full
|
|
5
|
+
* rationale): the presigned-URL path (a vault client + a company vault, cmp_*)
|
|
6
|
+
* and the direct-S3 path (no vault client, or a personal vault prs_*). The
|
|
7
|
+
* direct-S3 path goes through `getS3Client`, whose factory hook is independent
|
|
8
|
+
* from sources/internals.ts so signals tests can swap their stub without
|
|
9
|
+
* disturbing sources tests.
|
|
7
10
|
*/
|
|
8
11
|
|
|
9
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
S3Client,
|
|
14
|
+
GetObjectCommand,
|
|
15
|
+
ListObjectsV2Command,
|
|
16
|
+
} from "@aws-sdk/client-s3";
|
|
10
17
|
import type { EntityContext } from "../types.js";
|
|
18
|
+
import { PresignObjectIO, type PresignTransportClient } from "../object-io.js";
|
|
11
19
|
|
|
12
20
|
function defaultFactory(ctx: EntityContext): S3Client {
|
|
21
|
+
if (!ctx.credentials) {
|
|
22
|
+
// The direct-S3 read path needs STS creds. A credential-less context only
|
|
23
|
+
// exists on the presign path (HQ-59 company vend-skip), which reads via the
|
|
24
|
+
// vault list/presign endpoints, not this S3 client — so arriving here with
|
|
25
|
+
// no creds is a routing bug. Fail loudly rather than 403 opaquely later.
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Signals S3 read for ${ctx.uid} requires STS credentials but got a ` +
|
|
28
|
+
`presign-only context; company presign reads must go through the ` +
|
|
29
|
+
`vault transport, not getS3Client.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
13
32
|
return new S3Client({
|
|
14
33
|
region: ctx.region,
|
|
15
34
|
credentials: {
|
|
@@ -44,3 +63,133 @@ export async function streamToString(body: unknown): Promise<string> {
|
|
|
44
63
|
}
|
|
45
64
|
return Buffer.concat(chunks).toString("utf-8");
|
|
46
65
|
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Transport seam (presign for cmp_, direct-S3 otherwise)
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
/** Common shape of every reader's options: an entity + an optional vault client. */
|
|
72
|
+
export interface ReaderTransportOpts {
|
|
73
|
+
entity: EntityContext;
|
|
74
|
+
/**
|
|
75
|
+
* Presign-capable vault client. When supplied and the entity is a company
|
|
76
|
+
* vault (cmp_*), reads use the presigned-URL transport instead of direct S3.
|
|
77
|
+
*/
|
|
78
|
+
vault?: PresignTransportClient;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Lightweight listed object (transport-agnostic). */
|
|
82
|
+
export interface ListedKey {
|
|
83
|
+
key: string;
|
|
84
|
+
size: number;
|
|
85
|
+
lastModified: Date;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** True when this read should use the presigned-URL transport. */
|
|
89
|
+
export function usePresign(opts: ReaderTransportOpts): boolean {
|
|
90
|
+
return opts.vault != null && opts.entity.uid.startsWith("cmp_");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A not-found error normalized to the S3 `NoSuchKey` shape callers test for. */
|
|
94
|
+
function noSuchKeyError(key: string): Error {
|
|
95
|
+
return Object.assign(new Error(`No such key: ${key}`), { name: "NoSuchKey" });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isNotFound(err: unknown): boolean {
|
|
99
|
+
if (!err || typeof err !== "object") return false;
|
|
100
|
+
const name = (err as { name?: unknown }).name;
|
|
101
|
+
return (
|
|
102
|
+
name === "NoSuchKey" || name === "NoSuchKeyException" || name === "NotFound"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read an object's UTF-8 text. Throws a `NoSuchKey`-named error when the object
|
|
108
|
+
* is absent (both transports), so callers' existing not-found checks work
|
|
109
|
+
* unchanged.
|
|
110
|
+
*/
|
|
111
|
+
export async function readObjectText(
|
|
112
|
+
opts: ReaderTransportOpts,
|
|
113
|
+
key: string,
|
|
114
|
+
): Promise<string> {
|
|
115
|
+
if (usePresign(opts)) {
|
|
116
|
+
const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
|
|
117
|
+
try {
|
|
118
|
+
const { body } = await io.getObject(key);
|
|
119
|
+
return body.toString("utf-8");
|
|
120
|
+
} catch (err) {
|
|
121
|
+
if (isNotFound(err)) throw noSuchKeyError(key);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const client = getS3Client(opts.entity);
|
|
126
|
+
const res = await client.send(
|
|
127
|
+
new GetObjectCommand({ Bucket: opts.entity.bucketName, Key: key }),
|
|
128
|
+
);
|
|
129
|
+
return streamToString(res.Body);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Like {@link readObjectText} but returns null when the object is absent. */
|
|
133
|
+
export async function tryReadObjectText(
|
|
134
|
+
opts: ReaderTransportOpts,
|
|
135
|
+
key: string,
|
|
136
|
+
): Promise<string | null> {
|
|
137
|
+
try {
|
|
138
|
+
return await readObjectText(opts, key);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (isNotFound(err)) return null;
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* List one page of objects under `prefix`.
|
|
147
|
+
*
|
|
148
|
+
* Under the presigned transport the vault `list` endpoint is ACL-filtered and
|
|
149
|
+
* controls page size server-side, so `limit` is advisory — paginate via the
|
|
150
|
+
* returned `nextToken` (the opaque vault cursor) until it is undefined. Under
|
|
151
|
+
* direct S3, `limit` maps to `MaxKeys`.
|
|
152
|
+
*/
|
|
153
|
+
export async function listObjects(
|
|
154
|
+
opts: ReaderTransportOpts,
|
|
155
|
+
prefix: string,
|
|
156
|
+
page: { limit?: number; continuationToken?: string },
|
|
157
|
+
): Promise<{ contents: ListedKey[]; nextToken?: string }> {
|
|
158
|
+
if (usePresign(opts)) {
|
|
159
|
+
const io = new PresignObjectIO(opts.vault!, opts.entity.uid);
|
|
160
|
+
const res = await io.listObjects({
|
|
161
|
+
prefix,
|
|
162
|
+
continuationToken: page.continuationToken,
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
contents: res.objects.map((o) => ({
|
|
166
|
+
key: o.key,
|
|
167
|
+
size: o.size,
|
|
168
|
+
lastModified: o.lastModified,
|
|
169
|
+
})),
|
|
170
|
+
nextToken: res.nextContinuationToken,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const client = getS3Client(opts.entity);
|
|
174
|
+
const res = await client.send(
|
|
175
|
+
new ListObjectsV2Command({
|
|
176
|
+
Bucket: opts.entity.bucketName,
|
|
177
|
+
Prefix: prefix,
|
|
178
|
+
MaxKeys: page.limit,
|
|
179
|
+
ContinuationToken: page.continuationToken,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
const contents: ListedKey[] = [];
|
|
183
|
+
for (const obj of res.Contents ?? []) {
|
|
184
|
+
if (!obj.Key) continue;
|
|
185
|
+
contents.push({
|
|
186
|
+
key: obj.Key,
|
|
187
|
+
size: obj.Size ?? 0,
|
|
188
|
+
lastModified: obj.LastModified ?? new Date(0),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
contents,
|
|
193
|
+
nextToken: res.IsTruncated ? res.NextContinuationToken : undefined,
|
|
194
|
+
};
|
|
195
|
+
}
|
package/src/signals/list.test.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @aws-sdk/client-s3.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
10
10
|
import {
|
|
11
11
|
GetObjectCommand,
|
|
12
12
|
ListObjectsV2Command,
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
_setSignalsS3Factory,
|
|
18
18
|
_resetSignalsS3Factory,
|
|
19
19
|
} from "./internals.js";
|
|
20
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
21
|
+
import type { VaultListedObject } from "../vault-client.js";
|
|
20
22
|
import type { EntityContext } from "../types.js";
|
|
21
23
|
import { InvalidSignalTypeError, SIGNAL_TYPES } from "../schemas/signal-types.js";
|
|
22
24
|
|
|
@@ -281,3 +283,114 @@ describe("listSignals", () => {
|
|
|
281
283
|
expect(observed.commands).toHaveLength(0);
|
|
282
284
|
});
|
|
283
285
|
});
|
|
286
|
+
|
|
287
|
+
// ---------------------------------------------------------------------------
|
|
288
|
+
// Presigned transport (vault client + company vault) — HQ-59
|
|
289
|
+
// ---------------------------------------------------------------------------
|
|
290
|
+
|
|
291
|
+
interface PresignVaultStub {
|
|
292
|
+
vault: PresignTransportClient;
|
|
293
|
+
listCalls: Array<{ prefix?: string; cursor?: string }>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function makePresignVault(
|
|
297
|
+
page: { objects: VaultListedObject[]; cursor: string | null },
|
|
298
|
+
contents: Record<string, string> = {},
|
|
299
|
+
): PresignVaultStub {
|
|
300
|
+
const listCalls: Array<{ prefix?: string; cursor?: string }> = [];
|
|
301
|
+
vi.stubGlobal(
|
|
302
|
+
"fetch",
|
|
303
|
+
vi.fn(async (url: string) => {
|
|
304
|
+
const key = new URL(url).searchParams.get("key") ?? "";
|
|
305
|
+
const c = contents[key];
|
|
306
|
+
if (c === undefined) return new Response(null, { status: 404 });
|
|
307
|
+
return new Response(Buffer.from(c, "utf-8"), { status: 200 });
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
310
|
+
const vault: PresignTransportClient = {
|
|
311
|
+
presign: async (input) => ({
|
|
312
|
+
results: input.keys.map((k) => ({
|
|
313
|
+
key: k.key,
|
|
314
|
+
op: k.op ?? input.op ?? "get",
|
|
315
|
+
url: `https://signed.example/?key=${encodeURIComponent(k.key)}`,
|
|
316
|
+
})),
|
|
317
|
+
expiresAt: "2099-01-01T00:00:00.000Z",
|
|
318
|
+
}),
|
|
319
|
+
listFiles: async (_company, prefix, cursor) => {
|
|
320
|
+
listCalls.push({ prefix, cursor });
|
|
321
|
+
return {
|
|
322
|
+
objects: page.objects,
|
|
323
|
+
cursor: page.cursor,
|
|
324
|
+
truncated: page.cursor != null,
|
|
325
|
+
};
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
return { vault, listCalls };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function listed(key: string): VaultListedObject {
|
|
332
|
+
return {
|
|
333
|
+
key,
|
|
334
|
+
size: 10,
|
|
335
|
+
lastModified: "2026-03-15T15:00:00.000Z",
|
|
336
|
+
etag: "etag",
|
|
337
|
+
permission: "read",
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
describe("listSignals — presigned transport (vault + cmp_)", () => {
|
|
342
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
343
|
+
|
|
344
|
+
it("lists via the ACL-filtered vault endpoint and never touches S3", async () => {
|
|
345
|
+
_setSignalsS3Factory(
|
|
346
|
+
() =>
|
|
347
|
+
({
|
|
348
|
+
send: async () => {
|
|
349
|
+
throw new Error("S3 must not be used on the presign path");
|
|
350
|
+
},
|
|
351
|
+
}) as unknown as S3Client,
|
|
352
|
+
);
|
|
353
|
+
const { vault, listCalls } = makePresignVault({
|
|
354
|
+
objects: [listed("signals/action_item/foo.md")],
|
|
355
|
+
cursor: null,
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const res = await listSignals({
|
|
359
|
+
entity: ENTITY,
|
|
360
|
+
signalType: "action_item",
|
|
361
|
+
vault,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
expect(res.entries.map((e) => e.signalId)).toEqual(["foo"]);
|
|
365
|
+
expect(res.entries[0].key).toBe("signals/action_item/foo.md");
|
|
366
|
+
expect(res.nextToken).toBeUndefined();
|
|
367
|
+
expect(listCalls[0].prefix).toBe("signals/action_item/");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("surfaces the opaque vault cursor as nextToken", async () => {
|
|
371
|
+
const { vault } = makePresignVault({
|
|
372
|
+
objects: [listed("signals/action_item/foo.md")],
|
|
373
|
+
cursor: "OPAQUE_CURSOR",
|
|
374
|
+
});
|
|
375
|
+
const res = await listSignals({
|
|
376
|
+
entity: ENTITY,
|
|
377
|
+
signalType: "action_item",
|
|
378
|
+
vault,
|
|
379
|
+
});
|
|
380
|
+
expect(res.nextToken).toBe("OPAQUE_CURSOR");
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("includeFrontmatter surfaces sourceRef via a presigned GET", async () => {
|
|
384
|
+
const { vault } = makePresignVault(
|
|
385
|
+
{ objects: [listed("signals/action_item/foo.md")], cursor: null },
|
|
386
|
+
{ "signals/action_item/foo.md": ACTION_ITEM_MD },
|
|
387
|
+
);
|
|
388
|
+
const res = await listSignals({
|
|
389
|
+
entity: ENTITY,
|
|
390
|
+
signalType: "action_item",
|
|
391
|
+
includeFrontmatter: true,
|
|
392
|
+
vault,
|
|
393
|
+
});
|
|
394
|
+
expect(res.entries[0].sourceRef).toBe("abc-meeting-001");
|
|
395
|
+
});
|
|
396
|
+
});
|
package/src/signals/list.ts
CHANGED
|
@@ -6,12 +6,8 @@
|
|
|
6
6
|
* `includeFrontmatter: true` (otherwise the field is undefined).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
GetObjectCommand,
|
|
11
|
-
ListObjectsV2Command,
|
|
12
|
-
} from "@aws-sdk/client-s3";
|
|
13
9
|
import { assertSignalType } from "../schemas/signal-types.js";
|
|
14
|
-
import {
|
|
10
|
+
import { listObjects, readObjectText } from "./internals.js";
|
|
15
11
|
import { parseFrontmatter } from "./parse.js";
|
|
16
12
|
import type {
|
|
17
13
|
ListSignalsOptions,
|
|
@@ -31,44 +27,35 @@ function deriveSignalId(key: string, prefix: string): string | null {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
export async function listSignals(opts: ListSignalsOptions): Promise<ListSignalsResult> {
|
|
34
|
-
// Validate signalType BEFORE any
|
|
30
|
+
// Validate signalType BEFORE any read (acceptance criterion + agent-mitigation).
|
|
35
31
|
assertSignalType(opts.signalType);
|
|
36
32
|
|
|
37
|
-
const client = getS3Client(opts.entity);
|
|
38
33
|
const prefix = `signals/${opts.signalType}/`;
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
35
|
+
// Presign transport ACL-filters server-side and controls page size, so
|
|
36
|
+
// `limit` is advisory there; under direct S3 it maps to MaxKeys. Paginate via
|
|
37
|
+
// the returned nextToken regardless of transport.
|
|
38
|
+
const page = await listObjects(opts, prefix, {
|
|
39
|
+
limit: opts.limit,
|
|
40
|
+
continuationToken: opts.continuationToken,
|
|
41
|
+
});
|
|
48
42
|
|
|
49
43
|
const entries: SignalSummary[] = [];
|
|
50
|
-
for (const obj of
|
|
51
|
-
|
|
52
|
-
const signalId = deriveSignalId(obj.Key, prefix);
|
|
44
|
+
for (const obj of page.contents) {
|
|
45
|
+
const signalId = deriveSignalId(obj.key, prefix);
|
|
53
46
|
if (!signalId) continue;
|
|
54
47
|
|
|
55
48
|
const summary: SignalSummary = {
|
|
56
49
|
signalId,
|
|
57
50
|
signalType: opts.signalType,
|
|
58
|
-
key: obj.
|
|
59
|
-
lastModified: obj.
|
|
60
|
-
size: obj.
|
|
51
|
+
key: obj.key,
|
|
52
|
+
lastModified: obj.lastModified,
|
|
53
|
+
size: obj.size,
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
if (opts.includeFrontmatter) {
|
|
64
57
|
try {
|
|
65
|
-
const
|
|
66
|
-
new GetObjectCommand({
|
|
67
|
-
Bucket: opts.entity.bucketName,
|
|
68
|
-
Key: obj.Key,
|
|
69
|
-
}),
|
|
70
|
-
);
|
|
71
|
-
const text = await streamToString(get.Body);
|
|
58
|
+
const text = await readObjectText(opts, obj.key);
|
|
72
59
|
const fm = parseFrontmatter(text);
|
|
73
60
|
if (fm) {
|
|
74
61
|
summary.frontmatter = fm;
|
|
@@ -87,6 +74,6 @@ export async function listSignals(opts: ListSignalsOptions): Promise<ListSignals
|
|
|
87
74
|
|
|
88
75
|
return {
|
|
89
76
|
entries,
|
|
90
|
-
nextToken:
|
|
77
|
+
nextToken: page.nextToken,
|
|
91
78
|
};
|
|
92
79
|
}
|
package/src/signals/types.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { SignalType } from "../schemas/signal-types.js";
|
|
11
11
|
import type { EntityContext } from "../types.js";
|
|
12
|
+
import type { PresignTransportClient } from "../object-io.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Lightweight summary returned by listSignals(). `frontmatter` and
|
|
@@ -53,12 +54,23 @@ export interface SignalDocument {
|
|
|
53
54
|
export interface ListSignalsOptions {
|
|
54
55
|
entity: EntityContext;
|
|
55
56
|
signalType: SignalType;
|
|
56
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Max keys per page. Under direct S3 this maps to `MaxKeys`; under the
|
|
59
|
+
* presigned transport ({@link vault} + a company vault) it is advisory — the
|
|
60
|
+
* vault `list` endpoint controls page size server-side. Defaults to the S3
|
|
61
|
+
* default (1000) on the direct path.
|
|
62
|
+
*/
|
|
57
63
|
limit?: number;
|
|
58
64
|
/** Opaque continuation token returned by a prior page. */
|
|
59
65
|
continuationToken?: string;
|
|
60
66
|
/** When true, fetches+parses each entry's frontmatter (extra GETs). */
|
|
61
67
|
includeFrontmatter?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Presign-capable vault client. When supplied and {@link entity} is a company
|
|
70
|
+
* vault (cmp_*), reads use the presigned-URL transport (ACL-filtered, no
|
|
71
|
+
* direct S3). Personal vaults and the absent-client path stay on direct S3.
|
|
72
|
+
*/
|
|
73
|
+
vault?: PresignTransportClient;
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
export interface ListSignalsResult {
|
|
@@ -71,4 +83,9 @@ export interface GetSignalOptions {
|
|
|
71
83
|
entity: EntityContext;
|
|
72
84
|
signalType: SignalType;
|
|
73
85
|
signalId: string;
|
|
86
|
+
/**
|
|
87
|
+
* Presign-capable vault client. When supplied and {@link entity} is a company
|
|
88
|
+
* vault (cmp_*), reads use the presigned-URL transport (no direct S3).
|
|
89
|
+
*/
|
|
90
|
+
vault?: PresignTransportClient;
|
|
74
91
|
}
|