@indigoai-us/hq-cloud 5.46.0 → 5.47.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.
Files changed (49) hide show
  1. package/dist/bin/sync-runner.d.ts +12 -0
  2. package/dist/bin/sync-runner.d.ts.map +1 -1
  3. package/dist/bin/sync-runner.js +39 -0
  4. package/dist/bin/sync-runner.js.map +1 -1
  5. package/dist/bin/sync-runner.test.js +27 -1
  6. package/dist/bin/sync-runner.test.js.map +1 -1
  7. package/dist/cli/share.d.ts.map +1 -1
  8. package/dist/cli/share.js +17 -2
  9. package/dist/cli/share.js.map +1 -1
  10. package/dist/cli/share.test.js +2 -0
  11. package/dist/cli/share.test.js.map +1 -1
  12. package/dist/cli/sync-scope.test.js +1 -0
  13. package/dist/cli/sync-scope.test.js.map +1 -1
  14. package/dist/cli/sync.d.ts.map +1 -1
  15. package/dist/cli/sync.js +11 -1
  16. package/dist/cli/sync.js.map +1 -1
  17. package/dist/cli/sync.test.js +1 -0
  18. package/dist/cli/sync.test.js.map +1 -1
  19. package/dist/object-io.d.ts +218 -0
  20. package/dist/object-io.d.ts.map +1 -0
  21. package/dist/object-io.js +588 -0
  22. package/dist/object-io.js.map +1 -0
  23. package/dist/object-io.test.d.ts +11 -0
  24. package/dist/object-io.test.d.ts.map +1 -0
  25. package/dist/object-io.test.js +568 -0
  26. package/dist/object-io.test.js.map +1 -0
  27. package/dist/s3.d.ts +37 -0
  28. package/dist/s3.d.ts.map +1 -1
  29. package/dist/s3.js +207 -198
  30. package/dist/s3.js.map +1 -1
  31. package/dist/vault-client.d.ts +68 -0
  32. package/dist/vault-client.d.ts.map +1 -1
  33. package/dist/vault-client.js +35 -0
  34. package/dist/vault-client.js.map +1 -1
  35. package/package.json +1 -1
  36. package/scripts/presign-transport-e2e.mjs +203 -0
  37. package/scripts/vault-rebaseline.sh +275 -0
  38. package/scripts/vault-rescue.sh +8 -0
  39. package/src/bin/sync-runner.test.ts +41 -0
  40. package/src/bin/sync-runner.ts +52 -0
  41. package/src/cli/share.test.ts +2 -0
  42. package/src/cli/share.ts +29 -2
  43. package/src/cli/sync-scope.test.ts +1 -0
  44. package/src/cli/sync.test.ts +1 -0
  45. package/src/cli/sync.ts +22 -1
  46. package/src/object-io.test.ts +663 -0
  47. package/src/object-io.ts +782 -0
  48. package/src/s3.ts +259 -233
  49. package/src/vault-client.ts +101 -0
@@ -0,0 +1,218 @@
1
+ /**
2
+ * ObjectIO — transport seam for vault object byte/metadata movement.
3
+ *
4
+ * s3.ts holds the *semantics* of sync (symlink-record encoding, mode/mtime
5
+ * stamping, created-at preservation, directory-marker filtering). Those never
6
+ * change. What CAN change is the *wire transport* underneath them:
7
+ *
8
+ * - `S3SdkObjectIO` — the historical path. STS-vended credentials + the AWS
9
+ * S3 SDK talking directly to the per-company bucket. No policy-size
10
+ * ceiling concern for the BYTES, but the STS session policy that grants
11
+ * access has the 2048-char IAM limit that motivated the presigned model.
12
+ *
13
+ * - `PresignObjectIO` — the presigned-URL path. The vault-service decides
14
+ * access as a runtime DDB check (no IAM policy ceiling) and hands back
15
+ * short-lived presigned GET/PUT/DELETE URLs + (for PUT) the exact headers
16
+ * to replay. The client never holds AWS credentials — it just `fetch`es
17
+ * the signed URLs.
18
+ *
19
+ * The seam is a per-EntityContext factory resolved INSIDE s3.ts, so every
20
+ * existing call site (`uploadFile(ctx, …)`, `downloadFile(ctx, …)`, …) keeps
21
+ * its signature. `runRunner` selects the transport once per session via
22
+ * {@link setObjectIOFactory}; absent any selection the default is the S3 SDK,
23
+ * preserving today's behavior for every non-gated caller.
24
+ */
25
+ import type { EntityContext } from "./types.js";
26
+ import type { PresignOp, PresignKeyInput, PresignResultRow, VaultListedObject } from "./vault-client.js";
27
+ /**
28
+ * The slice of {@link VaultClient} the presigned transport needs. Narrowed to
29
+ * just `presign` + `listFiles` so the factory accepts any caller that exposes
30
+ * those two (the real VaultClient, or a stub in tests) without depending on
31
+ * the full 20-method surface.
32
+ */
33
+ export interface PresignTransportClient {
34
+ presign(input: {
35
+ companyUid: string;
36
+ op?: PresignOp;
37
+ expiresIn?: number;
38
+ keys: PresignKeyInput[];
39
+ }): Promise<{
40
+ results: PresignResultRow[];
41
+ expiresAt: string;
42
+ }>;
43
+ listFiles(companyUid: string, prefix?: string, cursor?: string): Promise<{
44
+ objects: VaultListedObject[];
45
+ cursor: string | null;
46
+ truncated: boolean;
47
+ }>;
48
+ }
49
+ export interface PutObjectInput {
50
+ key: string;
51
+ body: Buffer;
52
+ contentType: string;
53
+ /** S3 user metadata (x-amz-meta-*). Lowercased keys by convention. */
54
+ metadata?: Record<string, string>;
55
+ }
56
+ export interface GetObjectResult {
57
+ body: Buffer;
58
+ /** S3 user metadata (keys lowercased by S3). */
59
+ metadata?: Record<string, string>;
60
+ }
61
+ export interface ListObjectsInput {
62
+ prefix?: string;
63
+ continuationToken?: string;
64
+ }
65
+ export interface ListedRemoteObject {
66
+ key: string;
67
+ size: number;
68
+ lastModified: Date;
69
+ etag: string;
70
+ }
71
+ export interface ListObjectsResult {
72
+ objects: ListedRemoteObject[];
73
+ /** Opaque cursor for the next page; undefined when the listing is exhausted. */
74
+ nextContinuationToken?: string;
75
+ }
76
+ export interface HeadObjectResult {
77
+ lastModified: Date;
78
+ etag: string;
79
+ size: number;
80
+ metadata?: Record<string, string>;
81
+ }
82
+ /**
83
+ * The minimal byte/metadata transport s3.ts needs. Deliberately narrow — no
84
+ * symlink, mode, or created-at concepts leak in here; those live one layer up
85
+ * in s3.ts and compose on top of these five primitives.
86
+ */
87
+ export interface ObjectIO {
88
+ putObject(input: PutObjectInput): Promise<{
89
+ etag: string;
90
+ }>;
91
+ getObject(key: string): Promise<GetObjectResult>;
92
+ listObjects(input: ListObjectsInput): Promise<ListObjectsResult>;
93
+ deleteObject(key: string): Promise<void>;
94
+ /** Null when the key does not exist (404 / 403-as-absent). */
95
+ headObject(key: string): Promise<HeadObjectResult | null>;
96
+ /**
97
+ * Optional batch pre-mint. Warms an internal URL cache for `keys` under `op`
98
+ * so subsequent per-key get/head (and, when primed, put/delete) calls reuse a
99
+ * pre-signed URL instead of issuing one presign request each. This is what
100
+ * turns an N-file sync from N presign calls into ceil(N/chunk) — the
101
+ * difference between staying under and blowing past the 100-req/hr limit on a
102
+ * bulk pull. The S3 SDK transport has no presign step and omits this (the
103
+ * per-call cost there is the SDK request itself, not a separate presign).
104
+ * Best-effort: a failed chunk or per-key denial simply leaves those keys
105
+ * uncached, and the per-key call falls back to a single presign.
106
+ */
107
+ prime?(op: PresignOp, keys: PresignKeyInput[]): Promise<void>;
108
+ /**
109
+ * True if a live primed PUT URL exists for `key`. Lets uploadFile/uploadSymlink
110
+ * skip recomputing metadata + the created-at HEAD when a `prime("put", …)`
111
+ * pre-pass already signed the metadata into the cached URL (the upload just
112
+ * sends the body, replaying the cached headers). Absent (undefined) on the S3
113
+ * SDK transport → callers take their normal compute-metadata path.
114
+ */
115
+ hasPrimedPut?(key: string): boolean;
116
+ }
117
+ /**
118
+ * Direct-to-S3 transport over STS-vended credentials. A fresh client per
119
+ * instance so the latest credentials from the EntityContext are always used
120
+ * (caching/refresh is the caller's concern, at the EntityContext level — see
121
+ * the original buildClient note in s3.ts).
122
+ */
123
+ export declare class S3SdkObjectIO implements ObjectIO {
124
+ private readonly client;
125
+ private readonly bucket;
126
+ constructor(ctx: EntityContext);
127
+ putObject(input: PutObjectInput): Promise<{
128
+ etag: string;
129
+ }>;
130
+ getObject(key: string): Promise<GetObjectResult>;
131
+ listObjects(input: ListObjectsInput): Promise<ListObjectsResult>;
132
+ deleteObject(key: string): Promise<void>;
133
+ headObject(key: string): Promise<HeadObjectResult | null>;
134
+ }
135
+ /**
136
+ * Thrown when a presign mint is skipped because the per-user 100/hr vault rate
137
+ * budget is exhausted. Distinct name so callers can tell "deferred, retry next
138
+ * sync" apart from a real transfer failure. The key was NOT synced.
139
+ */
140
+ export declare class RateLimitedError extends Error {
141
+ readonly key: string;
142
+ readonly op: PresignOp;
143
+ constructor(key: string, op: PresignOp, options?: {
144
+ cause?: unknown;
145
+ });
146
+ }
147
+ /**
148
+ * One-way circuit breaker shared across a run's per-company transports. The
149
+ * first 429 (vault rate budget exhausted) trips it; thereafter every UNCACHED
150
+ * presign fails fast with {@link RateLimitedError} instead of hitting the wire.
151
+ *
152
+ * Without this, an exhausted budget spirals: prime chunks 429 → keys uncached
153
+ * → per-file presign → each 429s (after VaultClient's own 3 retries +
154
+ * backoff) → an 86-minute storm of ~10k doomed calls (observed live). Tripping
155
+ * once and short-circuiting turns that into a clean fast finish: primed URLs
156
+ * still work, un-primed keys are deferred, and the run reports them so the next
157
+ * sync (after the rolling hour recovers) picks them up.
158
+ */
159
+ export declare class RateLimitBreaker {
160
+ private tripped;
161
+ isTripped(): boolean;
162
+ trip(): void;
163
+ }
164
+ /**
165
+ * Transport that moves bytes over short-lived presigned URLs minted by the
166
+ * vault-service. Holds no AWS credentials. `companyUid` is the EntityContext's
167
+ * `uid` — the server resolves the per-company bucket from it, so cross-company
168
+ * reach is structurally impossible (same authority model as the list/presign
169
+ * handlers).
170
+ *
171
+ * URL cache: {@link prime} batch-mints URLs into `urlCache` (keyed by op+key)
172
+ * so the per-file get/head calls during a sync reuse them instead of issuing a
173
+ * presign request each. A single instance is shared across all s3.ts calls for
174
+ * one company within a run (see {@link presignObjectIOFactory} memoization), so
175
+ * a prime before the transfer loop warms the cache the loop then drains.
176
+ */
177
+ export declare class PresignObjectIO implements ObjectIO {
178
+ private readonly vault;
179
+ private readonly companyUid;
180
+ private readonly breaker;
181
+ private readonly urlCache;
182
+ constructor(vault: PresignTransportClient, companyUid: string, breaker?: RateLimitBreaker);
183
+ private cacheKey;
184
+ hasPrimedPut(key: string): boolean;
185
+ /** A live (non-expiring) cached URL for op+key, or undefined. */
186
+ private cached;
187
+ /**
188
+ * Resolve a presigned URL (+ replay headers) for op+key: cache hit if primed,
189
+ * else a single presign. Throws on per-key denial (matches the SDK path's
190
+ * access error). `extra` carries PUT contentType/metadata on the miss path.
191
+ */
192
+ private resolveUrl;
193
+ prime(op: PresignOp, keys: PresignKeyInput[]): Promise<void>;
194
+ putObject(input: PutObjectInput): Promise<{
195
+ etag: string;
196
+ }>;
197
+ getObject(key: string): Promise<GetObjectResult>;
198
+ listObjects(input: ListObjectsInput): Promise<ListObjectsResult>;
199
+ deleteObject(key: string): Promise<void>;
200
+ headObject(key: string): Promise<HeadObjectResult | null>;
201
+ }
202
+ export type ObjectIOFactory = (ctx: EntityContext) => ObjectIO;
203
+ /**
204
+ * Install the transport factory for the current process. Passing `null`
205
+ * resets to the default S3 SDK transport. Called once by `runRunner` after it
206
+ * resolves the caller's identity + feature-flag gate; every subsequent s3.ts
207
+ * call resolves its transport through this.
208
+ */
209
+ export declare function setObjectIOFactory(factory: ObjectIOFactory | null): void;
210
+ /** Resolve the transport for an EntityContext using the active factory. */
211
+ export declare function resolveObjectIO(ctx: EntityContext): ObjectIO;
212
+ /**
213
+ * Build a factory that routes every EntityContext through the presigned-URL
214
+ * transport, reusing the one already-authenticated VaultClient and deriving
215
+ * the per-company authority from `ctx.uid`.
216
+ */
217
+ export declare function presignObjectIOFactory(vault: PresignTransportClient): ObjectIOFactory;
218
+ //# sourceMappingURL=object-io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-io.d.ts","sourceRoot":"","sources":["../src/object-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAUH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAG3B;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,KAAK,EAAE;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,EAAE,CAAC,EAAE,SAAS,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,eAAe,EAA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