@memberjunction/core-entities 6.2.2 → 6.3.0-edge.1
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/.tsbuildinfo +1 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts +10 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts.map +1 -1
- package/dist/custom/AnchoredConversationSecurity.js +15 -0
- package/dist/custom/AnchoredConversationSecurity.js.map +1 -1
- package/dist/custom/ArtifactLockValidation.d.ts +28 -0
- package/dist/custom/ArtifactLockValidation.d.ts.map +1 -0
- package/dist/custom/ArtifactLockValidation.js +867 -0
- package/dist/custom/ArtifactLockValidation.js.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts +267 -0
- package/dist/custom/ArtifactPermissionDelegate.d.ts.map +1 -0
- package/dist/custom/ArtifactPermissionDelegate.js +1232 -0
- package/dist/custom/ArtifactPermissionDelegate.js.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts +199 -0
- package/dist/custom/ArtifactPreviewSnapshot.d.ts.map +1 -0
- package/dist/custom/ArtifactPreviewSnapshot.js +772 -0
- package/dist/custom/ArtifactPreviewSnapshot.js.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts +151 -0
- package/dist/custom/ArtifactSynthesisEngine.d.ts.map +1 -0
- package/dist/custom/ArtifactSynthesisEngine.js +1124 -0
- package/dist/custom/ArtifactSynthesisEngine.js.map +1 -0
- package/dist/custom/ConversationWriteAccess.d.ts +27 -0
- package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
- package/dist/custom/ConversationWriteAccess.js +53 -0
- package/dist/custom/ConversationWriteAccess.js.map +1 -1
- package/dist/custom/DocumentLiveBlockEngine.d.ts +612 -0
- package/dist/custom/DocumentLiveBlockEngine.d.ts.map +1 -0
- package/dist/custom/DocumentLiveBlockEngine.js +2352 -0
- package/dist/custom/DocumentLiveBlockEngine.js.map +1 -0
- package/dist/custom/MJQueryEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityExtended.js +27 -11
- package/dist/custom/MJQueryEntityExtended.js.map +1 -1
- package/dist/custom/MJUserViewEntityExtended.d.ts +4 -7
- package/dist/custom/MJUserViewEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJUserViewEntityExtended.js +15 -97
- package/dist/custom/MJUserViewEntityExtended.js.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js +31 -7
- package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts +3 -4
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts.map +1 -1
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js +334 -47
- package/dist/custom/PermissionProviders/CollectionPermissionProvider.js.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts +19 -3
- package/dist/custom/Permissions/BaseShareEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/BaseShareEntityExtended.js +139 -13
- package/dist/custom/Permissions/BaseShareEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts +8 -6
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +93 -41
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts +12 -5
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +240 -37
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
- package/dist/custom/SlideDeckEngine.d.ts +427 -0
- package/dist/custom/SlideDeckEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckEngine.js +1669 -0
- package/dist/custom/SlideDeckEngine.js.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts +25 -0
- package/dist/custom/SlideDeckPptxEngine.d.ts.map +1 -0
- package/dist/custom/SlideDeckPptxEngine.js +1237 -0
- package/dist/custom/SlideDeckPptxEngine.js.map +1 -0
- package/dist/custom/SpreadsheetEngine.d.ts +1370 -0
- package/dist/custom/SpreadsheetEngine.d.ts.map +1 -0
- package/dist/custom/SpreadsheetEngine.js +17580 -0
- package/dist/custom/SpreadsheetEngine.js.map +1 -0
- package/dist/custom/approvals.d.ts +7 -1
- package/dist/custom/approvals.d.ts.map +1 -1
- package/dist/custom/approvals.js +8 -1
- package/dist/custom/approvals.js.map +1 -1
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js +7 -0
- package/dist/custom/operations/ArtifactComplianceAuditOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js +7 -0
- package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts +60 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.d.ts.map +1 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js +6 -0
- package/dist/custom/operations/ArtifactGuestShareOperations.js.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts.map +1 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js +7 -0
- package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js.map +1 -0
- package/dist/custom/typedQuery.d.ts +162 -0
- package/dist/custom/typedQuery.d.ts.map +1 -0
- package/dist/custom/typedQuery.js +296 -0
- package/dist/custom/typedQuery.js.map +1 -0
- package/dist/engines/CanonGraphEngine.d.ts +122 -0
- package/dist/engines/CanonGraphEngine.d.ts.map +1 -0
- package/dist/engines/CanonGraphEngine.js +500 -0
- package/dist/engines/CanonGraphEngine.js.map +1 -0
- package/dist/engines/EncryptionEngineBase.js +2 -2
- package/dist/engines/EncryptionEngineBase.js.map +1 -1
- package/dist/engines/QueryEngine.js +2 -2
- package/dist/engines/QueryEngine.js.map +1 -1
- package/dist/engines/SearchEngineBase.d.ts +17 -3
- package/dist/engines/SearchEngineBase.d.ts.map +1 -1
- package/dist/engines/SearchEngineBase.js +100 -28
- package/dist/engines/SearchEngineBase.js.map +1 -1
- package/dist/engines/UserInfoEngine.d.ts +8 -0
- package/dist/engines/UserInfoEngine.d.ts.map +1 -1
- package/dist/engines/UserInfoEngine.js +62 -10
- package/dist/engines/UserInfoEngine.js.map +1 -1
- package/dist/engines/conversations.d.ts +213 -12
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +578 -30
- package/dist/engines/conversations.js.map +1 -1
- package/dist/generated/entities/__mj.d.ts +4265 -25257
- package/dist/generated/entities/__mj.d.ts.map +1 -1
- package/dist/generated/entities/__mj.js +3793 -40542
- package/dist/generated/entities/__mj.js.map +1 -1
- package/dist/generated/queries/__mj.d.ts +269 -0
- package/dist/generated/queries/__mj.d.ts.map +1 -0
- package/dist/generated/queries/__mj.js +100 -0
- package/dist/generated/queries/__mj.js.map +1 -0
- package/dist/generated/queries/index.d.ts +2 -0
- package/dist/generated/queries/index.d.ts.map +1 -0
- package/dist/generated/queries/index.js +4 -0
- package/dist/generated/queries/index.js.map +1 -0
- package/dist/generated/remote_operations.d.ts +275 -22
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +98 -3
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/generated/schemas/__mj.d.ts +25489 -0
- package/dist/generated/schemas/__mj.d.ts.map +1 -0
- package/dist/generated/schemas/__mj.js +41768 -0
- package/dist/generated/schemas/__mj.js.map +1 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +2 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/graph/BaseGraphEdgeProvider.d.ts +158 -0
- package/dist/graph/BaseGraphEdgeProvider.d.ts.map +1 -0
- package/dist/graph/BaseGraphEdgeProvider.js +70 -0
- package/dist/graph/BaseGraphEdgeProvider.js.map +1 -0
- package/dist/graph/GraphEngine.d.ts +274 -0
- package/dist/graph/GraphEngine.d.ts.map +1 -0
- package/dist/graph/GraphEngine.js +1156 -0
- package/dist/graph/GraphEngine.js.map +1 -0
- package/dist/graph/GraphExpansion.d.ts +142 -0
- package/dist/graph/GraphExpansion.d.ts.map +1 -0
- package/dist/graph/GraphExpansion.js +87 -0
- package/dist/graph/GraphExpansion.js.map +1 -0
- package/dist/graph/index.d.ts +15 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +30 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/providers/AlternateBaseViewEdgeProvider.d.ts +16 -0
- package/dist/graph/providers/AlternateBaseViewEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/AlternateBaseViewEdgeProvider.js +115 -0
- package/dist/graph/providers/AlternateBaseViewEdgeProvider.js.map +1 -0
- package/dist/graph/providers/EntityMetadataEdgeProvider.d.ts +17 -0
- package/dist/graph/providers/EntityMetadataEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/EntityMetadataEdgeProvider.js +145 -0
- package/dist/graph/providers/EntityMetadataEdgeProvider.js.map +1 -0
- package/dist/graph/providers/ForeignKeyEdgeProvider.d.ts +25 -0
- package/dist/graph/providers/ForeignKeyEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/ForeignKeyEdgeProvider.js +131 -0
- package/dist/graph/providers/ForeignKeyEdgeProvider.js.map +1 -0
- package/dist/graph/providers/JoinEntityEdgeProvider.d.ts +37 -0
- package/dist/graph/providers/JoinEntityEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/JoinEntityEdgeProvider.js +170 -0
- package/dist/graph/providers/JoinEntityEdgeProvider.js.map +1 -0
- package/dist/graph/providers/QueryEdgeProvider.d.ts +33 -0
- package/dist/graph/providers/QueryEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/QueryEdgeProvider.js +120 -0
- package/dist/graph/providers/QueryEdgeProvider.js.map +1 -0
- package/dist/graph/providers/QueryMetadataEdgeProvider.d.ts +18 -0
- package/dist/graph/providers/QueryMetadataEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/QueryMetadataEdgeProvider.js +163 -0
- package/dist/graph/providers/QueryMetadataEdgeProvider.js.map +1 -0
- package/dist/graph/providers/RecordLinkEdgeProvider.d.ts +20 -0
- package/dist/graph/providers/RecordLinkEdgeProvider.d.ts.map +1 -0
- package/dist/graph/providers/RecordLinkEdgeProvider.js +172 -0
- package/dist/graph/providers/RecordLinkEdgeProvider.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +6 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +6 -0
- package/dist/schemas.js.map +1 -0
- package/package.json +17 -6
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
import { NormalizeUUID, UUIDsEqual } from '@memberjunction/global';
|
|
2
|
+
import { DocumentLiveBlockEngine } from './DocumentLiveBlockEngine.js';
|
|
3
|
+
import { SlideDeckEngine } from './SlideDeckEngine.js';
|
|
4
|
+
import { EXCEL_MAX_COLS, EXCEL_MAX_ROWS, FormatCellAddress, ParseCellAddress, ParseRangeAddress, SpreadsheetEngine } from './SpreadsheetEngine.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds an unambiguous `(content, configuration)` composite cache key for `preParsedWorkbooks` (`R10-1`).
|
|
7
|
+
* Never share keys across different `(content, config)` pairs — a JSON `Configuration` overrides `.xlsx` metadata.
|
|
8
|
+
*/
|
|
9
|
+
export function MakePreParsedWorkbookCacheKey(content, configuration) {
|
|
10
|
+
const c = typeof content === 'string' ? content : '';
|
|
11
|
+
const cfg = typeof configuration === 'string' ? configuration : '';
|
|
12
|
+
return `${c.length}:${c}\0${cfg.length}:${cfg}`;
|
|
13
|
+
}
|
|
14
|
+
function parseWorkbookWithCache(content, config, preParsedWorkbooks) {
|
|
15
|
+
if (preParsedWorkbooks) {
|
|
16
|
+
const hit = preParsedWorkbooks.get(MakePreParsedWorkbookCacheKey(content, config));
|
|
17
|
+
if (hit) {
|
|
18
|
+
return hit;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return SpreadsheetEngine.Instance.ParseWorkbook(content, config, { SkipEvaluate: true });
|
|
22
|
+
}
|
|
23
|
+
function isSlideLockConfigEqual(a, b) {
|
|
24
|
+
return (Boolean(a?.Locked) === Boolean(b?.Locked) &&
|
|
25
|
+
(a?.LockedByUserID ?? '').trim().toLowerCase() === (b?.LockedByUserID ?? '').trim().toLowerCase() &&
|
|
26
|
+
Boolean(a?.AllowEditors) === Boolean(b?.AllowEditors));
|
|
27
|
+
}
|
|
28
|
+
function findDuplicateNonEmptyId(ids) {
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
for (const raw of ids) {
|
|
31
|
+
const trimmed = (raw ?? '').trim();
|
|
32
|
+
if (!trimmed) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (seen.has(trimmed)) {
|
|
36
|
+
return trimmed;
|
|
37
|
+
}
|
|
38
|
+
seen.add(trimmed);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function doParsedRangesOverlap(a, b) {
|
|
43
|
+
return a.startRow <= b.endRow && b.startRow <= a.endRow && a.startCol <= b.endCol && b.startCol <= a.endCol;
|
|
44
|
+
}
|
|
45
|
+
const INDEXED_BUCKET_SPAN = 64;
|
|
46
|
+
function buildCompiledProtectedRangeIndex(rules, maxRows, maxCols, predicate) {
|
|
47
|
+
const byRow = new Map();
|
|
48
|
+
const byCol = new Map();
|
|
49
|
+
const wideRules = [];
|
|
50
|
+
const allEntries = [];
|
|
51
|
+
const unparsedRules = [];
|
|
52
|
+
for (const rule of rules) {
|
|
53
|
+
if (predicate && !predicate(rule)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const bounds = ParseRangeAddress(rule.Range, maxRows, maxCols);
|
|
57
|
+
if (!bounds) {
|
|
58
|
+
unparsedRules.push(rule);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const entry = {
|
|
62
|
+
rule,
|
|
63
|
+
startRow: bounds.startRow,
|
|
64
|
+
endRow: bounds.endRow,
|
|
65
|
+
startCol: bounds.startCol,
|
|
66
|
+
endCol: bounds.endCol
|
|
67
|
+
};
|
|
68
|
+
allEntries.push(entry);
|
|
69
|
+
if (bounds.endRow - bounds.startRow <= INDEXED_BUCKET_SPAN) {
|
|
70
|
+
for (let r = bounds.startRow; r <= bounds.endRow; r++) {
|
|
71
|
+
let list = byRow.get(r);
|
|
72
|
+
if (!list) {
|
|
73
|
+
list = [];
|
|
74
|
+
byRow.set(r, list);
|
|
75
|
+
}
|
|
76
|
+
list.push(entry);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (bounds.endCol - bounds.startCol <= INDEXED_BUCKET_SPAN) {
|
|
80
|
+
for (let c = bounds.startCol; c <= bounds.endCol; c++) {
|
|
81
|
+
let list = byCol.get(c);
|
|
82
|
+
if (!list) {
|
|
83
|
+
list = [];
|
|
84
|
+
byCol.set(c, list);
|
|
85
|
+
}
|
|
86
|
+
list.push(entry);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
wideRules.push(entry);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { index: { byRow, byCol, wideRules }, allEntries, unparsedRules };
|
|
94
|
+
}
|
|
95
|
+
function isActorAllowedForLockRule(rule, editCtx) {
|
|
96
|
+
const actor = (editCtx.UserID ?? '').trim();
|
|
97
|
+
if (actor && editCtx.OwnerUserID && UUIDsEqual(actor, editCtx.OwnerUserID)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
if (actor && rule.LockedByUserID && UUIDsEqual(actor, rule.LockedByUserID)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (rule.AllowEditors && editCtx.IsEditor) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
function checkSheetCellWithIndex(index, cellAddress, editCtx) {
|
|
109
|
+
const pos = ParseCellAddress(cellAddress);
|
|
110
|
+
if (!pos) {
|
|
111
|
+
return { Allowed: true };
|
|
112
|
+
}
|
|
113
|
+
const candidates = [
|
|
114
|
+
index.byRow.get(pos.row),
|
|
115
|
+
index.byCol.get(pos.col),
|
|
116
|
+
index.wideRules
|
|
117
|
+
];
|
|
118
|
+
for (const bucket of candidates) {
|
|
119
|
+
if (!bucket) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const entry of bucket) {
|
|
123
|
+
if (pos.row >= entry.startRow &&
|
|
124
|
+
pos.row <= entry.endRow &&
|
|
125
|
+
pos.col >= entry.startCol &&
|
|
126
|
+
pos.col <= entry.endCol &&
|
|
127
|
+
!isActorAllowedForLockRule(entry.rule, editCtx)) {
|
|
128
|
+
return {
|
|
129
|
+
Allowed: false,
|
|
130
|
+
Reason: `Cell '${cellAddress}' falls inside protected range '${entry.rule.Range}' (locked by ${entry.rule.LockedByUserID}).`
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { Allowed: true };
|
|
136
|
+
}
|
|
137
|
+
function findOverlappingIndexedProtectedRule(nextBounds, compiled) {
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
if (nextBounds.endRow - nextBounds.startRow <= INDEXED_BUCKET_SPAN) {
|
|
140
|
+
for (let r = nextBounds.startRow; r <= nextBounds.endRow; r++) {
|
|
141
|
+
const list = compiled.index.byRow.get(r);
|
|
142
|
+
if (!list)
|
|
143
|
+
continue;
|
|
144
|
+
for (const entry of list) {
|
|
145
|
+
if (seen.has(entry))
|
|
146
|
+
continue;
|
|
147
|
+
seen.add(entry);
|
|
148
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
149
|
+
return entry.rule;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const entry of compiled.index.wideRules) {
|
|
154
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
155
|
+
return entry.rule;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Row-narrow incoming range could also intersect col-bucketed rules covering that column
|
|
159
|
+
for (let c = nextBounds.startCol; c <= nextBounds.endCol && c - nextBounds.startCol <= INDEXED_BUCKET_SPAN; c++) {
|
|
160
|
+
const list = compiled.index.byCol.get(c);
|
|
161
|
+
if (!list)
|
|
162
|
+
continue;
|
|
163
|
+
for (const entry of list) {
|
|
164
|
+
if (seen.has(entry))
|
|
165
|
+
continue;
|
|
166
|
+
seen.add(entry);
|
|
167
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
168
|
+
return entry.rule;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (nextBounds.endCol - nextBounds.startCol > INDEXED_BUCKET_SPAN) {
|
|
173
|
+
for (const colEntries of compiled.index.byCol.values()) {
|
|
174
|
+
for (const entry of colEntries) {
|
|
175
|
+
if (seen.has(entry))
|
|
176
|
+
continue;
|
|
177
|
+
seen.add(entry);
|
|
178
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
179
|
+
return entry.rule;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (nextBounds.endCol - nextBounds.startCol <= INDEXED_BUCKET_SPAN) {
|
|
187
|
+
for (let c = nextBounds.startCol; c <= nextBounds.endCol; c++) {
|
|
188
|
+
const list = compiled.index.byCol.get(c);
|
|
189
|
+
if (!list)
|
|
190
|
+
continue;
|
|
191
|
+
for (const entry of list) {
|
|
192
|
+
if (seen.has(entry))
|
|
193
|
+
continue;
|
|
194
|
+
seen.add(entry);
|
|
195
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
196
|
+
return entry.rule;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const entry of compiled.index.wideRules) {
|
|
201
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
202
|
+
return entry.rule;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const rowEntries of compiled.index.byRow.values()) {
|
|
206
|
+
for (const entry of rowEntries) {
|
|
207
|
+
if (seen.has(entry))
|
|
208
|
+
continue;
|
|
209
|
+
seen.add(entry);
|
|
210
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
211
|
+
return entry.rule;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
for (const entry of compiled.allEntries) {
|
|
218
|
+
if (doParsedRangesOverlap(nextBounds, entry)) {
|
|
219
|
+
return entry.rule;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
function findFirstRowIdMismatchIndex(prevRows, nextRows) {
|
|
225
|
+
const prev = prevRows ?? [];
|
|
226
|
+
const next = nextRows ?? [];
|
|
227
|
+
const shared = Math.min(prev.length, next.length);
|
|
228
|
+
for (let i = 0; i < shared; i++) {
|
|
229
|
+
if (prev[i].RowID !== next[i].RowID) {
|
|
230
|
+
return i;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return shared;
|
|
234
|
+
}
|
|
235
|
+
function findFirstColIdMismatchIndex(prevCols, nextCols) {
|
|
236
|
+
const prev = prevCols ?? [];
|
|
237
|
+
const next = nextCols ?? [];
|
|
238
|
+
const shared = Math.min(prev.length, next.length);
|
|
239
|
+
for (let i = 0; i < shared; i++) {
|
|
240
|
+
if (prev[i].ColumnID !== next[i].ColumnID) {
|
|
241
|
+
return i;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return shared;
|
|
245
|
+
}
|
|
246
|
+
function inspectStructuredJsonKind(raw) {
|
|
247
|
+
if (!raw || typeof raw !== 'string') {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const trimmed = raw.trim();
|
|
251
|
+
if (!trimmed.startsWith('{')) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const parsed = JSON.parse(trimmed);
|
|
256
|
+
if (Array.isArray(parsed.Slides)) {
|
|
257
|
+
return 'slides';
|
|
258
|
+
}
|
|
259
|
+
if (Array.isArray(parsed.Worksheets)) {
|
|
260
|
+
return 'workbook';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
function isXlsxBinaryTextPayload(raw) {
|
|
269
|
+
if (!raw || typeof raw !== 'string') {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
const trimmed = raw.trim();
|
|
273
|
+
return trimmed.startsWith('data:') || trimmed.startsWith('UEsDB');
|
|
274
|
+
}
|
|
275
|
+
function validateNewLocksOnEmptyContent(nextContent, actorUserId, isOwner, preParsedWorkbooks) {
|
|
276
|
+
const trimmedNext = nextContent.trim();
|
|
277
|
+
const isWorkbookPayload = inspectStructuredJsonKind(trimmedNext) === 'workbook' || isXlsxBinaryTextPayload(trimmedNext);
|
|
278
|
+
const isSlidePayload = inspectStructuredJsonKind(trimmedNext) === 'slides';
|
|
279
|
+
if (!isWorkbookPayload && !isSlidePayload) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const normActor = actorUserId ? NormalizeUUID(actorUserId) : '';
|
|
283
|
+
try {
|
|
284
|
+
if (isSlidePayload) {
|
|
285
|
+
const nextDeck = SlideDeckEngine.Instance.ParseDeckSpec(nextContent);
|
|
286
|
+
const dupSlideId = findDuplicateNonEmptyId(nextDeck.Slides.map((s) => s.SlideID));
|
|
287
|
+
if (dupSlideId) {
|
|
288
|
+
return { Allowed: false, Reason: `Duplicate SlideID '${dupSlideId}' is not allowed.` };
|
|
289
|
+
}
|
|
290
|
+
for (const nextSlide of nextDeck.Slides) {
|
|
291
|
+
const dupRegionId = findDuplicateNonEmptyId(nextSlide.Regions.map((r) => r.RegionID));
|
|
292
|
+
if (dupRegionId) {
|
|
293
|
+
return { Allowed: false, Reason: `Duplicate RegionID '${dupRegionId}' is not allowed.` };
|
|
294
|
+
}
|
|
295
|
+
if (!isOwner) {
|
|
296
|
+
if (nextSlide.Locked && (!normActor || NormalizeUUID(nextSlide.LockedByUserID ?? '') !== normActor)) {
|
|
297
|
+
return {
|
|
298
|
+
Allowed: false,
|
|
299
|
+
Reason: 'Cannot create locked slide with another user as LockedByUserID.'
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
for (const reg of nextSlide.Regions) {
|
|
303
|
+
if (reg.Locked && (!normActor || NormalizeUUID(reg.LockedByUserID ?? '') !== normActor)) {
|
|
304
|
+
return {
|
|
305
|
+
Allowed: false,
|
|
306
|
+
Reason: 'Cannot create locked region with another user as LockedByUserID.'
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return { Allowed: true };
|
|
313
|
+
}
|
|
314
|
+
if (isWorkbookPayload) {
|
|
315
|
+
const nextWb = parseWorkbookWithCache(nextContent, undefined, preParsedWorkbooks);
|
|
316
|
+
const dupSheetId = findDuplicateNonEmptyId(nextWb.Worksheets.map((w) => w.SheetID));
|
|
317
|
+
if (dupSheetId) {
|
|
318
|
+
return { Allowed: false, Reason: `Duplicate SheetID '${dupSheetId}' is not allowed.` };
|
|
319
|
+
}
|
|
320
|
+
for (const nextSheet of nextWb.Worksheets) {
|
|
321
|
+
const dupRangeId = findDuplicateNonEmptyId((nextSheet.ProtectedRanges ?? []).map((r) => r.RangeID));
|
|
322
|
+
if (dupRangeId) {
|
|
323
|
+
return { Allowed: false, Reason: `Duplicate RangeID '${dupRangeId}' is not allowed.` };
|
|
324
|
+
}
|
|
325
|
+
if (!isOwner) {
|
|
326
|
+
for (const rule of nextSheet.ProtectedRanges ?? []) {
|
|
327
|
+
if (!normActor || NormalizeUUID(rule.LockedByUserID) !== normActor) {
|
|
328
|
+
return {
|
|
329
|
+
Allowed: false,
|
|
330
|
+
Reason: `Cannot create protected range '${rule.Range}' with spoofed LockedByUserID.`
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return { Allowed: true };
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
const msg = err instanceof Error ? err.message : '';
|
|
341
|
+
if (msg.startsWith('Spreadsheet ')) {
|
|
342
|
+
return { Allowed: false, Reason: msg };
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
Allowed: false,
|
|
346
|
+
Reason: 'Write rejected: malformed update to structured document.'
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
function validateSlideDeckLockTransition(prevDeck, nextDeck, actorUserId, isOwner) {
|
|
352
|
+
const effectiveOwnerId = isOwner && actorUserId ? actorUserId : '__artifact_owner__';
|
|
353
|
+
const normActor = actorUserId ? NormalizeUUID(actorUserId) : '';
|
|
354
|
+
const dupSlideId = findDuplicateNonEmptyId(nextDeck.Slides.map((s) => s.SlideID));
|
|
355
|
+
if (dupSlideId) {
|
|
356
|
+
return { Allowed: false, Reason: `Duplicate SlideID '${dupSlideId}' is not allowed.` };
|
|
357
|
+
}
|
|
358
|
+
const nextSlidesById = new Map(nextDeck.Slides.map((s) => [s.SlideID, s]));
|
|
359
|
+
for (const nextSlide of nextDeck.Slides) {
|
|
360
|
+
const dupRegionId = findDuplicateNonEmptyId(nextSlide.Regions.map((r) => r.RegionID));
|
|
361
|
+
if (dupRegionId) {
|
|
362
|
+
return {
|
|
363
|
+
Allowed: false,
|
|
364
|
+
Reason: `Duplicate RegionID '${dupRegionId}' on slide '${nextSlide.SlideID}' is not allowed.`
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
for (const prevSlide of prevDeck.Slides) {
|
|
369
|
+
const nextSlide = nextSlidesById.get(prevSlide.SlideID);
|
|
370
|
+
const slideCheck = SlideDeckEngine.Instance.CanActorEditSlide(prevSlide, actorUserId, effectiveOwnerId, true);
|
|
371
|
+
if (!slideCheck.Allowed) {
|
|
372
|
+
if (!nextSlide || JSON.stringify(prevSlide) !== JSON.stringify(nextSlide)) {
|
|
373
|
+
return { Allowed: false, Reason: slideCheck.Reason };
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (!isOwner && nextSlide && !isSlideLockConfigEqual(prevSlide, nextSlide)) {
|
|
378
|
+
const canSelfLockSlide = !prevSlide.Locked &&
|
|
379
|
+
Boolean(nextSlide.Locked) &&
|
|
380
|
+
normActor !== '' &&
|
|
381
|
+
NormalizeUUID(nextSlide.LockedByUserID ?? '') === normActor &&
|
|
382
|
+
!nextSlide.AllowEditors;
|
|
383
|
+
const isSelfLockOwner = Boolean(prevSlide.Locked) &&
|
|
384
|
+
normActor !== '' &&
|
|
385
|
+
NormalizeUUID(prevSlide.LockedByUserID ?? '') === normActor &&
|
|
386
|
+
(!nextSlide.Locked || NormalizeUUID(nextSlide.LockedByUserID ?? '') === normActor);
|
|
387
|
+
if (!canSelfLockSlide && !isSelfLockOwner) {
|
|
388
|
+
return {
|
|
389
|
+
Allowed: false,
|
|
390
|
+
Reason: 'Cannot modify slide lock metadata without owner permission.'
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (prevSlide.Regions.length > 0) {
|
|
395
|
+
const nextRegionsById = nextSlide
|
|
396
|
+
? new Map(nextSlide.Regions.map((r) => [r.RegionID, r]))
|
|
397
|
+
: null;
|
|
398
|
+
for (const prevRegion of prevSlide.Regions) {
|
|
399
|
+
const regionCheck = SlideDeckEngine.Instance.CanActorEditRegion(prevSlide, prevRegion, actorUserId, effectiveOwnerId, true);
|
|
400
|
+
const nextRegion = nextRegionsById?.get(prevRegion.RegionID);
|
|
401
|
+
if (!regionCheck.Allowed) {
|
|
402
|
+
if (!nextSlide || !nextRegion || JSON.stringify(prevRegion) !== JSON.stringify(nextRegion)) {
|
|
403
|
+
return { Allowed: false, Reason: regionCheck.Reason };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else if (!isOwner &&
|
|
407
|
+
nextRegion &&
|
|
408
|
+
!isSlideLockConfigEqual(prevRegion, nextRegion)) {
|
|
409
|
+
const canSelfLockRegion = !prevRegion.Locked &&
|
|
410
|
+
Boolean(nextRegion.Locked) &&
|
|
411
|
+
normActor !== '' &&
|
|
412
|
+
NormalizeUUID(nextRegion.LockedByUserID ?? '') === normActor &&
|
|
413
|
+
!nextRegion.AllowEditors;
|
|
414
|
+
const isSelfLockOwner = Boolean(prevRegion.Locked) &&
|
|
415
|
+
normActor !== '' &&
|
|
416
|
+
NormalizeUUID(prevRegion.LockedByUserID ?? '') === normActor &&
|
|
417
|
+
(!nextRegion.Locked ||
|
|
418
|
+
NormalizeUUID(nextRegion.LockedByUserID ?? '') === normActor);
|
|
419
|
+
if (!canSelfLockRegion && !isSelfLockOwner) {
|
|
420
|
+
return {
|
|
421
|
+
Allowed: false,
|
|
422
|
+
Reason: 'Cannot modify slide region lock metadata without owner permission.'
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (!isOwner) {
|
|
430
|
+
const prevSlidesById = new Map(prevDeck.Slides.map((s) => [s.SlideID, s]));
|
|
431
|
+
for (const nextSlide of nextDeck.Slides) {
|
|
432
|
+
const prevSlide = prevSlidesById.get(nextSlide.SlideID);
|
|
433
|
+
if (!prevSlide && nextSlide.Locked) {
|
|
434
|
+
if (!normActor || NormalizeUUID(nextSlide.LockedByUserID ?? '') !== normActor) {
|
|
435
|
+
return {
|
|
436
|
+
Allowed: false,
|
|
437
|
+
Reason: 'Cannot create locked slide with another user as LockedByUserID.'
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const prevRegIds = new Set(prevSlide ? prevSlide.Regions.map((r) => r.RegionID) : []);
|
|
442
|
+
for (const nextReg of nextSlide.Regions) {
|
|
443
|
+
if (!prevRegIds.has(nextReg.RegionID) && nextReg.Locked) {
|
|
444
|
+
if (!normActor || NormalizeUUID(nextReg.LockedByUserID ?? '') !== normActor) {
|
|
445
|
+
return {
|
|
446
|
+
Allowed: false,
|
|
447
|
+
Reason: 'Cannot create locked region with another user as LockedByUserID.'
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return { Allowed: true };
|
|
455
|
+
}
|
|
456
|
+
function serializeSheetCellForLockDiff(cell) {
|
|
457
|
+
if (!cell) {
|
|
458
|
+
return 'null';
|
|
459
|
+
}
|
|
460
|
+
const { ComputedValue: _cv, DisplayValue: _dv, ...structuralCell } = cell;
|
|
461
|
+
return JSON.stringify(structuralCell);
|
|
462
|
+
}
|
|
463
|
+
function validateWorkbookLockTransition(prevWb, nextWb, actorUserId, isOwner) {
|
|
464
|
+
const effectiveOwnerId = isOwner && actorUserId ? actorUserId : '__artifact_owner__';
|
|
465
|
+
const normActor = actorUserId ? NormalizeUUID(actorUserId) : '';
|
|
466
|
+
const dupSheetId = findDuplicateNonEmptyId(nextWb.Worksheets.map((s) => s.SheetID));
|
|
467
|
+
if (dupSheetId) {
|
|
468
|
+
return { Allowed: false, Reason: `Duplicate SheetID '${dupSheetId}' is not allowed.` };
|
|
469
|
+
}
|
|
470
|
+
const nextSheetsById = new Map(nextWb.Worksheets.map((s) => [s.SheetID, s]));
|
|
471
|
+
const prevSheetsById = new Map(prevWb.Worksheets.map((s) => [s.SheetID, s]));
|
|
472
|
+
const editCtx = {
|
|
473
|
+
UserID: actorUserId ?? undefined,
|
|
474
|
+
OwnerUserID: effectiveOwnerId,
|
|
475
|
+
IsEditor: true
|
|
476
|
+
};
|
|
477
|
+
for (const prevSheet of prevWb.Worksheets) {
|
|
478
|
+
const rules = prevSheet.ProtectedRanges ?? [];
|
|
479
|
+
const nextSheet = nextSheetsById.get(prevSheet.SheetID);
|
|
480
|
+
if (!nextSheet) {
|
|
481
|
+
if (rules.length > 0 && !isOwner) {
|
|
482
|
+
return {
|
|
483
|
+
Allowed: false,
|
|
484
|
+
Reason: `Cannot delete worksheet '${prevSheet.Name}' containing protected ranges.`
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
const dupRangeId = findDuplicateNonEmptyId((nextSheet.ProtectedRanges ?? []).map((r) => r.RangeID));
|
|
490
|
+
if (dupRangeId) {
|
|
491
|
+
return {
|
|
492
|
+
Allowed: false,
|
|
493
|
+
Reason: `Duplicate RangeID '${dupRangeId}' on worksheet '${prevSheet.Name}' is not allowed.`
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
const prevRulesById = new Map(rules.map((r) => [r.RangeID, r]));
|
|
497
|
+
const nextRulesById = new Map((nextSheet.ProtectedRanges ?? []).map((r) => [r.RangeID, r]));
|
|
498
|
+
for (const rule of rules) {
|
|
499
|
+
const matchingNextRule = nextRulesById.get(rule.RangeID);
|
|
500
|
+
const isRuleOwner = isOwner || (normActor !== '' && NormalizeUUID(rule.LockedByUserID) === normActor);
|
|
501
|
+
const ruleModified = !matchingNextRule ||
|
|
502
|
+
matchingNextRule.Range !== rule.Range ||
|
|
503
|
+
Boolean(matchingNextRule.AllowEditors) !== Boolean(rule.AllowEditors) ||
|
|
504
|
+
NormalizeUUID(matchingNextRule.LockedByUserID) !== NormalizeUUID(rule.LockedByUserID) ||
|
|
505
|
+
(matchingNextRule.Description ?? '') !== (rule.Description ?? '') ||
|
|
506
|
+
(matchingNextRule.LockedAt ?? '') !== (rule.LockedAt ?? '');
|
|
507
|
+
if (ruleModified && !isRuleOwner) {
|
|
508
|
+
return {
|
|
509
|
+
Allowed: false,
|
|
510
|
+
Reason: `Cannot alter or remove protected range '${rule.Range}' without owner permission.`
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
const maxRows = Math.max(prevSheet.Rows?.length ?? 0, nextSheet.Rows?.length ?? 0, 1000);
|
|
515
|
+
const maxCols = Math.max(prevSheet.Columns?.length ?? 0, nextSheet.Columns?.length ?? 0, 260);
|
|
516
|
+
if (!isOwner && rules.length > 0) {
|
|
517
|
+
const newRulesToCheck = (nextSheet.ProtectedRanges ?? []).filter((nr) => !prevRulesById.has(nr.RangeID));
|
|
518
|
+
if (newRulesToCheck.length > 0) {
|
|
519
|
+
const disallowedPrev = buildCompiledProtectedRangeIndex(rules, maxRows, maxCols, (prevRule) => {
|
|
520
|
+
const isPrevRuleCreator = normActor !== '' && NormalizeUUID(prevRule.LockedByUserID) === normActor;
|
|
521
|
+
return !isPrevRuleCreator && !prevRule.AllowEditors;
|
|
522
|
+
});
|
|
523
|
+
for (const nextRule of newRulesToCheck) {
|
|
524
|
+
if (!normActor || NormalizeUUID(nextRule.LockedByUserID) !== normActor) {
|
|
525
|
+
return {
|
|
526
|
+
Allowed: false,
|
|
527
|
+
Reason: `Cannot create protected range '${nextRule.Range}' with spoofed LockedByUserID.`
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
const nextParsed = ParseRangeAddress(nextRule.Range, maxRows, maxCols);
|
|
531
|
+
if (!nextParsed) {
|
|
532
|
+
return {
|
|
533
|
+
Allowed: false,
|
|
534
|
+
Reason: `Invalid protected range address '${nextRule.Range}'.`
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
if (disallowedPrev.unparsedRules.length > 0) {
|
|
538
|
+
return {
|
|
539
|
+
Allowed: false,
|
|
540
|
+
Reason: `Cannot add protected range '${nextRule.Range}' overlapping locked range '${disallowedPrev.unparsedRules[0].Range}'.`
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
const overlapping = findOverlappingIndexedProtectedRule(nextParsed, disallowedPrev);
|
|
544
|
+
if (overlapping) {
|
|
545
|
+
return {
|
|
546
|
+
Allowed: false,
|
|
547
|
+
Reason: `Cannot add protected range '${nextRule.Range}' overlapping locked range '${overlapping.Range}'.`
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
else if (!isOwner) {
|
|
554
|
+
for (const nextRule of nextSheet.ProtectedRanges ?? []) {
|
|
555
|
+
if (!prevRulesById.has(nextRule.RangeID)) {
|
|
556
|
+
if (!normActor || NormalizeUUID(nextRule.LockedByUserID) !== normActor) {
|
|
557
|
+
return {
|
|
558
|
+
Allowed: false,
|
|
559
|
+
Reason: `Cannot create protected range '${nextRule.Range}' with spoofed LockedByUserID.`
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const nextParsed = ParseRangeAddress(nextRule.Range, maxRows, maxCols);
|
|
563
|
+
if (!nextParsed) {
|
|
564
|
+
return {
|
|
565
|
+
Allowed: false,
|
|
566
|
+
Reason: `Invalid protected range address '${nextRule.Range}'.`
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (rules.length === 0) {
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const prevRowsLen = prevSheet.Rows?.length ?? 0;
|
|
576
|
+
const nextRowsLen = nextSheet.Rows?.length ?? 0;
|
|
577
|
+
const firstRowMismatchIdx = findFirstRowIdMismatchIndex(prevSheet.Rows, nextSheet.Rows);
|
|
578
|
+
const prevColsLen = prevSheet.Columns?.length ?? 0;
|
|
579
|
+
const nextColsLen = nextSheet.Columns?.length ?? 0;
|
|
580
|
+
const firstColMismatchIdx = findFirstColIdMismatchIndex(prevSheet.Columns, nextSheet.Columns);
|
|
581
|
+
const sortSpecChanged = JSON.stringify(prevSheet.SortSpec ?? null) !== JSON.stringify(nextSheet.SortSpec ?? null);
|
|
582
|
+
const mergeRangesChanged = JSON.stringify(prevSheet.MergeRanges ?? []) !== JSON.stringify(nextSheet.MergeRanges ?? []);
|
|
583
|
+
for (const rule of rules) {
|
|
584
|
+
const parsedRange = ParseRangeAddress(rule.Range, maxRows, maxCols);
|
|
585
|
+
if (!parsedRange) {
|
|
586
|
+
if (!isOwner) {
|
|
587
|
+
return {
|
|
588
|
+
Allowed: false,
|
|
589
|
+
Reason: `Blocked structural edit: invalid protected range '${rule.Range}'.`
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
if (isActorAllowedForLockRule(rule, editCtx)) {
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
const sampleAddr = FormatCellAddress(parsedRange.startRow, parsedRange.startCol);
|
|
598
|
+
const sampleDeniedReason = `Cell '${sampleAddr}' falls inside protected range '${rule.Range}' (locked by ${rule.LockedByUserID}).`;
|
|
599
|
+
const prevRowPrefixLen = Math.min(prevRowsLen, parsedRange.endRow);
|
|
600
|
+
const nextRowPrefixLen = Math.min(nextRowsLen, parsedRange.endRow);
|
|
601
|
+
if (prevRowPrefixLen !== nextRowPrefixLen || firstRowMismatchIdx < prevRowPrefixLen) {
|
|
602
|
+
return {
|
|
603
|
+
Allowed: false,
|
|
604
|
+
Reason: sampleDeniedReason
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
const prevColPrefixLen = Math.min(prevColsLen, parsedRange.endCol);
|
|
608
|
+
const nextColPrefixLen = Math.min(nextColsLen, parsedRange.endCol);
|
|
609
|
+
if (prevColPrefixLen !== nextColPrefixLen || firstColMismatchIdx < prevColPrefixLen) {
|
|
610
|
+
return {
|
|
611
|
+
Allowed: false,
|
|
612
|
+
Reason: sampleDeniedReason
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
if (sortSpecChanged) {
|
|
616
|
+
return {
|
|
617
|
+
Allowed: false,
|
|
618
|
+
Reason: `Cannot alter sort specification on worksheet with protected range '${rule.Range}'.`
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
if (mergeRangesChanged) {
|
|
622
|
+
return {
|
|
623
|
+
Allowed: false,
|
|
624
|
+
Reason: `Cannot alter merged ranges on worksheet with protected range '${rule.Range}'.`
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const compiledPrevCellIndex = buildCompiledProtectedRangeIndex(rules, EXCEL_MAX_ROWS, EXCEL_MAX_COLS).index;
|
|
629
|
+
const allAddresses = new Set([
|
|
630
|
+
...Object.keys(prevSheet.Cells ?? {}),
|
|
631
|
+
...Object.keys(nextSheet.Cells ?? {})
|
|
632
|
+
]);
|
|
633
|
+
for (const addr of allAddresses) {
|
|
634
|
+
const prevCell = prevSheet.Cells?.[addr];
|
|
635
|
+
const nextCell = nextSheet.Cells?.[addr];
|
|
636
|
+
if (serializeSheetCellForLockDiff(prevCell) === serializeSheetCellForLockDiff(nextCell)) {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const perm = checkSheetCellWithIndex(compiledPrevCellIndex, addr, editCtx);
|
|
640
|
+
if (!perm.Allowed) {
|
|
641
|
+
return { Allowed: false, Reason: perm.Reason };
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (!isOwner) {
|
|
646
|
+
for (const nextSheet of nextWb.Worksheets) {
|
|
647
|
+
if (prevSheetsById.has(nextSheet.SheetID)) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
const dupRangeId = findDuplicateNonEmptyId((nextSheet.ProtectedRanges ?? []).map((r) => r.RangeID));
|
|
651
|
+
if (dupRangeId) {
|
|
652
|
+
return {
|
|
653
|
+
Allowed: false,
|
|
654
|
+
Reason: `Duplicate RangeID '${dupRangeId}' on worksheet '${nextSheet.Name}' is not allowed.`
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
for (const nextRule of nextSheet.ProtectedRanges ?? []) {
|
|
658
|
+
if (!normActor || NormalizeUUID(nextRule.LockedByUserID) !== normActor) {
|
|
659
|
+
return {
|
|
660
|
+
Allowed: false,
|
|
661
|
+
Reason: `Cannot create protected range '${nextRule.Range}' with spoofed LockedByUserID.`
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return { Allowed: true };
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Validates an artifact content mutation (`currentContent -> nextContent`) and optional
|
|
671
|
+
* `Configuration` transition against Markdown heading/block locks, Slide Deck locks (`Locked`,
|
|
672
|
+
* `LockedByUserID`, `AllowEditors`), and Spreadsheet protected ranges (`ProtectedRanges`) (`B3`).
|
|
673
|
+
*/
|
|
674
|
+
export function ValidateArtifactContentMutationAgainstLocks(currentContent, nextContent, actorUserId, isOwner = false, options) {
|
|
675
|
+
const currentConfig = options?.currentConfiguration ?? null;
|
|
676
|
+
const nextConfig = options?.nextConfiguration ?? null;
|
|
677
|
+
if (currentContent === nextContent && currentConfig === nextConfig) {
|
|
678
|
+
return { Allowed: true };
|
|
679
|
+
}
|
|
680
|
+
const effectiveOwnerId = isOwner && actorUserId ? actorUserId : '__artifact_owner__';
|
|
681
|
+
const normActor = actorUserId ? NormalizeUUID(actorUserId) : '';
|
|
682
|
+
const trimmedCurrent = currentContent.trim();
|
|
683
|
+
if (!trimmedCurrent && !(currentConfig ?? '').trim()) {
|
|
684
|
+
if (nextConfig && inspectStructuredJsonKind(nextConfig)) {
|
|
685
|
+
const emptyConfigCheck = validateNewLocksOnEmptyContent(nextConfig, actorUserId, isOwner, options?.preParsedWorkbooks);
|
|
686
|
+
if (emptyConfigCheck !== null && !emptyConfigCheck.Allowed) {
|
|
687
|
+
return emptyConfigCheck;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const emptyContentCheck = validateNewLocksOnEmptyContent(nextContent, actorUserId, isOwner, options?.preParsedWorkbooks);
|
|
691
|
+
if (emptyContentCheck !== null && !emptyContentCheck.Allowed) {
|
|
692
|
+
return emptyContentCheck;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const currentContentKind = inspectStructuredJsonKind(currentContent);
|
|
696
|
+
const nextContentKind = inspectStructuredJsonKind(nextContent);
|
|
697
|
+
const currentConfigKind = inspectStructuredJsonKind(currentConfig);
|
|
698
|
+
const nextConfigKind = inspectStructuredJsonKind(nextConfig);
|
|
699
|
+
const hasCurrentSlides = currentContentKind === 'slides' || currentConfigKind === 'slides';
|
|
700
|
+
const isSlidesInvolved = hasCurrentSlides || nextContentKind === 'slides' || nextConfigKind === 'slides';
|
|
701
|
+
const hasCurrentWorkbook = currentContentKind === 'workbook' ||
|
|
702
|
+
currentConfigKind === 'workbook' ||
|
|
703
|
+
isXlsxBinaryTextPayload(currentContent);
|
|
704
|
+
const isWorkbookInvolved = hasCurrentWorkbook ||
|
|
705
|
+
nextContentKind === 'workbook' ||
|
|
706
|
+
nextConfigKind === 'workbook' ||
|
|
707
|
+
isXlsxBinaryTextPayload(nextContent);
|
|
708
|
+
if (isSlidesInvolved) {
|
|
709
|
+
try {
|
|
710
|
+
const checkSlidePair = (prevPayload, nextPayload) => {
|
|
711
|
+
if (prevPayload.trim()) {
|
|
712
|
+
const res = validateSlideDeckLockTransition(SlideDeckEngine.Instance.ParseDeckSpec(prevPayload), SlideDeckEngine.Instance.ParseDeckSpec(nextPayload), actorUserId, isOwner);
|
|
713
|
+
if (!res.Allowed) {
|
|
714
|
+
return res;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
const newCheck = validateNewLocksOnEmptyContent(nextPayload, actorUserId, isOwner);
|
|
719
|
+
if (newCheck && !newCheck.Allowed) {
|
|
720
|
+
return newCheck;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return null;
|
|
724
|
+
};
|
|
725
|
+
if (hasCurrentSlides) {
|
|
726
|
+
// R4 / Lower: Use the Content slot only when it parses as slides (so an owner with Markdown
|
|
727
|
+
// Content + slides Configuration never fails parsing); still block non-owners replacing
|
|
728
|
+
// locked slides with non-slide Markdown Content (`R4`).
|
|
729
|
+
const prevRenderedSlide = currentContentKind === 'slides'
|
|
730
|
+
? currentContent
|
|
731
|
+
: currentConfigKind === 'slides'
|
|
732
|
+
? currentConfig
|
|
733
|
+
: '';
|
|
734
|
+
const nonOwnerNonSlideContentOverride = !isOwner && nextContent.trim().length > 0 && nextContentKind !== 'slides';
|
|
735
|
+
const nextRenderedSlide = nonOwnerNonSlideContentOverride
|
|
736
|
+
? nextContent
|
|
737
|
+
: nextContentKind === 'slides'
|
|
738
|
+
? nextContent
|
|
739
|
+
: nextConfigKind === 'slides'
|
|
740
|
+
? nextConfig
|
|
741
|
+
: '';
|
|
742
|
+
if (prevRenderedSlide || nextRenderedSlide) {
|
|
743
|
+
const renderedCheck = checkSlidePair(prevRenderedSlide, nextRenderedSlide);
|
|
744
|
+
if (renderedCheck) {
|
|
745
|
+
return renderedCheck;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
// Prior state was not slides (e.g. locked Markdown); validate any newly introduced slide locks
|
|
751
|
+
// without returning Allowed early so DocumentLiveBlockEngine still inspects `Content` (`B1`).
|
|
752
|
+
if (nextContentKind === 'slides') {
|
|
753
|
+
const newSlideContentCheck = validateNewLocksOnEmptyContent(nextContent, actorUserId, isOwner);
|
|
754
|
+
if (newSlideContentCheck && !newSlideContentCheck.Allowed) {
|
|
755
|
+
return newSlideContentCheck;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (nextConfigKind === 'slides' && nextConfig) {
|
|
759
|
+
const newSlideConfigCheck = validateNewLocksOnEmptyContent(nextConfig, actorUserId, isOwner);
|
|
760
|
+
if (newSlideConfigCheck && !newSlideConfigCheck.Allowed) {
|
|
761
|
+
return newSlideConfigCheck;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (currentContentKind === 'slides' || (hasCurrentSlides && nextContentKind === 'slides')) {
|
|
766
|
+
const contentCheck = checkSlidePair(currentContent, nextContent);
|
|
767
|
+
if (contentCheck) {
|
|
768
|
+
return contentCheck;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (currentConfigKind === 'slides' || (hasCurrentSlides && nextConfigKind === 'slides')) {
|
|
772
|
+
const configCheck = checkSlidePair(currentConfig ?? '', nextConfig ?? '');
|
|
773
|
+
if (configCheck) {
|
|
774
|
+
return configCheck;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
catch {
|
|
779
|
+
return {
|
|
780
|
+
Allowed: false,
|
|
781
|
+
Reason: 'Write rejected: malformed update to structured presentation with protected regions.'
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (isWorkbookInvolved) {
|
|
786
|
+
try {
|
|
787
|
+
if (hasCurrentWorkbook) {
|
|
788
|
+
const prevEffectiveWb = parseWorkbookWithCache(currentContent, currentConfig, options?.preParsedWorkbooks);
|
|
789
|
+
const nextEffectiveWb = parseWorkbookWithCache(nextContent, nextConfig, options?.preParsedWorkbooks);
|
|
790
|
+
const effectiveRes = validateWorkbookLockTransition(prevEffectiveWb, nextEffectiveWb, actorUserId, isOwner);
|
|
791
|
+
if (!effectiveRes.Allowed) {
|
|
792
|
+
return effectiveRes;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
// Prior state was not a workbook (e.g. locked Markdown); validate any newly introduced
|
|
797
|
+
// protected ranges without returning Allowed early so `docCheck` still runs (`B1`).
|
|
798
|
+
if (nextContentKind === 'workbook' || isXlsxBinaryTextPayload(nextContent)) {
|
|
799
|
+
const newWbContentCheck = validateNewLocksOnEmptyContent(nextContent, actorUserId, isOwner, options?.preParsedWorkbooks);
|
|
800
|
+
if (newWbContentCheck && !newWbContentCheck.Allowed) {
|
|
801
|
+
return newWbContentCheck;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (nextConfigKind === 'workbook' && nextConfig) {
|
|
805
|
+
const newWbConfigCheck = validateNewLocksOnEmptyContent(nextConfig, actorUserId, isOwner, options?.preParsedWorkbooks);
|
|
806
|
+
if (newWbConfigCheck && !newWbConfigCheck.Allowed) {
|
|
807
|
+
return newWbConfigCheck;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// Also independently guard Content vs Content and Configuration vs Configuration so
|
|
812
|
+
// tampering either field (even when the other already parses) cannot smuggle edits (`B3`).
|
|
813
|
+
if ((currentContentKind === 'workbook' || isXlsxBinaryTextPayload(currentContent)) &&
|
|
814
|
+
(nextContentKind === 'workbook' || isXlsxBinaryTextPayload(nextContent)) &&
|
|
815
|
+
currentContent !== nextContent) {
|
|
816
|
+
const contentRes = validateWorkbookLockTransition(parseWorkbookWithCache(currentContent, null, options?.preParsedWorkbooks), parseWorkbookWithCache(nextContent, null, options?.preParsedWorkbooks), actorUserId, isOwner);
|
|
817
|
+
if (!contentRes.Allowed) {
|
|
818
|
+
return contentRes;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (currentConfigKind === 'workbook' && nextConfigKind === 'workbook' && currentConfig !== nextConfig) {
|
|
822
|
+
const configRes = validateWorkbookLockTransition(parseWorkbookWithCache(null, currentConfig, options?.preParsedWorkbooks), parseWorkbookWithCache(null, nextConfig, options?.preParsedWorkbooks), actorUserId, isOwner);
|
|
823
|
+
if (!configRes.Allowed) {
|
|
824
|
+
return configRes;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
catch (err) {
|
|
829
|
+
const msg = err instanceof Error ? err.message : '';
|
|
830
|
+
if (msg.startsWith('Spreadsheet ')) {
|
|
831
|
+
return { Allowed: false, Reason: msg };
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
Allowed: false,
|
|
835
|
+
Reason: 'Write rejected: malformed update to structured workbook with protected ranges.'
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
const docCheck = DocumentLiveBlockEngine.Instance.ValidateDocumentEditAgainstLocks(currentContent, nextContent, actorUserId, effectiveOwnerId, true);
|
|
840
|
+
if (!docCheck.Allowed) {
|
|
841
|
+
return { Allowed: false, Reason: docCheck.ViolationReason };
|
|
842
|
+
}
|
|
843
|
+
if (!isOwner) {
|
|
844
|
+
const prevLocks = DocumentLiveBlockEngine.Instance.ParseDocumentLocks(currentContent);
|
|
845
|
+
const nextLocks = DocumentLiveBlockEngine.Instance.ParseDocumentLocks(nextContent);
|
|
846
|
+
if (nextLocks.length > prevLocks.length) {
|
|
847
|
+
const prevKeys = prevLocks.map((l) => `${l.Kind}|${l.Scope}|${l.LockedByUserID ? NormalizeUUID(l.LockedByUserID) : ''}|${l.Label}`);
|
|
848
|
+
for (const nl of nextLocks) {
|
|
849
|
+
const nlKey = `${nl.Kind}|${nl.Scope}|${nl.LockedByUserID ? NormalizeUUID(nl.LockedByUserID) : ''}|${nl.Label}`;
|
|
850
|
+
const existingIdx = prevKeys.indexOf(nlKey);
|
|
851
|
+
if (existingIdx >= 0) {
|
|
852
|
+
prevKeys.splice(existingIdx, 1);
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
const lockedByNorm = nl.LockedByUserID ? NormalizeUUID(nl.LockedByUserID) : '';
|
|
856
|
+
if (nl.Scope === 'owner-only' || !normActor || lockedByNorm !== normActor) {
|
|
857
|
+
return {
|
|
858
|
+
Allowed: false,
|
|
859
|
+
Reason: `Cannot add document lock '${nl.Label}' without owner permission.`
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return { Allowed: true };
|
|
866
|
+
}
|
|
867
|
+
//# sourceMappingURL=ArtifactLockValidation.js.map
|