@aglyn/tenant-data-admin 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/lib/server/erase.js +9 -0
- package/src/lib/server/erase.js.map +1 -1
- package/src/lib/server/placement-access.d.ts +38 -0
- package/src/lib/server/placement-access.js +51 -0
- package/src/lib/server/placement-access.js.map +1 -0
- package/src/lib/server/scope-sharing-sweep.d.ts +114 -0
- package/src/lib/server/scope-sharing-sweep.js +380 -0
- package/src/lib/server/scope-sharing-sweep.js.map +1 -0
- package/src/lib/server/serve-media-cdn.js +6 -5
- package/src/lib/server/serve-media-cdn.js.map +1 -1
- package/src/lib/server/transfer-host.js +16 -0
- package/src/lib/server/transfer-host.js.map +1 -1
- package/src/lib/server/visitor-upload.d.ts +28 -0
- package/src/lib/server/visitor-upload.js +81 -9
- package/src/lib/server/visitor-upload.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/scope-sharing-sweep.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 * KEEPING \"ALL SITES EXCEPT…\" TRUE AS SITES COME AND GO (AGL-4047).\n *\n * A document shared this way names its included sites in `visibleTo`, the one\n * field readers enforce. A new site therefore has to be added to it, and a\n * site that left has to come off it. {@link sweepScopeSharingAfterSiteChange}\n * does that after every change to `orgs/{orgId}.hosts`: a site created, moved\n * in or out, or erased.\n *\n * ## What it costs when nothing is marked\n *\n * One query per declared collection, each answering nothing, and not one\n * write. Every workspace pays that on a site change and nothing more, which\n * is why a sweep document is only written once a marked document turns up.\n *\n * ## Each document in its own transaction, reading the org document\n *\n * The transaction reads `orgs/{orgId}` as well as the document, so what it\n * writes is computed from the sites that are true at commit. A site claimed\n * while the sweep runs either serializes before it (and the sweep sees the\n * site) or after it (and the sweep that claim starts sees the document).\n *\n * ## Inline for a few seconds, then the job\n *\n * The caller is a person creating or deleting a site, so a trigger works for\n * {@link INLINE_BUDGET_MS} and leaves the rest to the job, from a cursor in\n * `orgs/{orgId}/scopeSweeps/{sweepId}`. That document exists only while work\n * is left, so the job's query answers nothing on a quiet beat. No rule opens\n * the path: only this server code reads or writes it.\n *\n * Every step is idempotent. A second sweep, or a resumed one going over a\n * document again, reads `current` and writes nothing.\n */\n\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport {\n reconcileAllExcept,\n SCOPE_MODE_ALL_EXCEPT,\n type ScopeSharingFields,\n} from '@aglyn/aglyn/app-utils/scope-tokens'\nimport { runPluginDeclarationsRepair } from '@aglyn/aglyn/plugin-manager/plugin-declarations-repair'\nimport {\n listScopeSharingCollections,\n type ResolvedScopeSharingCollection,\n scopeSharingPatchFor,\n} from '@aglyn/aglyn/plugin-manager/plugin-scope-sharing'\nimport {\n type CollectionReference,\n type DocumentReference,\n FieldPath,\n FieldValue,\n type Firestore,\n type QueryDocumentSnapshot,\n type QuerySnapshot,\n} from 'firebase-admin/firestore'\nimport firebaseAdmin from './firebase-admin'\n\n/** Where a sweep with work left records its cursor. */\nexport const SCOPE_SWEEPS_COLLECTION = 'scopeSweeps'\n/** Marked documents read at a time in one collection. */\nconst PAGE_SIZE = 100\n/** Transactions running at once. */\nconst CONCURRENCY = 8\n/** How long a person's site change waits for the sweep. */\nexport const INLINE_BUDGET_MS = 3_000\n/** How long one job beat spends, across every sweep it takes. */\nexport const JOB_BUDGET_MS = 20_000\n/** Sweeps one beat reads. */\nconst SWEEPS_PER_BEAT = 10\n/** Beats a failing sweep gets. The weekly drift report still counts its documents. */\nexport const MAX_SWEEP_ATTEMPTS = 5\n\nexport type ScopeSweepReason = 'site-added' | 'site-removed' | 'drift-repair'\n\nexport interface ScopeSweepCounts {\n /** Marked documents read. */\n marked: number\n /** Written because they had fallen behind. */\n changed: number\n /** Past their collection's limit, and so no longer widening. */\n capped: number\n /** A marker the helper cannot act on: left alone, and reported. */\n invalid: number\n /** A transaction or patch that threw. */\n failed: number\n}\n\nexport interface ScopeSweepResult extends ScopeSweepCounts {\n /** Every declared collection was walked to its end. */\n complete: boolean\n /** Where to carry on from, when `complete` is false. */\n cursor: ScopeSweepCursor | null\n}\n\n/** A position in {@link listScopeSharingCollections}. */\nexport interface ScopeSweepCursor {\n collection: string\n afterId: string | null\n}\n\nconst emptyCounts = (): ScopeSweepCounts => ({\n marked: 0,\n changed: 0,\n capped: 0,\n invalid: 0,\n failed: 0,\n})\n\nconst platformFirestore = () => firebaseAdmin.app().firestore() as unknown as Firestore\n\n/** The sites `orgs/{orgId}.hosts` names. */\nexport function orgHostIdsFromDoc(org: Readonly<Record<string, unknown>> | undefined): string[] {\n const hosts = org?.['hosts']\n if (!hosts || typeof hosts !== 'object' || Array.isArray(hosts)) return []\n return Object.entries(hosts as Record<string, unknown>)\n .filter(([, on]) => Boolean(on))\n .map(([hostId]) => hostId)\n}\n\n/** The sites a document keeps whatever it excludes, per its declaration. */\nfunction keptHostIds(\n declared: ResolvedScopeSharingCollection,\n doc: Readonly<Record<string, unknown>>,\n): string[] {\n const kept: string[] = []\n for (const field of declared.keepSiteFields ?? []) {\n const value = doc[field]\n if (typeof value === 'string' && value) kept.push(value)\n if (Array.isArray(value)) {\n for (const id of value) if (typeof id === 'string' && id) kept.push(id)\n }\n }\n return kept\n}\n\n/** The marked documents of one collection, in the order a cursor can resume. */\nfunction markedPage(collectionRef: CollectionReference, afterId: string | null): Promise<QuerySnapshot> {\n const ordered = collectionRef\n .where('scopeMode', '==', SCOPE_MODE_ALL_EXCEPT)\n .orderBy(FieldPath.documentId())\n return (afterId ? ordered.startAfter(afterId) : ordered).limit(PAGE_SIZE).get()\n}\n\n/** Runs `work` over `items`, at most {@link CONCURRENCY} at a time. */\nasync function eachConcurrently<T>(\n items: readonly T[],\n work: (item: T) => Promise<void>,\n): Promise<void> {\n let next = 0\n await Promise.all(\n Array.from({ length: Math.min(CONCURRENCY, items.length) }, async () => {\n while (next < items.length) {\n const item = items[next]\n next += 1\n await work(item)\n }\n }),\n )\n}\n\n/** A write's data: a `null` marker field is deleted, never stored. */\nfunction fieldsToWrite(fields: ScopeSharingFields): Record<string, unknown> {\n return {\n visibleTo: fields.visibleTo,\n scopeMode: fields.scopeMode ?? FieldValue.delete(),\n scopeExcept: fields.scopeExcept ?? FieldValue.delete(),\n }\n}\n\n/** The document as it will read after the write, for a patch to work from. */\nfunction asStored(\n data: Readonly<Record<string, unknown>>,\n fields: ScopeSharingFields,\n): Record<string, unknown> {\n const next: Record<string, unknown> = { ...data, visibleTo: fields.visibleTo }\n if (fields.scopeMode) {\n next['scopeMode'] = fields.scopeMode\n next['scopeExcept'] = fields.scopeExcept\n } else {\n delete next['scopeMode']\n delete next['scopeExcept']\n }\n return next\n}\n\n/** Brings one marked document level, in its own transaction. */\nasync function reconcileDocument(\n db: Firestore,\n orgRef: DocumentReference,\n declared: ResolvedScopeSharingCollection,\n docRef: DocumentReference,\n counts: ScopeSweepCounts,\n): Promise<void> {\n const status = await db.runTransaction(async (tx) => {\n const [org, doc] = await tx.getAll(orgRef, docRef)\n // The workspace went while this ran, and the document with it.\n if (!org.exists || !doc.exists) return 'current'\n const data = doc.data() as Record<string, unknown>\n const answer = reconcileAllExcept(data, orgHostIdsFromDoc(org.data()), {\n maxIncluded: declared.maxIncluded ?? null,\n keepHostIds: keptHostIds(declared, data),\n })\n if (answer.fields) {\n const patch = declared.patch\n ? await requiredPatch(declared.name)(declared.name, asStored(data, answer.fields))\n : {}\n // Not an edit, so `updatedAt` stays: a list ordered by it must not\n // reshuffle because a site was added somewhere in the workspace.\n tx.update(docRef, { ...fieldsToWrite(answer.fields), ...patch })\n }\n return answer.status\n })\n if (status === 'changed') counts.changed += 1\n if (status === 'capped') counts.capped += 1\n if (status === 'invalid') counts.invalid += 1\n}\n\nfunction requiredPatch(collection: string) {\n const patch = scopeSharingPatchFor(collection)\n if (!patch) throw new Error(`no scope-sharing patch is registered for ${collection}`)\n return patch\n}\n\n/**\n * A declared patch is missing where the boot step has not run. Runs it once,\n * and only when a marked document needs one, so a sweep that finds nothing\n * never pays for it.\n */\nasync function ensurePatches(\n collections: readonly ResolvedScopeSharingCollection[],\n): Promise<void> {\n if (collections.every((row) => !row.patch || scopeSharingPatchFor(row.name))) return\n await runPluginDeclarationsRepair().catch((error: unknown) => {\n console.error('[scope-sweep] the declarations repair failed', error)\n })\n}\n\nexport interface RunScopeSharingSweepInput {\n orgId: string\n /** Stops starting new work past this; omit to walk to the end. */\n budgetMs?: number\n /** Resume from here. */\n from?: ScopeSweepCursor | null\n /**\n * Called the first time a marked document turns up, so a sweep that finds\n * nothing writes nothing. A trigger records its sweep document here.\n */\n onFirstMarked?: () => Promise<void>\n firestore?: Firestore\n}\n\n/**\n * Walks every declared collection's marked documents and brings each level.\n * Throws only on a failed query; one document failing is counted and the walk\n * goes on, and an incomplete walk answers where it stopped.\n */\nexport async function runScopeSharingSweep(\n input: RunScopeSharingSweepInput,\n): Promise<ScopeSweepResult> {\n const db = input.firestore ?? platformFirestore()\n const orgRef = db.collection('orgs').doc(input.orgId)\n const collections = listScopeSharingCollections()\n const startAt = input.from\n ? Math.max(0, collections.findIndex((row) => row.name === input.from?.collection))\n : 0\n const remaining = collections.slice(startAt)\n const deadline = input.budgetMs == null ? null : Date.now() + input.budgetMs\n const counts = emptyCounts()\n\n // Every collection's first page at once, so the common answer of nothing\n // costs one round of queries rather than one after another.\n const pages = new Map<string, QueryDocumentSnapshot[]>()\n const firstAfter = (name: string) =>\n input.from && input.from.collection === name ? input.from.afterId : null\n await eachConcurrently(remaining, async (declared) => {\n const snapshot = await markedPage(orgRef.collection(declared.name), firstAfter(declared.name))\n pages.set(declared.name, snapshot.docs)\n })\n if ([...pages.values()].every((docs) => !docs.length)) {\n return { ...counts, complete: true, cursor: null }\n }\n await input.onFirstMarked?.()\n await ensurePatches(remaining)\n\n for (const declared of remaining) {\n let docs = pages.get(declared.name) ?? []\n let afterId = firstAfter(declared.name)\n while (docs.length) {\n if (deadline != null && Date.now() >= deadline) {\n return { ...counts, complete: false, cursor: { collection: declared.name, afterId } }\n }\n counts.marked += docs.length\n await eachConcurrently(docs, async (doc) => {\n try {\n await reconcileDocument(db, orgRef, declared, doc.ref, counts)\n } catch (error) {\n counts.failed += 1\n console.error(`[scope-sweep] ${declared.name}/${doc.id} in ${input.orgId} was not brought level`, error)\n }\n })\n afterId = docs[docs.length - 1].id\n if (docs.length < PAGE_SIZE) break\n docs = (await markedPage(orgRef.collection(declared.name), afterId)).docs\n }\n }\n return { ...counts, complete: true, cursor: null }\n}\n\n/**\n * What a change to a workspace's sites runs, once the change has committed.\n *\n * NEVER THROWS, because the site change is done and is what the person asked\n * for. Work it could not finish is left in a sweep document for the job, and\n * if even that write fails the weekly drift report finds what is behind.\n */\nexport async function sweepScopeSharingAfterSiteChange(input: {\n orgId: string\n reason: ScopeSweepReason\n hostId?: string\n firestore?: Firestore\n}): Promise<void> {\n const { orgId, reason, hostId } = input\n let sweepRef: DocumentReference | null = null\n const leaveForTheJob = async (cursor: ScopeSweepCursor | null, attempts: number) => {\n const db = input.firestore ?? platformFirestore()\n sweepRef ??= db.collection('orgs').doc(orgId).collection(SCOPE_SWEEPS_COLLECTION).doc(createResourceUid())\n await sweepRef.set({\n reason,\n ...(hostId ? { hostId } : {}),\n cursor,\n attempts,\n createdAtMs: Date.now(),\n })\n }\n try {\n const result = await runScopeSharingSweep({\n orgId,\n budgetMs: INLINE_BUDGET_MS,\n ...(input.firestore ? { firestore: input.firestore } : {}),\n onFirstMarked: () => leaveForTheJob(null, 0),\n })\n if (!result.complete) {\n await leaveForTheJob(result.cursor, 0)\n return\n }\n if (result.failed) {\n await leaveForTheJob(null, 1)\n return\n }\n await sweepRef?.delete()\n } catch (error) {\n console.error(`[scope-sweep] the sweep of ${orgId} after ${reason} did not finish`, error)\n await leaveForTheJob(null, 1).catch((writeError: unknown) => {\n console.error(`[scope-sweep] could not leave ${orgId}'s sweep for the job`, writeError)\n })\n }\n}\n\n/**\n * Carries on every unfinished sweep: the job's handler. A sweep document exists\n * only while work is left, so the unfiltered query needs no index and answers\n * nothing on a quiet beat, for one read.\n */\nexport async function resumeScopeSweeps(\n options: { budgetMs?: number; firestore?: Firestore } = {},\n): Promise<{ resumed: number; finished: number; droppedAfterFailing: number }> {\n const db = options.firestore ?? platformFirestore()\n const pending = await db.collectionGroup(SCOPE_SWEEPS_COLLECTION).limit(SWEEPS_PER_BEAT).get()\n const tally = { resumed: 0, finished: 0, droppedAfterFailing: 0 }\n const deadline = Date.now() + (options.budgetMs ?? JOB_BUDGET_MS)\n for (const sweep of pending.docs) {\n const budgetMs = deadline - Date.now()\n if (budgetMs <= 0) break\n tally.resumed += 1\n const orgRef = sweep.ref.parent.parent\n const attempts = Number(sweep.get('attempts') ?? 0)\n try {\n const org = orgRef ? await orgRef.get() : null\n // The workspace was erased after this was left. Nothing to bring level.\n if (!org?.exists) {\n await sweep.ref.delete()\n tally.finished += 1\n continue\n }\n const result = await runScopeSharingSweep({\n orgId: org.id,\n budgetMs,\n from: (sweep.get('cursor') as ScopeSweepCursor | null | undefined) ?? null,\n firestore: db,\n })\n if (!result.complete) {\n await sweep.ref.update({ cursor: result.cursor })\n continue\n }\n if (!result.failed) {\n await sweep.ref.delete()\n tally.finished += 1\n continue\n }\n throw new Error(`${result.failed} document(s) failed`)\n } catch (error) {\n console.error(`[scope-sweep] ${sweep.ref.path} failed on attempt ${attempts + 1}`, error)\n if (attempts + 1 >= MAX_SWEEP_ATTEMPTS) {\n // Stops holding a place in the beat. What it left behind is what the\n // weekly drift report counts, and that report goes to staff.\n await sweep.ref.delete().catch(() => undefined)\n tally.droppedAfterFailing += 1\n } else {\n await sweep.ref.update({ attempts: attempts + 1, cursor: null }).catch(() => undefined)\n }\n }\n }\n return tally\n}\n\n/** What the weekly report asks of one workspace. Reads only. */\nexport interface ScopeSharingDrift {\n /** Marked documents read. */\n marked: number\n /** Should read differently from how they read: what a sweep would write. */\n stale: number\n /** Past their collection's limit. A known state, reported and not alarmed. */\n capped: number\n /** A marker that cannot be acted on. */\n invalid: number\n}\n\nexport function emptyScopeSharingDrift(): ScopeSharingDrift {\n return { marked: 0, stale: 0, capped: 0, invalid: 0 }\n}\n\n/**\n * How far one workspace's marked documents are from what a sweep would write,\n * with the same helper the sweep uses. One query per declared collection when\n * nothing is marked.\n */\nexport async function scopeSharingDriftForOrg(\n orgRef: DocumentReference,\n orgData: Readonly<Record<string, unknown>> | undefined,\n): Promise<ScopeSharingDrift> {\n const drift = emptyScopeSharingDrift()\n const hostIds = orgHostIdsFromDoc(orgData)\n await eachConcurrently(listScopeSharingCollections(), async (declared) => {\n let afterId: string | null = null\n for (;;) {\n const page: QuerySnapshot = await markedPage(orgRef.collection(declared.name), afterId)\n for (const doc of page.docs) {\n const data = doc.data() as Record<string, unknown>\n const answer = reconcileAllExcept(data, hostIds, {\n maxIncluded: declared.maxIncluded ?? null,\n keepHostIds: keptHostIds(declared, data),\n })\n drift.marked += 1\n if (answer.status === 'invalid') drift.invalid += 1\n if (answer.status === 'capped') drift.capped += 1\n if (answer.fields) drift.stale += 1\n }\n if (page.docs.length < PAGE_SIZE) return\n afterId = page.docs[page.docs.length - 1].id\n }\n })\n return drift\n}\n"],"names":["createResourceUid","reconcileAllExcept","SCOPE_MODE_ALL_EXCEPT","runPluginDeclarationsRepair","listScopeSharingCollections","scopeSharingPatchFor","FieldPath","FieldValue","firebaseAdmin","SCOPE_SWEEPS_COLLECTION","PAGE_SIZE","CONCURRENCY","INLINE_BUDGET_MS","JOB_BUDGET_MS","SWEEPS_PER_BEAT","MAX_SWEEP_ATTEMPTS","emptyCounts","marked","changed","capped","invalid","failed","platformFirestore","app","firestore","orgHostIdsFromDoc","org","hosts","Array","isArray","Object","entries","filter","on","Boolean","map","hostId","keptHostIds","declared","doc","kept","field","keepSiteFields","value","push","id","markedPage","collectionRef","afterId","ordered","where","orderBy","documentId","startAfter","limit","get","eachConcurrently","items","work","next","Promise","all","from","length","Math","min","item","fieldsToWrite","fields","visibleTo","scopeMode","delete","scopeExcept","asStored","data","reconcileDocument","db","orgRef","docRef","counts","status","runTransaction","tx","getAll","exists","answer","maxIncluded","keepHostIds","patch","requiredPatch","name","update","collection","Error","ensurePatches","collections","every","row","catch","error","console","runScopeSharingSweep","input","orgId","startAt","max","findIndex","remaining","slice","deadline","budgetMs","Date","now","pages","Map","firstAfter","snapshot","set","docs","values","complete","cursor","onFirstMarked","ref","sweepScopeSharingAfterSiteChange","reason","sweepRef","leaveForTheJob","attempts","createdAtMs","result","writeError","resumeScopeSweeps","options","pending","collectionGroup","tally","resumed","finished","droppedAfterFailing","sweep","parent","Number","path","undefined","emptyScopeSharingDrift","stale","scopeSharingDriftForOrg","orgData","drift","hostIds","page"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SACEC,kBAAkB,EAClBC,qBAAqB,QAEhB,sCAAqC;AAC5C,SAASC,2BAA2B,QAAQ,yDAAwD;AACpG,SACEC,2BAA2B,EAE3BC,oBAAoB,QACf,mDAAkD;AACzD,SAGEC,SAAS,EACTC,UAAU,QAIL,2BAA0B;AACjC,OAAOC,mBAAmB,sBAAkB;AAE5C,qDAAqD,GACrD,OAAO,MAAMC,0BAA0B,cAAa;AACpD,uDAAuD,GACvD,MAAMC,YAAY;AAClB,kCAAkC,GAClC,MAAMC,cAAc;AACpB,yDAAyD,GACzD,OAAO,MAAMC,mBAAmB,KAAK;AACr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AAG,EAAE,CAAClB,EAAE;QAC9C;IACF;IACA,OAAOwG;AACT"}
|
|
@@ -1007,10 +1007,11 @@ export function parseMediaCdnRange(header, size) {
|
|
|
1007
1007
|
});
|
|
1008
1008
|
return;
|
|
1009
1009
|
}
|
|
1010
|
-
// Scope check (AGL-1043). The bare `org:` form serves ORG-WIDE assets
|
|
1011
|
-
//
|
|
1012
|
-
// names the site using it,
|
|
1013
|
-
// warns which pages are
|
|
1010
|
+
// Scope check (AGL-1043). The bare `org:` form serves ORG-WIDE assets and
|
|
1011
|
+
// assets shared with all sites except some; an asset shared with chosen
|
|
1012
|
+
// sites must be requested through the form that names the site using it,
|
|
1013
|
+
// which is when AGL-1045's confirmation already warns which pages are
|
|
1014
|
+
// affected.
|
|
1014
1015
|
//
|
|
1015
1016
|
// An asset carrying no `visibleTo` is refused here rather than treated as
|
|
1016
1017
|
// org-wide: absent is "nobody has said who may see this", not "everybody"
|
|
@@ -1022,7 +1023,7 @@ export function parseMediaCdnRange(header, size) {
|
|
|
1022
1023
|
// something the caller has no standing to learn. Short max-age so
|
|
1023
1024
|
// re-widening a scope propagates quickly instead of being pinned by a
|
|
1024
1025
|
// long-lived negative cache entry.
|
|
1025
|
-
const refusal = mediaCdnScopeRefusal(scope, snapshot.get('visibleTo'));
|
|
1026
|
+
const refusal = mediaCdnScopeRefusal(scope, snapshot.get('visibleTo'), snapshot.get('scopeMode'));
|
|
1026
1027
|
if (refusal) {
|
|
1027
1028
|
/**
|
|
1028
1029
|
* A `restricted` refusal is the gate WORKING and is deliberately
|