@aglyn/tenant-data-admin 1.0.0-beta.275 → 1.0.0-beta.282

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 (34) hide show
  1. package/package.json +7 -7
  2. package/src/lib/server/account-emails.js +18 -4
  3. package/src/lib/server/account-emails.js.map +1 -1
  4. package/src/lib/server/bundle-links.d.ts +5 -0
  5. package/src/lib/server/bundle-links.js +4 -2
  6. package/src/lib/server/bundle-links.js.map +1 -1
  7. package/src/lib/server/erase.js +9 -0
  8. package/src/lib/server/erase.js.map +1 -1
  9. package/src/lib/server/media-strong-digest.js +33 -5
  10. package/src/lib/server/media-strong-digest.js.map +1 -1
  11. package/src/lib/server/organizations.js +20 -0
  12. package/src/lib/server/organizations.js.map +1 -1
  13. package/src/lib/server/owner-handoff-emails.d.ts +43 -0
  14. package/src/lib/server/owner-handoff-emails.js +134 -0
  15. package/src/lib/server/owner-handoff-emails.js.map +1 -0
  16. package/src/lib/server/personal-data-export.js +18 -4
  17. package/src/lib/server/personal-data-export.js.map +1 -1
  18. package/src/lib/server/render-monitor.d.ts +8 -4
  19. package/src/lib/server/render-monitor.js +12 -8
  20. package/src/lib/server/render-monitor.js.map +1 -1
  21. package/src/lib/server/site-care-inbound.d.ts +75 -4
  22. package/src/lib/server/site-care-inbound.js +236 -26
  23. package/src/lib/server/site-care-inbound.js.map +1 -1
  24. package/src/lib/server/site-care-reconcile.d.ts +36 -2
  25. package/src/lib/server/site-care-reconcile.js +219 -54
  26. package/src/lib/server/site-care-reconcile.js.map +1 -1
  27. package/src/lib/server/site-care-requests.d.ts +43 -1
  28. package/src/lib/server/site-care-requests.js +117 -6
  29. package/src/lib/server/site-care-requests.js.map +1 -1
  30. package/src/lib/server/upgrade-proposal.d.ts +6 -1
  31. package/src/lib/server/upgrade-proposal.js.map +1 -1
  32. package/src/lib/server/upload-cors-reconcile.d.ts +2 -2
  33. package/src/lib/server/upload-cors-reconcile.js +2 -2
  34. package/src/lib/server/upload-cors-reconcile.js.map +1 -1
@@ -1,3 +1,4 @@
1
+ import { _ as _async_iterator } from "@swc/helpers/_/_async_iterator";
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2026 Aglyn LLC
@@ -157,11 +158,38 @@
157
158
  let peakChunkBytes = 0;
158
159
  try {
159
160
  const stream = file.createReadStream();
160
- for await (const chunk of stream){
161
- const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
162
- if (buffer.length > peakChunkBytes) peakChunkBytes = buffer.length;
163
- bytesRead += buffer.length;
164
- hash.update(new Uint8Array(buffer));
161
+ {
162
+ var _iteratorAbruptCompletion = false, _didIteratorError = false, _iteratorError, _return;
163
+ try {
164
+ var _iterator = _async_iterator(stream);
165
+ if (_iterator === null || typeof _iterator !== "object" && typeof _iterator !== "function") throw new TypeError("Iterator result is not an object");
166
+ for(var _next = _iterator.next, _step;; _iteratorAbruptCompletion = false){
167
+ _step = await Reflect.apply(_next, _iterator, []);
168
+ if (_step === null || typeof _step !== "object" && typeof _step !== "function") throw new TypeError("Iterator result is not an object");
169
+ _iteratorAbruptCompletion = !_step.done;
170
+ if (!_iteratorAbruptCompletion) break;
171
+ let _value = _step.value;
172
+ const chunk = _value;
173
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
174
+ if (buffer.length > peakChunkBytes) peakChunkBytes = buffer.length;
175
+ bytesRead += buffer.length;
176
+ hash.update(new Uint8Array(buffer));
177
+ }
178
+ } catch (err) {
179
+ _didIteratorError = true;
180
+ _iteratorError = err;
181
+ } finally{
182
+ try {
183
+ if (_iteratorAbruptCompletion && (_return = _iterator.return) != null) {
184
+ _step = await Reflect.apply(_return, _iterator, []);
185
+ if (_step === null || typeof _step !== "object" && typeof _step !== "function") throw new TypeError("Iterator result is not an object");
186
+ }
187
+ } finally{
188
+ if (_didIteratorError) {
189
+ throw _iteratorError;
190
+ }
191
+ }
192
+ }
165
193
  }
166
194
  } catch (error) {
167
195
  console.error('[media] strong digest read failed', error);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/media-strong-digest.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A BOUNDED strong content digest for objects the server never held\n * (AGL-1629) — the decision AGL-1614 deferred, taken now that AGL-1475\n * changed what it costs.\n *\n * ## What changed since the question was asked\n *\n * AGL-1614 wrote `contentSha256` only where the bytes were already in hand,\n * and argued — correctly, at the time — that the signed-upload route could\n * not have one: the browser PUTs straight to GCS, GCS computes md5 and\n * crc32c but never sha256, and `file.download()` on a 200 MB video is the\n * exact cost the route exists to avoid. The conclusion was \"needs a\n * product call on cost\".\n *\n * AGL-1475 (`c607678ee`) then made finalize read bytes anyway — a 4 KB head\n * and, for document archives, a 64 KB tail — to inspect structure. The\n * route is no longer byte-blind, and the honest question is no longer\n * \"download or not\" but \"how much\".\n *\n * ## The measurement the decision rests on\n *\n * Production media bucket, `gs://aglyn-main.appspot.com`, read-only listing\n * on 2026-08-20: **182 source objects, 44,774,216 bytes (42.70 MiB)** —\n * plus 269 derived `__wNNN.webp` variants, which carry no media document\n * and need no digest. Largest single object **7,742,225 B (7.38 MiB)**;\n * mean 246 KB; 177 of 182 under 1 MB; **nothing above 10 MiB and no video\n * at all**. Hashing the entire back catalogue is ~$0.005 of egress.\n *\n * So the \"200 MB video\" that made this expensive is a CEILING, not a\n * population. It still has to be handled — a ceiling is what an attacker\n * aims at — but it must not be allowed to price the other 99%.\n *\n * ## The decision\n *\n * Digest every signed upload up to {@link MEDIA_STRONG_DIGEST_MAX_BYTES},\n * by STREAMING; above it, write nothing and degrade exactly as before.\n *\n * **Why 50 MiB and not a rounder number.** It is precisely the largest\n * NON-VIDEO ceiling on the signed route: ZIP is 50 MB and `.pptx` is 50 MB,\n * PDF and the Office types are 25 MB, images are 15 MB. At 50 MiB every\n * type except video is covered *at its own maximum* — there is no size at\n * which a PDF or a brand-kit zip silently loses its strong digest. Only\n * video (200 MB) can exceed it, and only past 50 MB.\n *\n * **What the bound costs, precisely.** One additional full read of the\n * object, capped at 50 MiB. GCS internet egress is ~$0.12/GiB, so the\n * worst case is **$0.0057 per upload** and the measured mean case is\n * **$0.00003**. sha256 in Node runs at roughly 500 MB/s, so the CPU is\n * ~0.1 s at the ceiling. The route already declares `maxDuration = 60` and\n * already budgets a 15 MB download plus three `sharp` encodes inside it.\n *\n * **What the bound buys.**\n *\n * 1. **Cross-route matching, which was previously impossible.** The\n * in-process routes key on sha256 of the bytes; this route keyed on a\n * 16-hex truncation of GCS's md5. The same file through the two paths\n * produced two unrelated keys, so \"re-uploading the same bytes stays\n * quarantined\" held within an ingestion path and not across them. Under\n * the ceiling it now holds across them. That is the headline.\n * 2. **The md5 collision target goes away** for everything under the\n * ceiling. A chosen-prefix md5 collision is hours of ordinary compute\n * and yields two files sharing the 64-bit truncation — a cross-tenant\n * availability attack an outsider could mount. The preferred key stops\n * being md5-derived.\n * 3. **Ingestion refusal actually works** on the signed route for known\n * bytes, rather than only at delivery via the per-asset fallback.\n *\n * **What it does not buy, stated rather than implied.** Video above 50 MB\n * carries no `contentSha256` and never will on this path. That is the\n * bounded alternative, not a pretence of completeness: such an object\n * matches on the legacy truncated hash and on its per-asset key, exactly as\n * every signed upload did before this module existed. Video is also the\n * type least plausibly a chosen-prefix collision target or a\n * shared-bytes malware carrier, which is why it is the class the bound\n * sacrifices.\n *\n * ## Why streaming rather than `download()`\n *\n * `file.download()` resolves a single Buffer. At the ceiling that is 50 MiB\n * of function heap on a path that is concurrently holding a `sharp`\n * pipeline. Streaming through the hash keeps the resident set at one chunk\n * regardless of object size, which is what makes a 50 MiB bound safe to\n * state at all. The spec asserts the peak rather than only the hex, because\n * a hex-only assertion passes just as happily against a buffering\n * implementation.\n */\n\nimport { createHash } from 'node:crypto'\n\n/**\n * The largest object this path will digest.\n *\n * Deliberately equal to the largest non-video `signedMaxBytes` in\n * `apps/console/utils/media-upload-limits.ts` (ZIP, `.pptx`). Raising it\n * only ever adds video; lowering it silently strips the strong key off a\n * document type that has one today, which is why the spec asserts the\n * number instead of trusting it.\n */\nexport const MEDIA_STRONG_DIGEST_MAX_BYTES = 50 * 1024 * 1024\n\n/** Why no digest was taken. Absent when one was. */\nexport type StrongDigestSkip = 'over-ceiling' | 'unreadable'\n\nexport interface StoredObjectDigest {\n /** Lower-case hex sha256 of the whole object, or absent. */\n sha256?: string\n /** Set when — and only when — `sha256` is absent. */\n skipped?: StrongDigestSkip\n /** Bytes actually pulled out of the bucket. Zero when the bound bit. */\n bytesRead: number\n /**\n * The largest single buffer held while hashing.\n *\n * Exported because it is the only externally checkable evidence that this\n * function streams rather than buffers — a caller, a log line or a spec\n * can distinguish the two without reading the implementation. It is also\n * the number that would move first if someone \"simplified\" this back to\n * `file.download()`.\n */\n peakChunkBytes: number\n}\n\n/**\n * May an object of this size be digested?\n *\n * A pure predicate so the route and the spec (AGL-1630) apply ONE rule\n * rather than copies that drift.\n *\n * An unknown, zero or non-finite size answers `false`, never `true`. GCS\n * reports no size for a composite object, and guessing \"small\" there means\n * starting an unbounded read on the exact shape that cannot be bounded.\n */\nexport function strongDigestWithinCeiling(\n sizeBytes: number,\n maxBytes: number = MEDIA_STRONG_DIGEST_MAX_BYTES,\n): boolean {\n if (typeof sizeBytes !== 'number' || !Number.isFinite(sizeBytes)) return false\n if (sizeBytes <= 0) return false\n return sizeBytes <= maxBytes\n}\n\n/** The minimal Storage surface this needs; injectable for tests. */\nexport interface DigestibleStorageFile {\n createReadStream: (options?: unknown) => NodeJS.ReadableStream\n}\n\n/**\n * Stream one stored object through sha256.\n *\n * FAILS SOFT, in both directions, and that is the whole safety argument:\n *\n * * An unreadable object returns `unreadable`, not a throw. The callers are\n * an upload finalize and a backfill; a Storage blip must not start\n * refusing uploads, matching the fail-open posture of the ranged\n * inspection above it and the deny-list read below it.\n * * A stream that ends SHORT — a truncated range, a proxy cutting the body,\n * a mid-flight reset — returns `unreadable` rather than the digest of\n * what did arrive. A partial digest is worse than none: it is a\n * well-formed 64-hex value that matches nothing, and because\n * `mediaQuarantineKeys` PREFERS the strong digest, writing one would\n * shadow the legacy hash that would otherwise have matched. That is a\n * takedown quietly lifting itself, which is the one failure this whole\n * subsystem may not have.\n */\nexport async function storedObjectSha256(options: {\n file: DigestibleStorageFile\n /** The object's real size, as Storage reports it. */\n sizeBytes: number\n maxBytes?: number\n}): Promise<StoredObjectDigest> {\n const { file, sizeBytes } = options\n const maxBytes = options.maxBytes ?? MEDIA_STRONG_DIGEST_MAX_BYTES\n\n // Before any egress, not after — a bound that reads and discards costs\n // exactly what it exists to save.\n if (!strongDigestWithinCeiling(sizeBytes, maxBytes)) {\n return { skipped: 'over-ceiling', bytesRead: 0, peakChunkBytes: 0 }\n }\n\n const hash = createHash('sha256')\n let bytesRead = 0\n let peakChunkBytes = 0\n try {\n const stream = file.createReadStream()\n for await (const chunk of stream as AsyncIterable<Buffer | string>) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))\n if (buffer.length > peakChunkBytes) peakChunkBytes = buffer.length\n bytesRead += buffer.length\n hash.update(new Uint8Array(buffer))\n }\n } catch (error) {\n console.error('[media] strong digest read failed', error)\n return { skipped: 'unreadable', bytesRead, peakChunkBytes }\n }\n\n if (bytesRead !== sizeBytes) {\n // See the fail-soft note above: a short read is not a small file.\n console.error(\n '[media] strong digest read short',\n `expected ${sizeBytes} bytes, read ${bytesRead}`,\n )\n return { skipped: 'unreadable', bytesRead, peakChunkBytes }\n }\n\n return { sha256: hash.digest('hex'), bytesRead, peakChunkBytes }\n}\n"],"names":["createHash","MEDIA_STRONG_DIGEST_MAX_BYTES","strongDigestWithinCeiling","sizeBytes","maxBytes","Number","isFinite","storedObjectSha256","options","file","skipped","bytesRead","peakChunkBytes","hash","stream","createReadStream","chunk","buffer","Buffer","isBuffer","from","String","length","update","Uint8Array","error","console","sha256","digest"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqFC,GAED,SAASA,UAAU,QAAQ,cAAa;AAExC;;;;;;;;CAQC,GACD,OAAO,MAAMC,gCAAgC,KAAK,OAAO,KAAI;AAwB7D;;;;;;;;;CASC,GACD,OAAO,SAASC,0BACdC,SAAiB,EACjBC,WAAmBH,6BAA6B;IAEhD,IAAI,OAAOE,cAAc,YAAY,CAACE,OAAOC,QAAQ,CAACH,YAAY,OAAO;IACzE,IAAIA,aAAa,GAAG,OAAO;IAC3B,OAAOA,aAAaC;AACtB;AAOA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeG,mBAAmBC,OAKxC;QAEkBA;IADjB,MAAM,EAAEC,IAAI,EAAEN,SAAS,EAAE,GAAGK;IAC5B,MAAMJ,YAAWI,oBAAAA,QAAQJ,QAAQ,YAAhBI,oBAAoBP;IAErC,uEAAuE;IACvE,kCAAkC;IAClC,IAAI,CAACC,0BAA0BC,WAAWC,WAAW;QACnD,OAAO;YAAEM,SAAS;YAAgBC,WAAW;YAAGC,gBAAgB;QAAE;IACpE;IAEA,MAAMC,OAAOb,WAAW;IACxB,IAAIW,YAAY;IAChB,IAAIC,iBAAiB;IACrB,IAAI;QACF,MAAME,SAASL,KAAKM,gBAAgB;QACpC,WAAW,MAAMC,SAASF,OAA0C;YAClE,MAAMG,SAASC,OAAOC,QAAQ,CAACH,SAASA,QAAQE,OAAOE,IAAI,CAACC,OAAOL;YACnE,IAAIC,OAAOK,MAAM,GAAGV,gBAAgBA,iBAAiBK,OAAOK,MAAM;YAClEX,aAAaM,OAAOK,MAAM;YAC1BT,KAAKU,MAAM,CAAC,IAAIC,WAAWP;QAC7B;IACF,EAAE,OAAOQ,OAAO;QACdC,QAAQD,KAAK,CAAC,qCAAqCA;QACnD,OAAO;YAAEf,SAAS;YAAcC;YAAWC;QAAe;IAC5D;IAEA,IAAID,cAAcR,WAAW;QAC3B,kEAAkE;QAClEuB,QAAQD,KAAK,CACX,oCACA,CAAC,SAAS,EAAEtB,UAAU,aAAa,EAAEQ,WAAW;QAElD,OAAO;YAAED,SAAS;YAAcC;YAAWC;QAAe;IAC5D;IAEA,OAAO;QAAEe,QAAQd,KAAKe,MAAM,CAAC;QAAQjB;QAAWC;IAAe;AACjE"}
1
+ {"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/media-strong-digest.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A BOUNDED strong content digest for objects the server never held\n * (AGL-1629) — the decision AGL-1614 deferred, taken now that AGL-1475\n * changed what it costs.\n *\n * ## What changed since the question was asked\n *\n * AGL-1614 wrote `contentSha256` only where the bytes were already in hand,\n * and argued — correctly, at the time — that the signed-upload route could\n * not have one: the browser PUTs straight to GCS, GCS computes md5 and\n * crc32c but never sha256, and `file.download()` on a 200 MB video is the\n * exact cost the route exists to avoid. The conclusion was \"needs a\n * product call on cost\".\n *\n * AGL-1475 (`c607678ee`) then made finalize read bytes anyway — a 4 KB head\n * and, for document archives, a 64 KB tail — to inspect structure. The\n * route is no longer byte-blind, and the honest question is no longer\n * \"download or not\" but \"how much\".\n *\n * ## The measurement the decision rests on\n *\n * Production media bucket, `gs://aglyn-main.appspot.com`, read-only listing\n * on 2026-08-20: **182 source objects, 44,774,216 bytes (42.70 MiB)** —\n * plus 269 derived `__wNNN.webp` variants, which carry no media document\n * and need no digest. Largest single object **7,742,225 B (7.38 MiB)**;\n * mean 246 KB; 177 of 182 under 1 MB; **nothing above 10 MiB and no video\n * at all**. Hashing the entire back catalogue is ~$0.005 of egress.\n *\n * So the \"200 MB video\" that made this expensive is a CEILING, not a\n * population. It still has to be handled — a ceiling is what an attacker\n * aims at — but it must not be allowed to price the other 99%.\n *\n * ## The decision\n *\n * Digest every signed upload up to {@link MEDIA_STRONG_DIGEST_MAX_BYTES},\n * by STREAMING; above it, write nothing and degrade exactly as before.\n *\n * **Why 50 MiB and not a rounder number.** It is precisely the largest\n * NON-VIDEO ceiling on the signed route: ZIP is 50 MB and `.pptx` is 50 MB,\n * PDF and the Office types are 25 MB, images are 15 MB. At 50 MiB every\n * type except video is covered *at its own maximum* — there is no size at\n * which a PDF or a brand-kit zip silently loses its strong digest. Only\n * video (200 MB) can exceed it, and only past 50 MB.\n *\n * **What the bound costs, precisely.** One additional full read of the\n * object, capped at 50 MiB. GCS internet egress is ~$0.12/GiB, so the\n * worst case is **$0.0057 per upload** and the measured mean case is\n * **$0.00003**. sha256 in Node runs at roughly 500 MB/s, so the CPU is\n * ~0.1 s at the ceiling. The route already declares `maxDuration = 60` and\n * already budgets a 15 MB download plus three `sharp` encodes inside it.\n *\n * **What the bound buys.**\n *\n * 1. **Cross-route matching, which was previously impossible.** The\n * in-process routes key on sha256 of the bytes; this route keyed on a\n * 16-hex truncation of GCS's md5. The same file through the two paths\n * produced two unrelated keys, so \"re-uploading the same bytes stays\n * quarantined\" held within an ingestion path and not across them. Under\n * the ceiling it now holds across them. That is the headline.\n * 2. **The md5 collision target goes away** for everything under the\n * ceiling. A chosen-prefix md5 collision is hours of ordinary compute\n * and yields two files sharing the 64-bit truncation — a cross-tenant\n * availability attack an outsider could mount. The preferred key stops\n * being md5-derived.\n * 3. **Ingestion refusal actually works** on the signed route for known\n * bytes, rather than only at delivery via the per-asset fallback.\n *\n * **What it does not buy, stated rather than implied.** Video above 50 MB\n * carries no `contentSha256` and never will on this path. That is the\n * bounded alternative, not a pretence of completeness: such an object\n * matches on the legacy truncated hash and on its per-asset key, exactly as\n * every signed upload did before this module existed. Video is also the\n * type least plausibly a chosen-prefix collision target or a\n * shared-bytes malware carrier, which is why it is the class the bound\n * sacrifices.\n *\n * ## Why streaming rather than `download()`\n *\n * `file.download()` resolves a single Buffer. At the ceiling that is 50 MiB\n * of function heap on a path that is concurrently holding a `sharp`\n * pipeline. Streaming through the hash keeps the resident set at one chunk\n * regardless of object size, which is what makes a 50 MiB bound safe to\n * state at all. The spec asserts the peak rather than only the hex, because\n * a hex-only assertion passes just as happily against a buffering\n * implementation.\n */\n\nimport { createHash } from 'node:crypto'\n\n/**\n * The largest object this path will digest.\n *\n * Deliberately equal to the largest non-video `signedMaxBytes` in\n * `apps/console/utils/media-upload-limits.ts` (ZIP, `.pptx`). Raising it\n * only ever adds video; lowering it silently strips the strong key off a\n * document type that has one today, which is why the spec asserts the\n * number instead of trusting it.\n */\nexport const MEDIA_STRONG_DIGEST_MAX_BYTES = 50 * 1024 * 1024\n\n/** Why no digest was taken. Absent when one was. */\nexport type StrongDigestSkip = 'over-ceiling' | 'unreadable'\n\nexport interface StoredObjectDigest {\n /** Lower-case hex sha256 of the whole object, or absent. */\n sha256?: string\n /** Set when — and only when — `sha256` is absent. */\n skipped?: StrongDigestSkip\n /** Bytes actually pulled out of the bucket. Zero when the bound bit. */\n bytesRead: number\n /**\n * The largest single buffer held while hashing.\n *\n * Exported because it is the only externally checkable evidence that this\n * function streams rather than buffers — a caller, a log line or a spec\n * can distinguish the two without reading the implementation. It is also\n * the number that would move first if someone \"simplified\" this back to\n * `file.download()`.\n */\n peakChunkBytes: number\n}\n\n/**\n * May an object of this size be digested?\n *\n * A pure predicate so the route and the spec (AGL-1630) apply ONE rule\n * rather than copies that drift.\n *\n * An unknown, zero or non-finite size answers `false`, never `true`. GCS\n * reports no size for a composite object, and guessing \"small\" there means\n * starting an unbounded read on the exact shape that cannot be bounded.\n */\nexport function strongDigestWithinCeiling(\n sizeBytes: number,\n maxBytes: number = MEDIA_STRONG_DIGEST_MAX_BYTES,\n): boolean {\n if (typeof sizeBytes !== 'number' || !Number.isFinite(sizeBytes)) return false\n if (sizeBytes <= 0) return false\n return sizeBytes <= maxBytes\n}\n\n/** The minimal Storage surface this needs; injectable for tests. */\nexport interface DigestibleStorageFile {\n createReadStream: (options?: unknown) => NodeJS.ReadableStream\n}\n\n/**\n * Stream one stored object through sha256.\n *\n * FAILS SOFT, in both directions, and that is the whole safety argument:\n *\n * * An unreadable object returns `unreadable`, not a throw. The callers are\n * an upload finalize and a backfill; a Storage blip must not start\n * refusing uploads, matching the fail-open posture of the ranged\n * inspection above it and the deny-list read below it.\n * * A stream that ends SHORT — a truncated range, a proxy cutting the body,\n * a mid-flight reset — returns `unreadable` rather than the digest of\n * what did arrive. A partial digest is worse than none: it is a\n * well-formed 64-hex value that matches nothing, and because\n * `mediaQuarantineKeys` PREFERS the strong digest, writing one would\n * shadow the legacy hash that would otherwise have matched. That is a\n * takedown quietly lifting itself, which is the one failure this whole\n * subsystem may not have.\n */\nexport async function storedObjectSha256(options: {\n file: DigestibleStorageFile\n /** The object's real size, as Storage reports it. */\n sizeBytes: number\n maxBytes?: number\n}): Promise<StoredObjectDigest> {\n const { file, sizeBytes } = options\n const maxBytes = options.maxBytes ?? MEDIA_STRONG_DIGEST_MAX_BYTES\n\n // Before any egress, not after — a bound that reads and discards costs\n // exactly what it exists to save.\n if (!strongDigestWithinCeiling(sizeBytes, maxBytes)) {\n return { skipped: 'over-ceiling', bytesRead: 0, peakChunkBytes: 0 }\n }\n\n const hash = createHash('sha256')\n let bytesRead = 0\n let peakChunkBytes = 0\n try {\n const stream = file.createReadStream()\n for await (const chunk of stream as AsyncIterable<Buffer | string>) {\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))\n if (buffer.length > peakChunkBytes) peakChunkBytes = buffer.length\n bytesRead += buffer.length\n hash.update(new Uint8Array(buffer))\n }\n } catch (error) {\n console.error('[media] strong digest read failed', error)\n return { skipped: 'unreadable', bytesRead, peakChunkBytes }\n }\n\n if (bytesRead !== sizeBytes) {\n // See the fail-soft note above: a short read is not a small file.\n console.error(\n '[media] strong digest read short',\n `expected ${sizeBytes} bytes, read ${bytesRead}`,\n )\n return { skipped: 'unreadable', bytesRead, peakChunkBytes }\n }\n\n return { sha256: hash.digest('hex'), bytesRead, peakChunkBytes }\n}\n"],"names":["createHash","MEDIA_STRONG_DIGEST_MAX_BYTES","strongDigestWithinCeiling","sizeBytes","maxBytes","Number","isFinite","storedObjectSha256","options","file","skipped","bytesRead","peakChunkBytes","hash","stream","createReadStream","chunk","buffer","Buffer","isBuffer","from","String","length","update","Uint8Array","error","console","sha256","digest"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqFC,GAED,SAASA,UAAU,QAAQ,cAAa;AAExC;;;;;;;;CAQC,GACD,OAAO,MAAMC,gCAAgC,KAAK,OAAO,KAAI;AAwB7D;;;;;;;;;CASC,GACD,OAAO,SAASC,0BACdC,SAAiB,EACjBC,WAAmBH,6BAA6B;IAEhD,IAAI,OAAOE,cAAc,YAAY,CAACE,OAAOC,QAAQ,CAACH,YAAY,OAAO;IACzE,IAAIA,aAAa,GAAG,OAAO;IAC3B,OAAOA,aAAaC;AACtB;AAOA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeG,mBAAmBC,OAKxC;QAEkBA;IADjB,MAAM,EAAEC,IAAI,EAAEN,SAAS,EAAE,GAAGK;IAC5B,MAAMJ,YAAWI,oBAAAA,QAAQJ,QAAQ,YAAhBI,oBAAoBP;IAErC,uEAAuE;IACvE,kCAAkC;IAClC,IAAI,CAACC,0BAA0BC,WAAWC,WAAW;QACnD,OAAO;YAAEM,SAAS;YAAgBC,WAAW;YAAGC,gBAAgB;QAAE;IACpE;IAEA,MAAMC,OAAOb,WAAW;IACxB,IAAIW,YAAY;IAChB,IAAIC,iBAAiB;IACrB,IAAI;QACF,MAAME,SAASL,KAAKM,gBAAgB;QACpC;;YAAA,IAAoE;gDAA1CD;;gBAA1B,0EAAoE;;;;;;0BAAnDE;oBACf,MAAMC,SAASC,OAAOC,QAAQ,CAACH,SAASA,QAAQE,OAAOE,IAAI,CAACC,OAAOL;oBACnE,IAAIC,OAAOK,MAAM,GAAGV,gBAAgBA,iBAAiBK,OAAOK,MAAM;oBAClEX,aAAaM,OAAOK,MAAM;oBAC1BT,KAAKU,MAAM,CAAC,IAAIC,WAAWP;gBAC7B;YAAA;;;;;;;;;;;;;;;QAAA;IACF,EAAE,OAAOQ,OAAO;QACdC,QAAQD,KAAK,CAAC,qCAAqCA;QACnD,OAAO;YAAEf,SAAS;YAAcC;YAAWC;QAAe;IAC5D;IAEA,IAAID,cAAcR,WAAW;QAC3B,kEAAkE;QAClEuB,QAAQD,KAAK,CACX,oCACA,CAAC,SAAS,EAAEtB,UAAU,aAAa,EAAEQ,WAAW;QAElD,OAAO;YAAED,SAAS;YAAcC;YAAWC;QAAe;IAC5D;IAEA,OAAO;QAAEe,QAAQd,KAAKe,MAAM,CAAC;QAAQjB;QAAWC;IAAe;AACjE"}
@@ -2001,6 +2001,7 @@ const MEMBER_PROJECTION_WRITE = {
2001
2001
  const db = firestore();
2002
2002
  let move = null;
2003
2003
  let ownerEmail = null;
2004
+ let ownerName = null;
2004
2005
  await db.runTransaction(async (tx)=>{
2005
2006
  var _invite_email, _org_name, _org_slug;
2006
2007
  const orgRef = db.collection('orgs').doc(orgId);
@@ -2028,6 +2029,7 @@ const MEMBER_PROJECTION_WRITE = {
2028
2029
  const invitee = inviteeSnapshot.data();
2029
2030
  const owner = ownerSnapshot.data();
2030
2031
  ownerEmail = typeof (owner == null ? void 0 : owner.email) === 'string' ? owner.email : null;
2032
+ ownerName = typeof (owner == null ? void 0 : owner.displayName) === 'string' ? owner.displayName : null;
2031
2033
  await assertOwnerHandoffSeat({
2032
2034
  orgRef,
2033
2035
  org,
@@ -2087,6 +2089,24 @@ const MEMBER_PROJECTION_WRITE = {
2087
2089
  id: uid,
2088
2090
  name: email
2089
2091
  });
2092
+ // Both sides hear it from the platform (AGL-4023), by email, whichever
2093
+ // way the handoff completed. Loaded here rather than at the top: the
2094
+ // email renderer's consent module imports this file, and a static import
2095
+ // closed that cycle, so a module reading these exports mid-load saw them
2096
+ // uninitialized.
2097
+ const { sendOwnerHandoffEmails } = await import("./owner-handoff-emails.js");
2098
+ await sendOwnerHandoffEmails({
2099
+ orgId,
2100
+ newOwner: {
2101
+ email,
2102
+ displayName: displayName != null ? displayName : null
2103
+ },
2104
+ previousOwner: {
2105
+ email: ownerEmail,
2106
+ displayName: ownerName
2107
+ },
2108
+ previousOwnerStays: settled.previousOwner === 'stay'
2109
+ });
2090
2110
  return {
2091
2111
  previousOwnerUid: settled.fromUid,
2092
2112
  previousOwner: settled.previousOwner