@embedpdf/engine-core 3.0.0-next.12 → 3.0.0-next.14

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 (64) hide show
  1. package/dist/{AbortError-8-9JAX1Y.js → AbortError-DwuHPK_I.js} +2 -2
  2. package/dist/{AbortError-8-9JAX1Y.js.map → AbortError-DwuHPK_I.js.map} +1 -1
  3. package/dist/{AbortError-CRSooKsk.cjs → AbortError-P0RU0Mgg.cjs} +4 -4
  4. package/dist/{AbortError-CRSooKsk.cjs.map → AbortError-P0RU0Mgg.cjs.map} +1 -1
  5. package/dist/{AnnotationListSnapshot-x6tKulNV.d.cts → AnnotationListSnapshot-D9R5n2Kf.d.cts} +1390 -176
  6. package/dist/{AnnotationListSnapshot-x6tKulNV.d.ts → AnnotationListSnapshot-D9R5n2Kf.d.ts} +1390 -176
  7. package/dist/{DocumentSecurityService-CK0pejAK.d.cts → DocumentSecurityService-CIx1MT0T.d.cts} +2 -2
  8. package/dist/{DocumentSecurityService-9MawYxP-.d.ts → DocumentSecurityService-Ca6EK3-3.d.ts} +2 -2
  9. package/dist/{Engine--0XF0UAK.d.cts → Engine-EWWHhEIi.d.ts} +179 -11
  10. package/dist/{Engine-Ds0ytbl6.d.ts → Engine-FNaAEjfb.d.cts} +179 -11
  11. package/dist/conformance.cjs +1441 -88
  12. package/dist/conformance.cjs.map +1 -1
  13. package/dist/conformance.d.cts +74 -3
  14. package/dist/conformance.d.ts +74 -3
  15. package/dist/conformance.js +1376 -25
  16. package/dist/conformance.js.map +1 -1
  17. package/dist/derive-BbsDk_Kz.cjs +880 -0
  18. package/dist/derive-BbsDk_Kz.cjs.map +1 -0
  19. package/dist/derive-DAFJolWu.js +647 -0
  20. package/dist/derive-DAFJolWu.js.map +1 -0
  21. package/dist/{PageInsertBlankInput-WKY0tr6S.js → format-Bbphf4zR.js} +95 -3
  22. package/dist/format-Bbphf4zR.js.map +1 -0
  23. package/dist/{PageInsertBlankInput-CzShuSJI.cjs → format-D_epWlob.cjs} +106 -2
  24. package/dist/format-D_epWlob.cjs.map +1 -0
  25. package/dist/index.cjs +137 -88
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +5 -5
  29. package/dist/{resolver-D-jumvgM.cjs → resolver-CYVNV4hn.cjs} +216 -10
  30. package/dist/resolver-CYVNV4hn.cjs.map +1 -0
  31. package/dist/{resolver-CHG4waXL.js → resolver-inAVzsWt.js} +157 -11
  32. package/dist/resolver-inAVzsWt.js.map +1 -0
  33. package/dist/runtime.cjs +147 -98
  34. package/dist/runtime.cjs.map +1 -1
  35. package/dist/runtime.d.cts +216 -5
  36. package/dist/runtime.d.ts +216 -5
  37. package/dist/runtime.js +6 -6
  38. package/dist/{schemas-DOyVEPk7.js → schemas-CFQGvWiu.js} +551 -5
  39. package/dist/schemas-CFQGvWiu.js.map +1 -0
  40. package/dist/{schemas-RChsAMWw.cjs → schemas-D0g6tKa9.cjs} +829 -25
  41. package/dist/schemas-D0g6tKa9.cjs.map +1 -0
  42. package/dist/{builders-8Hl1AYNU.cjs → viewport-BWeNHZmb.cjs} +1522 -117
  43. package/dist/viewport-BWeNHZmb.cjs.map +1 -0
  44. package/dist/{builders-DOjcKDWQ.js → viewport-CvMcadfQ.js} +1386 -89
  45. package/dist/viewport-CvMcadfQ.js.map +1 -0
  46. package/dist/wire.cjs +252 -13
  47. package/dist/wire.cjs.map +1 -1
  48. package/dist/wire.d.cts +3147 -5
  49. package/dist/wire.d.ts +3147 -5
  50. package/dist/wire.js +207 -14
  51. package/dist/wire.js.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/PageInsertBlankInput-CzShuSJI.cjs.map +0 -1
  54. package/dist/PageInsertBlankInput-WKY0tr6S.js.map +0 -1
  55. package/dist/builders-8Hl1AYNU.cjs.map +0 -1
  56. package/dist/builders-DOjcKDWQ.js.map +0 -1
  57. package/dist/fold-BfyxxwS6.js +0 -334
  58. package/dist/fold-BfyxxwS6.js.map +0 -1
  59. package/dist/fold-C7I5GpBz.cjs +0 -447
  60. package/dist/fold-C7I5GpBz.cjs.map +0 -1
  61. package/dist/resolver-CHG4waXL.js.map +0 -1
  62. package/dist/resolver-D-jumvgM.cjs.map +0 -1
  63. package/dist/schemas-DOyVEPk7.js.map +0 -1
  64. package/dist/schemas-RChsAMWw.cjs.map +0 -1
@@ -1,447 +0,0 @@
1
- const require_PageInsertBlankInput = require("./PageInsertBlankInput-CzShuSJI.cjs");
2
- //#region src/geometry/convert.ts
3
- /**
4
- * Normalize a `PdfRect` to the y-up invariant (`left <= right`, `bottom <= top`),
5
- * regardless of how the PDF ordered the corners (a `/Rect` array or `FS_RECTF`
6
- * may carry them in any order). THE enforcement point for the "PdfRect is always
7
- * normalized" rule: every producer that reads a raw box from PDFium passes it
8
- * through here, so the invariant holds once, centrally — downstream `width =
9
- * right - left` is never negative.
10
- */
11
- function normalizePdfRect(r) {
12
- return {
13
- left: Math.min(r.left, r.right),
14
- right: Math.max(r.left, r.right),
15
- bottom: Math.min(r.top, r.bottom),
16
- top: Math.max(r.top, r.bottom)
17
- };
18
- }
19
- function pdfRectWidth(r) {
20
- return r.right - r.left;
21
- }
22
- function pdfRectHeight(r) {
23
- return r.top - r.bottom;
24
- }
25
- function pdfRectSize(r) {
26
- return {
27
- width: r.right - r.left,
28
- height: r.top - r.bottom
29
- };
30
- }
31
- /** Convert edges -> origin+size, staying y-up (origin at bottom-left). */
32
- function pdfRectToOriginSize(r) {
33
- return {
34
- x: r.left,
35
- y: r.bottom,
36
- width: r.right - r.left,
37
- height: r.top - r.bottom
38
- };
39
- }
40
- /** Convert y-up origin+size back to edges. */
41
- function pdfRectFromOriginSize(o) {
42
- return {
43
- left: o.x,
44
- bottom: o.y,
45
- right: o.x + o.width,
46
- top: o.y + o.height
47
- };
48
- }
49
- /**
50
- * Enclosing axis-aligned box of a quad, in PDF user space. Orientation
51
- * agnostic (correct for rotated/skewed quads) — this is what highlight
52
- * rendering and hit-testing want.
53
- */
54
- function pdfQuadBounds(q) {
55
- const xs = [
56
- q.p1.x,
57
- q.p2.x,
58
- q.p3.x,
59
- q.p4.x
60
- ];
61
- const ys = [
62
- q.p1.y,
63
- q.p2.y,
64
- q.p3.y,
65
- q.p4.y
66
- ];
67
- return {
68
- left: Math.min(...xs),
69
- right: Math.max(...xs),
70
- bottom: Math.min(...ys),
71
- top: Math.max(...ys)
72
- };
73
- }
74
- /**
75
- * Axis-aligned named-corner interpretation of a quad.
76
- *
77
- * VALID ONLY for upright (non-rotated, non-skewed) quads: it is derived from
78
- * the enclosing bounds, so for rotated/skewed quads it returns the bounding
79
- * box corners, not the true geometric corners. For arbitrary quads use the
80
- * positional `p1..p4` or `pdfQuadBounds` directly.
81
- */
82
- function pdfQuadCorners(q) {
83
- const b = pdfQuadBounds(q);
84
- return {
85
- topLeft: {
86
- x: b.left,
87
- y: b.top
88
- },
89
- topRight: {
90
- x: b.right,
91
- y: b.top
92
- },
93
- bottomLeft: {
94
- x: b.left,
95
- y: b.bottom
96
- },
97
- bottomRight: {
98
- x: b.right,
99
- y: b.bottom
100
- }
101
- };
102
- }
103
- /**
104
- * Build a quad from named corners, in PDFium `FS_QUADPOINTSF` slot order
105
- * (`p1 = topLeft`, `p2 = topRight`, `p3 = bottomLeft`, `p4 = bottomRight`).
106
- * The inverse of `pdfQuadCorners` for upright quads.
107
- */
108
- function pdfQuadFromCorners(c) {
109
- return {
110
- p1: c.topLeft,
111
- p2: c.topRight,
112
- p3: c.bottomLeft,
113
- p4: c.bottomRight
114
- };
115
- }
116
- //#endregion
117
- //#region src/dto/PageGeometrySnapshot.ts
118
- /** Narrowing guard: is this run the rotated (non-upright) variant? */
119
- function isRotatedGeometryRun(run) {
120
- return "rotation" in run;
121
- }
122
- /**
123
- * Uniform oriented-cell view over either run variant: the glyph's loose cell
124
- * as a quad (synthesized from the box corners when the run is upright, in
125
- * the same frame-geometric slot order).
126
- */
127
- function glyphLooseQuad(run, index) {
128
- if (isRotatedGeometryRun(run)) return run.glyphs[index].looseQuad;
129
- const b = run.glyphs[index].looseBox;
130
- return {
131
- p1: {
132
- x: b.left,
133
- y: b.top
134
- },
135
- p2: {
136
- x: b.right,
137
- y: b.top
138
- },
139
- p3: {
140
- x: b.left,
141
- y: b.bottom
142
- },
143
- p4: {
144
- x: b.right,
145
- y: b.bottom
146
- }
147
- };
148
- }
149
- /**
150
- * Uniform AABB view over either run variant: the glyph's loose box, or the
151
- * enclosing bounds of its oriented cell when the run is rotated. The
152
- * conservative envelope for consumers that genuinely want a box (culling,
153
- * scroll targets) — never a substitute for handling orientation in geometry
154
- * that gets DRAWN.
155
- */
156
- function glyphLooseBounds(run, index) {
157
- if (isRotatedGeometryRun(run)) return pdfQuadBounds(run.glyphs[index].looseQuad);
158
- return run.glyphs[index].looseBox;
159
- }
160
- //#endregion
161
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
162
- function _typeof(o) {
163
- "@babel/helpers - typeof";
164
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
165
- return typeof o;
166
- } : function(o) {
167
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
168
- }, _typeof(o);
169
- }
170
- //#endregion
171
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
172
- function toPrimitive(t, r) {
173
- if ("object" != _typeof(t) || !t) return t;
174
- var e = t[Symbol.toPrimitive];
175
- if (void 0 !== e) {
176
- var i = e.call(t, r || "default");
177
- if ("object" != _typeof(i)) return i;
178
- throw new TypeError("@@toPrimitive must return a primitive value.");
179
- }
180
- return ("string" === r ? String : Number)(t);
181
- }
182
- //#endregion
183
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
184
- function toPropertyKey(t) {
185
- var i = toPrimitive(t, "string");
186
- return "symbol" == _typeof(i) ? i : i + "";
187
- }
188
- //#endregion
189
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
190
- function _defineProperty(e, r, t) {
191
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
192
- value: t,
193
- enumerable: !0,
194
- configurable: !0,
195
- writable: !0
196
- }) : e[r] = t, e;
197
- }
198
- //#endregion
199
- //#region src/errors/EngineError.ts
200
- /**
201
- * Single error class shared across engine implementations. Has a stable
202
- * machine-readable `code` (see EngineErrorCode) so callers can match without
203
- * sniffing message strings.
204
- */
205
- var EngineError = class EngineError extends Error {
206
- constructor(code, message, opts = {}) {
207
- super(message ?? code, opts.cause === void 0 ? void 0 : { cause: opts.cause });
208
- _defineProperty(this, "name", "EngineError");
209
- _defineProperty(this, "code", void 0);
210
- _defineProperty(this, "details", void 0);
211
- this.code = code;
212
- this.details = opts.details;
213
- }
214
- static is(value, code) {
215
- if (!(value instanceof EngineError) && value?.name !== "EngineError") return false;
216
- if (code === void 0) return true;
217
- return value.code === code;
218
- }
219
- toJSON() {
220
- return {
221
- name: "EngineError",
222
- code: this.code,
223
- message: this.message,
224
- details: this.details
225
- };
226
- }
227
- };
228
- function serializeError(err) {
229
- if (EngineError.is(err)) return err.toJSON();
230
- if (err instanceof Error) return {
231
- name: "EngineError",
232
- code: err.name === "AbortError" ? require_PageInsertBlankInput.EngineErrorCode.Aborted : require_PageInsertBlankInput.EngineErrorCode.Unknown,
233
- message: err.message
234
- };
235
- return {
236
- name: "EngineError",
237
- code: require_PageInsertBlankInput.EngineErrorCode.Unknown,
238
- message: String(err ?? "unknown error")
239
- };
240
- }
241
- function deserializeError(payload) {
242
- return new EngineError(payload.code, payload.message, { details: payload.details });
243
- }
244
- //#endregion
245
- //#region src/search/fold.ts
246
- /**
247
- * Text folding for literal search: the deterministic normalization applied
248
- * to BOTH the page text and the needle so that "Café" finds "cafe" and a
249
- * line-wrapped "hello\n world" finds "hello world".
250
- *
251
- * Fold version 1:
252
- * - whitespace runs collapse to a single space (any `\s`, including the
253
- * spaces some compatibility decompositions emit),
254
- * - each code point is NFKD-decomposed (ligatures split: "fi" → "fi",
255
- * "²" → "2"),
256
- * - combining marks are stripped unless `keepMarks`,
257
- * - case is folded via upper→lower round-trip unless `keepCase` (this
258
- * poor-man's full fold catches "ß"→"ss" and "ς"→"σ", which a plain
259
- * `toLowerCase` misses).
260
- *
261
- * Every folded code unit remembers which original code point produced it
262
- * (`map`), so match ranges found in folded space translate back to exact
263
- * original-text ranges — the property the whole anchor stage rests on.
264
- *
265
- * Pre-folded corpus artifacts store this fold's output; bump
266
- * `SEARCH_FOLD_VERSION` on ANY semantic change so stored corpora are
267
- * rebuilt instead of silently mismatching fresh needles.
268
- */
269
- /** Version stamp for persisted pre-folded corpus artifacts. */
270
- const SEARCH_FOLD_VERSION = 1;
271
- const WHITESPACE = /\s/;
272
- const MARKS = /\p{M}/gu;
273
- function foldText(original, options = {}) {
274
- const units = [];
275
- const map = [];
276
- let lastWasSpace = false;
277
- let index = 0;
278
- for (const cp of original) {
279
- let piece;
280
- if (WHITESPACE.test(cp)) piece = " ";
281
- else {
282
- piece = cp.normalize("NFKD");
283
- if (!options.keepMarks) piece = piece.replace(MARKS, "");
284
- if (!options.keepCase) piece = piece.toUpperCase().toLowerCase();
285
- }
286
- for (let u = 0; u < piece.length; u++) {
287
- const unit = piece[u];
288
- if (WHITESPACE.test(unit)) {
289
- if (lastWasSpace) continue;
290
- units.push(" ");
291
- map.push(index);
292
- lastWasSpace = true;
293
- } else {
294
- units.push(unit);
295
- map.push(index);
296
- lastWasSpace = false;
297
- }
298
- }
299
- index += cp.length;
300
- }
301
- return {
302
- folded: units.join(""),
303
- map: Uint32Array.from(map),
304
- original
305
- };
306
- }
307
- /** Code-unit length of the code point starting at `index` (1 or 2). */
308
- function codePointLengthAt(text, index) {
309
- const unit = text.charCodeAt(index);
310
- if (unit >= 55296 && unit <= 56319 && index + 1 < text.length) {
311
- const next = text.charCodeAt(index + 1);
312
- if (next >= 56320 && next <= 57343) return 2;
313
- }
314
- return 1;
315
- }
316
- /**
317
- * Translate a match found in folded space back to the original text.
318
- * The range covers whole original code points: a hit on either folded
319
- * half of "fi" spans the full ligature, and a hit ending on a collapsed
320
- * space extends only through the first whitespace char of the run (the
321
- * remainder is presentation, not match).
322
- */
323
- function toOriginalRange(folded, foldedStart, foldedLength) {
324
- const start = folded.map[foldedStart];
325
- const lastOriginal = folded.map[foldedStart + foldedLength - 1];
326
- return {
327
- start,
328
- length: lastOriginal + codePointLengthAt(folded.original, lastOriginal) - start
329
- };
330
- }
331
- //#endregion
332
- Object.defineProperty(exports, "EngineError", {
333
- enumerable: true,
334
- get: function() {
335
- return EngineError;
336
- }
337
- });
338
- Object.defineProperty(exports, "SEARCH_FOLD_VERSION", {
339
- enumerable: true,
340
- get: function() {
341
- return SEARCH_FOLD_VERSION;
342
- }
343
- });
344
- Object.defineProperty(exports, "_defineProperty", {
345
- enumerable: true,
346
- get: function() {
347
- return _defineProperty;
348
- }
349
- });
350
- Object.defineProperty(exports, "deserializeError", {
351
- enumerable: true,
352
- get: function() {
353
- return deserializeError;
354
- }
355
- });
356
- Object.defineProperty(exports, "foldText", {
357
- enumerable: true,
358
- get: function() {
359
- return foldText;
360
- }
361
- });
362
- Object.defineProperty(exports, "glyphLooseBounds", {
363
- enumerable: true,
364
- get: function() {
365
- return glyphLooseBounds;
366
- }
367
- });
368
- Object.defineProperty(exports, "glyphLooseQuad", {
369
- enumerable: true,
370
- get: function() {
371
- return glyphLooseQuad;
372
- }
373
- });
374
- Object.defineProperty(exports, "isRotatedGeometryRun", {
375
- enumerable: true,
376
- get: function() {
377
- return isRotatedGeometryRun;
378
- }
379
- });
380
- Object.defineProperty(exports, "normalizePdfRect", {
381
- enumerable: true,
382
- get: function() {
383
- return normalizePdfRect;
384
- }
385
- });
386
- Object.defineProperty(exports, "pdfQuadBounds", {
387
- enumerable: true,
388
- get: function() {
389
- return pdfQuadBounds;
390
- }
391
- });
392
- Object.defineProperty(exports, "pdfQuadCorners", {
393
- enumerable: true,
394
- get: function() {
395
- return pdfQuadCorners;
396
- }
397
- });
398
- Object.defineProperty(exports, "pdfQuadFromCorners", {
399
- enumerable: true,
400
- get: function() {
401
- return pdfQuadFromCorners;
402
- }
403
- });
404
- Object.defineProperty(exports, "pdfRectFromOriginSize", {
405
- enumerable: true,
406
- get: function() {
407
- return pdfRectFromOriginSize;
408
- }
409
- });
410
- Object.defineProperty(exports, "pdfRectHeight", {
411
- enumerable: true,
412
- get: function() {
413
- return pdfRectHeight;
414
- }
415
- });
416
- Object.defineProperty(exports, "pdfRectSize", {
417
- enumerable: true,
418
- get: function() {
419
- return pdfRectSize;
420
- }
421
- });
422
- Object.defineProperty(exports, "pdfRectToOriginSize", {
423
- enumerable: true,
424
- get: function() {
425
- return pdfRectToOriginSize;
426
- }
427
- });
428
- Object.defineProperty(exports, "pdfRectWidth", {
429
- enumerable: true,
430
- get: function() {
431
- return pdfRectWidth;
432
- }
433
- });
434
- Object.defineProperty(exports, "serializeError", {
435
- enumerable: true,
436
- get: function() {
437
- return serializeError;
438
- }
439
- });
440
- Object.defineProperty(exports, "toOriginalRange", {
441
- enumerable: true,
442
- get: function() {
443
- return toOriginalRange;
444
- }
445
- });
446
-
447
- //# sourceMappingURL=fold-C7I5GpBz.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fold-C7I5GpBz.cjs","names":["EngineErrorCode"],"sources":["../src/geometry/convert.ts","../src/dto/PageGeometrySnapshot.ts","../src/errors/EngineError.ts","../src/search/fold.ts"],"sourcesContent":["/**\n * PDF-space-internal geometry helpers.\n *\n * These operate ENTIRELY within PDF user space (y-up, edges). They never\n * produce viewer-local (y-down) geometry — that conversion needs the crop box\n * plus rotation/scale and lives in the v3 viewer layer (the `Mat2D` matrix\n * model), never here.\n */\n\nimport type { PdfPoint, PdfQuad, PdfRect, PdfSize } from './primitives';\n\n/** Origin + size form of a `PdfRect`, still y-up (origin = bottom-left). */\nexport interface PdfOriginSize {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Normalize a `PdfRect` to the y-up invariant (`left <= right`, `bottom <= top`),\n * regardless of how the PDF ordered the corners (a `/Rect` array or `FS_RECTF`\n * may carry them in any order). THE enforcement point for the \"PdfRect is always\n * normalized\" rule: every producer that reads a raw box from PDFium passes it\n * through here, so the invariant holds once, centrally — downstream `width =\n * right - left` is never negative.\n */\nexport function normalizePdfRect(r: PdfRect): PdfRect {\n return {\n left: Math.min(r.left, r.right),\n right: Math.max(r.left, r.right),\n bottom: Math.min(r.top, r.bottom),\n top: Math.max(r.top, r.bottom),\n };\n}\n\nexport function pdfRectWidth(r: PdfRect): number {\n return r.right - r.left;\n}\n\nexport function pdfRectHeight(r: PdfRect): number {\n return r.top - r.bottom;\n}\n\nexport function pdfRectSize(r: PdfRect): PdfSize {\n return { width: r.right - r.left, height: r.top - r.bottom };\n}\n\n/** Convert edges -> origin+size, staying y-up (origin at bottom-left). */\nexport function pdfRectToOriginSize(r: PdfRect): PdfOriginSize {\n return { x: r.left, y: r.bottom, width: r.right - r.left, height: r.top - r.bottom };\n}\n\n/** Convert y-up origin+size back to edges. */\nexport function pdfRectFromOriginSize(o: PdfOriginSize): PdfRect {\n return { left: o.x, bottom: o.y, right: o.x + o.width, top: o.y + o.height };\n}\n\n/**\n * Enclosing axis-aligned box of a quad, in PDF user space. Orientation\n * agnostic (correct for rotated/skewed quads) — this is what highlight\n * rendering and hit-testing want.\n */\nexport function pdfQuadBounds(q: PdfQuad): PdfRect {\n const xs = [q.p1.x, q.p2.x, q.p3.x, q.p4.x];\n const ys = [q.p1.y, q.p2.y, q.p3.y, q.p4.y];\n return {\n left: Math.min(...xs),\n right: Math.max(...xs),\n bottom: Math.min(...ys),\n top: Math.max(...ys),\n };\n}\n\n/** Named corners of a quad, in PDF user space (y-up). */\nexport interface PdfQuadCorners {\n topLeft: PdfPoint;\n topRight: PdfPoint;\n bottomLeft: PdfPoint;\n bottomRight: PdfPoint;\n}\n\n/**\n * Axis-aligned named-corner interpretation of a quad.\n *\n * VALID ONLY for upright (non-rotated, non-skewed) quads: it is derived from\n * the enclosing bounds, so for rotated/skewed quads it returns the bounding\n * box corners, not the true geometric corners. For arbitrary quads use the\n * positional `p1..p4` or `pdfQuadBounds` directly.\n */\nexport function pdfQuadCorners(q: PdfQuad): PdfQuadCorners {\n const b = pdfQuadBounds(q);\n return {\n topLeft: { x: b.left, y: b.top },\n topRight: { x: b.right, y: b.top },\n bottomLeft: { x: b.left, y: b.bottom },\n bottomRight: { x: b.right, y: b.bottom },\n };\n}\n\n/**\n * Build a quad from named corners, in PDFium `FS_QUADPOINTSF` slot order\n * (`p1 = topLeft`, `p2 = topRight`, `p3 = bottomLeft`, `p4 = bottomRight`).\n * The inverse of `pdfQuadCorners` for upright quads.\n */\nexport function pdfQuadFromCorners(c: PdfQuadCorners): PdfQuad {\n return { p1: c.topLeft, p2: c.topRight, p3: c.bottomLeft, p4: c.bottomRight };\n}\n","import { pdfQuadBounds } from '../geometry/convert';\nimport type { PdfQuad, PdfRect } from '../geometry/primitives';\n\n/**\n * One upright glyph's geometry in PDF user space (y-up edges).\n *\n * `looseBox` is the loose char cell (pdfium `FPDFText_GetLooseCharBox`): the\n * font-metric box covering the full glyph cell without regard to the actual\n * glyph shape. Always present (zeroed + flagged empty for degenerate glyphs);\n * it's the box selection envelopes are built from.\n *\n * `tightBox` is the tight char box (pdfium `FPDFText_GetCharBox`): the box\n * hugging the actual glyph shape. Optional — absent for empty/whitespace\n * glyphs that have no real outline.\n *\n * `flags` carries slim per-glyph state (bit 1 = space, bit 2 = empty).\n */\nexport interface PageGeometryGlyph {\n looseBox: PdfRect;\n flags: number;\n tightBox?: PdfRect;\n}\n\n/**\n * One non-upright glyph's geometry: the exact oriented cells, in PDF user\n * space (page coordinates — NOT a local frame). The corner SLOTS are\n * frame-geometric in the glyph's own upright frame:\n * `p1` = upper-start, `p2` = upper-end, `p3` = lower-start, `p4` = lower-end,\n * where \"upper\" is the ascent side and \"start\" is the frame's minimum-x side.\n * Deliberately NOT a bidi/reading-order statement — advance direction is a\n * glyph-sequence concern, carried separately where consumers need it.\n *\n * Degenerate glyphs carry a zeroed `looseQuad` plus the empty flag (bit 2),\n * mirroring the upright variant's zeroed-box convention. `flags` bits match\n * {@link PageGeometryGlyph.flags}.\n */\nexport interface RotatedGeometryGlyph {\n looseQuad: PdfQuad;\n flags: number;\n tightQuad?: PdfQuad;\n}\n\n/**\n * A run whose char matrix is upright — byte-identical to the wire shape that\n * predates orientation support, so upright documents never pay for it.\n */\nexport interface UprightGeometryRun {\n rect: PdfRect;\n charStart: number;\n glyphs: PageGeometryGlyph[];\n fontSize?: number;\n}\n\n/**\n * A run whose char matrix is NOT upright (rotated, sheared, or mirrored).\n *\n * `rect` stays a page-space AABB (culling), like every other wire rect.\n * `rotation` is the baseline angle in radians, CCW in PDF y-up space\n * (`atan2(m.b, m.a)` of the run's char matrix). Note a shear-only run has\n * `rotation === 0` and still uses this variant — its cells are\n * parallelograms an AABB would misrepresent. `ascentFlip` is true when the\n * ascent vector maps opposite the rotated frame's +y (mirrored /\n * negative-determinant content).\n */\nexport interface RotatedGeometryRun {\n rect: PdfRect;\n charStart: number;\n glyphs: RotatedGeometryGlyph[];\n rotation: number;\n ascentFlip: boolean;\n fontSize?: number;\n}\n\n/**\n * One text run (contiguous glyphs sharing a text object and orientation).\n * A discriminated union so consumers CANNOT read axis-aligned boxes off\n * rotated text by accident — handling orientation is a compile-time\n * obligation, not a runtime discovery. Narrow with\n * {@link isRotatedGeometryRun}, or use the uniform {@link glyphLooseQuad} /\n * {@link glyphLooseBounds} views.\n */\nexport type PageGeometryRun = UprightGeometryRun | RotatedGeometryRun;\n\n/**\n * Geometry-only text layout for one page, in PDF user space (y-up). The v3\n * viewer converts to content/view space via the page geometry matrix.\n *\n * Pure content, addressed and cached by `contentVersion`. Carries NO\n * annotation liveness envelope (`PageState`) — see `PageTextSnapshot` for\n * the rationale; liveness lives on annotation reads.\n */\nexport interface PageGeometrySnapshot {\n runs: PageGeometryRun[];\n}\n\n/** Narrowing guard: is this run the rotated (non-upright) variant? */\nexport function isRotatedGeometryRun(run: PageGeometryRun): run is RotatedGeometryRun {\n return 'rotation' in run;\n}\n\n/**\n * Uniform oriented-cell view over either run variant: the glyph's loose cell\n * as a quad (synthesized from the box corners when the run is upright, in\n * the same frame-geometric slot order).\n */\nexport function glyphLooseQuad(run: PageGeometryRun, index: number): PdfQuad {\n if (isRotatedGeometryRun(run)) return run.glyphs[index].looseQuad;\n const b = run.glyphs[index].looseBox;\n return {\n p1: { x: b.left, y: b.top },\n p2: { x: b.right, y: b.top },\n p3: { x: b.left, y: b.bottom },\n p4: { x: b.right, y: b.bottom },\n };\n}\n\n/**\n * Uniform AABB view over either run variant: the glyph's loose box, or the\n * enclosing bounds of its oriented cell when the run is rotated. The\n * conservative envelope for consumers that genuinely want a box (culling,\n * scroll targets) — never a substitute for handling orientation in geometry\n * that gets DRAWN.\n */\nexport function glyphLooseBounds(run: PageGeometryRun, index: number): PdfRect {\n if (isRotatedGeometryRun(run)) return pdfQuadBounds(run.glyphs[index].looseQuad);\n return run.glyphs[index].looseBox;\n}\n","import { EngineErrorCode } from './EngineErrorCode';\n\nexport interface EngineErrorOptions {\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\n/**\n * Single error class shared across engine implementations. Has a stable\n * machine-readable `code` (see EngineErrorCode) so callers can match without\n * sniffing message strings.\n */\nexport class EngineError extends Error {\n override readonly name = 'EngineError';\n readonly code: EngineErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(code: EngineErrorCode, message?: string, opts: EngineErrorOptions = {}) {\n super(message ?? code, opts.cause === undefined ? undefined : { cause: opts.cause });\n this.code = code;\n this.details = opts.details;\n }\n\n static is(value: unknown, code?: EngineErrorCode): value is EngineError {\n if (\n !(value instanceof EngineError) &&\n (value as { name?: string } | null)?.name !== 'EngineError'\n ) {\n return false;\n }\n if (code === undefined) return true;\n return (value as EngineError).code === code;\n }\n\n toJSON(): {\n name: 'EngineError';\n code: EngineErrorCode;\n message: string;\n details?: Record<string, unknown>;\n } {\n return {\n name: 'EngineError',\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n\nexport interface SerializedEngineError {\n name: 'EngineError';\n code: EngineErrorCode;\n message: string;\n details?: Record<string, unknown>;\n}\n\nexport function serializeError(err: unknown): SerializedEngineError {\n if (EngineError.is(err)) {\n return err.toJSON();\n }\n if (err instanceof Error) {\n const code: EngineErrorCode =\n err.name === 'AbortError' ? EngineErrorCode.Aborted : EngineErrorCode.Unknown;\n return { name: 'EngineError', code, message: err.message };\n }\n return {\n name: 'EngineError',\n code: EngineErrorCode.Unknown,\n message: String(err ?? 'unknown error'),\n };\n}\n\nexport function deserializeError(payload: SerializedEngineError): EngineError {\n return new EngineError(payload.code, payload.message, { details: payload.details });\n}\n","/**\n * Text folding for literal search: the deterministic normalization applied\n * to BOTH the page text and the needle so that \"Café\" finds \"cafe\" and a\n * line-wrapped \"hello\\n world\" finds \"hello world\".\n *\n * Fold version 1:\n * - whitespace runs collapse to a single space (any `\\s`, including the\n * spaces some compatibility decompositions emit),\n * - each code point is NFKD-decomposed (ligatures split: \"fi\" → \"fi\",\n * \"²\" → \"2\"),\n * - combining marks are stripped unless `keepMarks`,\n * - case is folded via upper→lower round-trip unless `keepCase` (this\n * poor-man's full fold catches \"ß\"→\"ss\" and \"ς\"→\"σ\", which a plain\n * `toLowerCase` misses).\n *\n * Every folded code unit remembers which original code point produced it\n * (`map`), so match ranges found in folded space translate back to exact\n * original-text ranges — the property the whole anchor stage rests on.\n *\n * Pre-folded corpus artifacts store this fold's output; bump\n * `SEARCH_FOLD_VERSION` on ANY semantic change so stored corpora are\n * rebuilt instead of silently mismatching fresh needles.\n */\n\n/** Version stamp for persisted pre-folded corpus artifacts. */\nexport const SEARCH_FOLD_VERSION = 1;\n\nexport interface FoldOptions {\n /** Preserve case (matchCase). */\n keepCase?: boolean;\n /** Preserve combining marks (matchDiacritics). */\n keepMarks?: boolean;\n}\n\nexport interface FoldedText {\n folded: string;\n /** Folded code unit i → code-unit index of the original code point it came from. */\n map: Uint32Array;\n original: string;\n}\n\n/** A half-open match range in ORIGINAL code-unit space. */\nexport interface SearchMatchRange {\n start: number;\n length: number;\n}\n\nconst WHITESPACE = /\\s/;\nconst MARKS = /\\p{M}/gu;\n\nexport function foldText(original: string, options: FoldOptions = {}): FoldedText {\n const units: string[] = [];\n const map: number[] = [];\n let lastWasSpace = false;\n\n let index = 0;\n for (const cp of original) {\n let piece: string;\n if (WHITESPACE.test(cp)) {\n piece = ' ';\n } else {\n piece = cp.normalize('NFKD');\n if (!options.keepMarks) piece = piece.replace(MARKS, '');\n if (!options.keepCase) piece = piece.toUpperCase().toLowerCase();\n }\n // A decomposition can itself contain whitespace (U+00A8 → space +\n // combining diaeresis), so collapse runs at the unit level, not just\n // for source whitespace.\n for (let u = 0; u < piece.length; u++) {\n const unit = piece[u];\n if (WHITESPACE.test(unit)) {\n if (lastWasSpace) continue;\n units.push(' ');\n map.push(index);\n lastWasSpace = true;\n } else {\n units.push(unit);\n map.push(index);\n lastWasSpace = false;\n }\n }\n index += cp.length;\n }\n\n return { folded: units.join(''), map: Uint32Array.from(map), original };\n}\n\n/** Code-unit length of the code point starting at `index` (1 or 2). */\nfunction codePointLengthAt(text: string, index: number): number {\n const unit = text.charCodeAt(index);\n if (unit >= 0xd800 && unit <= 0xdbff && index + 1 < text.length) {\n const next = text.charCodeAt(index + 1);\n if (next >= 0xdc00 && next <= 0xdfff) return 2;\n }\n return 1;\n}\n\n/**\n * Translate a match found in folded space back to the original text.\n * The range covers whole original code points: a hit on either folded\n * half of \"fi\" spans the full ligature, and a hit ending on a collapsed\n * space extends only through the first whitespace char of the run (the\n * remainder is presentation, not match).\n */\nexport function toOriginalRange(\n folded: FoldedText,\n foldedStart: number,\n foldedLength: number,\n): SearchMatchRange {\n const start = folded.map[foldedStart];\n const lastOriginal = folded.map[foldedStart + foldedLength - 1];\n const end = lastOriginal + codePointLengthAt(folded.original, lastOriginal);\n return { start, length: end - start };\n}\n"],"mappings":";;;;;;;;;;AA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AAW,QAAQ,MAAM,QAAQ,OAAO,EAAE;GACvD,IAAI,CAAC,QAAQ,UAAU,QAAQ,MAAM,YAAY,CAAC,CAAC,YAAY;EACjE;EAIA,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;GACrC,MAAM,OAAO,MAAM;GACnB,IAAI,WAAW,KAAK,IAAI,GAAG;IACzB,IAAI,cAAc;IAClB,MAAM,KAAK,GAAG;IACd,IAAI,KAAK,KAAK;IACd,eAAe;GACjB,OAAO;IACL,MAAM,KAAK,IAAI;IACf,IAAI,KAAK,KAAK;IACd,eAAe;GACjB;EACF;EACA,SAAS,GAAG;CACd;CAEA,OAAO;EAAE,QAAQ,MAAM,KAAK,EAAE;EAAG,KAAK,YAAY,KAAK,GAAG;EAAG;CAAS;AACxE;;AAGA,SAAS,kBAAkB,MAAc,OAAuB;CAC9D,MAAM,OAAO,KAAK,WAAW,KAAK;CAClC,IAAI,QAAQ,SAAU,QAAQ,SAAU,QAAQ,IAAI,KAAK,QAAQ;EAC/D,MAAM,OAAO,KAAK,WAAW,QAAQ,CAAC;EACtC,IAAI,QAAQ,SAAU,QAAQ,OAAQ,OAAO;CAC/C;CACA,OAAO;AACT;;;;;;;;AASA,SAAgB,gBACd,QACA,aACA,cACkB;CAClB,MAAM,QAAQ,OAAO,IAAI;CACzB,MAAM,eAAe,OAAO,IAAI,cAAc,eAAe;CAE7D,OAAO;EAAE;EAAO,QADJ,eAAe,kBAAkB,OAAO,UAAU,YAAY,IAC5C;CAAM;AACtC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver-CHG4waXL.js","names":[],"sources":["../src/auth/scope/errors.ts","../src/auth/scope/parser.ts","../src/auth/scope/resolver.ts"],"sourcesContent":["/**\n * Thrown by {@link parseScope} / {@link validateScopeArray} when a scope\n * string does not match any known grammar (capability, collab, virtual,\n * or wildcard).\n *\n * Carries the offending scope verbatim so route/JWT-layer error\n * handlers can echo it to the customer.\n */\nexport class InvalidScope extends Error {\n constructor(\n public readonly scope: string,\n reason: string,\n ) {\n super(`invalid scope \"${scope}\": ${reason}`);\n this.name = 'InvalidScope';\n }\n}\n\n/**\n * Thrown by route guards and engine-local enforcement when a capability\n * or collab action is denied for the current request/handle.\n *\n * `required` names what the caller needed (e.g., \"doc.render\" or\n * \"annotations:update\"). `context` is an optional label such as \"local\"\n * or \"/v1/docs/.../pages/2/render\".\n */\nexport class PermissionDenied extends Error {\n constructor(\n public readonly required: string,\n public readonly context?: string,\n ) {\n super(`permission denied${context ? ` (${context})` : ''}: ${required}`);\n this.name = 'PermissionDenied';\n }\n}\n\n/**\n * Thrown at engine-local open time when the supplied scope includes\n * collab filters (`:self`, `:group=...`) but the identity claims needed\n * to resolve them are missing. Fails loudly at open so the configuration\n * mistake is visible immediately instead of producing silent denies at\n * every annotation mutation.\n */\nexport class MissingIdentity extends Error {\n constructor(scope: string) {\n super(`scope \"${scope}\" requires identity claims (user_id and/or groups)`);\n this.name = 'MissingIdentity';\n }\n}\n","import { InvalidScope } from './errors';\nimport type { CollabAction, CollabFilter, DocCapability, ParsedScope } from './types';\n\n/**\n * Closed set of recognized capability strings. Membership is the\n * authoritative source of truth — adding a new capability requires\n * extending the `DocCapability` union AND adding it here. The parser\n * rejects anything outside this set.\n *\n * Removed legacy names (e.g., `doc.read`, `doc.edit-pages`, `doc.save`)\n * are deliberately absent so any JWT carrying them fails at verify\n * time with a clear error.\n */\nconst KNOWN_CAPABILITIES: ReadonlySet<DocCapability> = new Set([\n 'doc.open',\n 'doc.render',\n 'doc.text.select',\n 'doc.text.copy',\n 'doc.text.search',\n 'doc.content.copy',\n 'doc.download',\n 'doc.download.flattened',\n 'doc.print',\n 'doc.print.high',\n 'doc.pages.modify',\n 'doc.pages.assemble',\n 'doc.forms.read',\n 'doc.forms.fill',\n 'doc.forms.modify',\n 'doc.forms.submit',\n 'doc.annotate.read',\n 'doc.annotate.modify',\n 'doc.metadata.modify',\n 'doc.attachments.modify',\n 'doc.redact',\n]);\n\n/**\n * Parse a single scope string into a structured `ParsedScope`.\n *\n * Recognised shapes:\n * - `\"*\"` → wildcard\n * - `\"pdf.permissions\"` → virtual (expands at resolve time)\n * - `\"a.b.c...\"` (dotted) → capability\n * - `\"entity:action:filter\"` (colons) → collab\n *\n * Throws {@link InvalidScope} for any string that fails to match one of\n * those shapes, or whose capability/entity/action/filter is not in the\n * closed enum.\n */\nexport function parseScope(raw: string): ParsedScope {\n if (raw === '*') return { kind: 'wildcard' };\n if (raw === 'pdf.permissions') return { kind: 'virtual', name: 'pdf.permissions' };\n if (raw.includes(':')) return parseCollab(raw);\n return parseCapability(raw);\n}\n\n/**\n * Validate every entry in a scope array by attempting to parse it.\n * Throws on the first invalid string. Discards the parse output —\n * callers re-parse at resolution time to keep the array as the\n * authoritative payload.\n */\nexport function validateScopeArray(raw: ReadonlyArray<string>): void {\n for (const s of raw) parseScope(s);\n}\n\nfunction parseCollab(raw: string): ParsedScope {\n // Split on the FIRST two colons only. Filter values may contain\n // colons (UUIDs with `urn:uuid:...`, subject ids like `auth0|user:1`).\n const idx1 = raw.indexOf(':');\n const idx2 = raw.indexOf(':', idx1 + 1);\n if (idx1 === -1 || idx2 === -1) {\n throw new InvalidScope(raw, 'collab scope requires entity:action:filter');\n }\n const entity = raw.slice(0, idx1);\n const action = raw.slice(idx1 + 1, idx2);\n const filterStr = raw.slice(idx2 + 1);\n\n if (entity !== 'annotations') {\n throw new InvalidScope(raw, `unknown collab entity: ${entity}`);\n }\n if (\n action !== 'create' &&\n action !== 'update' &&\n action !== 'delete' &&\n action !== 'set-group' &&\n action !== '*'\n ) {\n throw new InvalidScope(raw, `unknown collab action: ${action}`);\n }\n const filter = parseFilter(filterStr, raw);\n\n // `set-group` is a group-assignment authority, not a per-record collab\n // filter. The only meaningful filter values are `all` (assign to any\n // group) and `group=X` (assign to group X). `:self` and `:createdBy=Y`\n // can't be sensibly applied to \"what group is this annotation in\", so\n // we reject them at parse time rather than silently always-denying.\n if (action === 'set-group' && (filter.kind === 'self' || filter.kind === 'createdBy')) {\n throw new InvalidScope(\n raw,\n `set-group only supports :all or :group=<id> filters (got :${filter.kind})`,\n );\n }\n\n return {\n kind: 'collab',\n entity,\n action: action as CollabAction | '*',\n filter,\n };\n}\n\nfunction parseFilter(s: string, raw: string): CollabFilter {\n if (s === 'all') return { kind: 'all' };\n if (s === 'self') return { kind: 'self' };\n if (s.startsWith('createdBy=')) {\n const v = s.slice('createdBy='.length);\n if (!v) throw new InvalidScope(raw, 'createdBy= requires a value');\n return { kind: 'createdBy', userId: v };\n }\n if (s.startsWith('group=')) {\n const v = s.slice('group='.length);\n if (!v) throw new InvalidScope(raw, 'group= requires a value');\n return { kind: 'group', groupId: v };\n }\n throw new InvalidScope(raw, `unknown filter: ${s}`);\n}\n\n// Capability shape: lowercase dotted segments, e.g. \"doc.text.copy\".\n// Validates shape first, then membership in the closed set.\nconst CAPABILITY_SHAPE = /^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$/;\n\nfunction parseCapability(raw: string): ParsedScope {\n if (!CAPABILITY_SHAPE.test(raw)) {\n throw new InvalidScope(raw, 'invalid capability name shape');\n }\n if (!KNOWN_CAPABILITIES.has(raw as DocCapability)) {\n throw new InvalidScope(raw, `unknown capability: ${raw}`);\n }\n return { kind: 'capability', name: raw as DocCapability };\n}\n","import { parseScope } from './parser';\nimport type {\n CollabAction,\n CollabFilter,\n DocCapability,\n IdentityClaims,\n ParsedScope,\n PdfBits,\n} from './types';\n\n/**\n * Resolved collab subject — the per-record identity bits used to test\n * collab filters against. Sourced from the target record's stored\n * `/EMBD_Metadata/UserID` and `/GroupID` at mutation time.\n */\nexport interface CollabTarget {\n userId?: string;\n groupId?: string;\n}\n\n/**\n * True iff the given capability is granted by the scope array plus the\n * PDF bits visible via `pdf.permissions` expansion.\n *\n * Wildcard `*` short-circuits to true. Anything not explicitly granted\n * (or expanded from `pdf.permissions`) is denied.\n */\nexport function checkCapability(\n capability: DocCapability,\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): boolean {\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n return expandedCapabilities(parsed, pdfBits).has(capability);\n}\n\n/**\n * True iff the scope grants AT LEAST ONE of `capabilities`. Convenience\n * for routes like `/text` (`doc.text.copy` OR `doc.text.search`) and\n * `/geometry` (`doc.text.select` OR `doc.text.search`).\n */\nexport function checkAnyCapability(\n capabilities: ReadonlyArray<DocCapability>,\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): boolean {\n return capabilities.some((c) => checkCapability(c, rawScope, pdfBits));\n}\n\n/**\n * True iff the scope grants the collab action against the target record.\n *\n * Narrowing model. For each action independently:\n * 1. wildcard `*` → allow (global escape hatch)\n * 2. if any collab scope applies to this action → NARROW: only those\n * collab filters decide. If none match the target, deny — even if\n * `doc.annotate.modify` is also present. This is what makes\n * `[modify, update:self]` correctly mean \"edit own only\" rather\n * than \"edit anyone via modify-bypass.\"\n * 3. otherwise, if `doc.annotate.modify` is present → allow. This is\n * the broad PDF-bit-derived default for create/update/delete when\n * no per-action collab filter has been written.\n * 4. otherwise → deny.\n *\n * For create: `target` should be built by the caller from JWT identity\n * (`{ userId: caller.user_id, groupId: caller.group_id }`). `:self` and\n * `:all` then trivially pass; `:group=X` is the meaningful filter (only\n * matches when the caller's default group is X).\n *\n * For update / delete: `target` is the existing row's owner.\n */\nexport function checkCollab(\n action: CollabAction,\n target: CollabTarget,\n rawScope: ReadonlyArray<string>,\n identity: IdentityClaims,\n pdfBits: PdfBits,\n): boolean {\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n\n const applicableCollab = parsed.filter(\n (s): s is Extract<ParsedScope, { kind: 'collab' }> =>\n s.kind === 'collab' &&\n s.entity === 'annotations' &&\n (s.action === action || s.action === '*'),\n );\n\n if (applicableCollab.length > 0) {\n // Narrow: presence of any applicable collab scope shadows\n // `modify`-as-default for this action.\n return applicableCollab.some((s) => filterMatches(s.filter, target, identity));\n }\n\n // No collab scope for this action — fall back to the broad default.\n return expandedCapabilities(parsed, pdfBits).has('doc.annotate.modify');\n}\n\n/**\n * Compute the full set of granted capabilities after expanding\n * `pdf.permissions` and applying implication rules.\n *\n * Implications applied:\n * - `doc.annotate.modify` implies `doc.annotate.read` (you can't\n * sensibly modify what you can't see).\n * - `doc.forms.modify` implies `doc.forms.fill` and `doc.forms.read`.\n * - `doc.forms.fill` implies `doc.forms.read`.\n * - any annotation collab scope implies `doc.annotate.read`, because\n * mutation routes need to see the target row to evaluate the\n * collab filter against its current owner.\n *\n * Does NOT short-circuit on wildcard — callers do that themselves\n * before calling this. Returning the expanded set is useful for the\n * `/access` response's `effectiveScope` and for advisory UI surfacing.\n */\nexport function expandedCapabilities(\n parsed: ReadonlyArray<ParsedScope>,\n pdfBits: PdfBits,\n): Set<DocCapability> {\n const out = new Set<DocCapability>();\n let hasAnnotationCollab = false;\n\n for (const s of parsed) {\n if (s.kind === 'capability') {\n out.add(s.name);\n } else if (s.kind === 'virtual' && s.name === 'pdf.permissions') {\n addPdfPermissions(out, pdfBits);\n } else if (s.kind === 'collab' && s.entity === 'annotations') {\n hasAnnotationCollab = true;\n }\n }\n\n // Implications (apply after the explicit additions above)\n if (out.has('doc.annotate.modify')) out.add('doc.annotate.read');\n if (out.has('doc.forms.modify')) {\n out.add('doc.forms.fill');\n out.add('doc.forms.read');\n }\n if (out.has('doc.forms.fill')) out.add('doc.forms.read');\n if (hasAnnotationCollab) out.add('doc.annotate.read');\n\n return out;\n}\n\n/**\n * Convenience wrapper: takes the raw scope array, parses each entry,\n * returns the expanded capability set. Exposed for the `/access`\n * endpoint and for the SDK helper that surfaces `effectiveScope`.\n */\nexport function expandRawScope(\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): Set<DocCapability> {\n return expandedCapabilities(rawScope.map(parseScope), pdfBits);\n}\n\n/**\n * Test a single collab filter against a target record + the caller's\n * identity. Pure function — no side effects, no implicit rules.\n *\n * all → always matches\n * self → matches if identity.user_id === target.userId\n * createdBy=<X> → matches if target.userId === X\n * group=<X> → matches if target.groupId === X\n * AND identity.groups includes X\n *\n * The group-membership check on `group=X` prevents a token from\n * matching annotations in a group it doesn't belong to, even if the\n * target row carries that groupId.\n */\n/**\n * Authority to assign a specific groupId to an annotation.\n *\n * Set-group is decoupled from `doc.annotate.modify`. The reasoning:\n * capabilities like `modify` describe row access — what kind of write\n * you can do to which existing rows — and map to PDF permission bits.\n * Set-group is a cloud-only *assignment authority*: which destination\n * group can you put an annotation into? There is no PDF-bit\n * counterpart, so it doesn't inherit from `modify`.\n *\n * Resolution order:\n * 1. newGroupId === callerDefaultGroupId → true (no real reassignment\n * is happening; the annotation gets the caller's default group)\n * 2. wildcard `*` → true (global escape hatch)\n * 3. `annotations:set-group:all` → true\n * 4. `annotations:set-group:group=<newGroupId>` → true\n * 5. `annotations:*:all` or `annotations:*:group=<newGroupId>` → true\n * (action wildcard includes set-group)\n * 6. otherwise → false\n *\n * Note: independent from membership. A user with\n * `set-group:group=legal` can assign annotations to the legal group\n * even if they're not a member — that's the whole point.\n */\nexport function checkSetGroup(\n newGroupId: string,\n callerDefaultGroupId: string | undefined,\n rawScope: ReadonlyArray<string>,\n _pdfBits: PdfBits,\n): boolean {\n // No authority needed when the caller is assigning their default group.\n if (newGroupId === callerDefaultGroupId) return true;\n\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n\n for (const s of parsed) {\n if (s.kind !== 'collab') continue;\n if (s.entity !== 'annotations') continue;\n if (s.action !== 'set-group' && s.action !== '*') continue;\n if (s.filter.kind === 'all') return true;\n if (s.filter.kind === 'group' && s.filter.groupId === newGroupId) return true;\n // :self and :createdBy are rejected at parse time for set-group, so\n // they never appear here. The action-wildcard path could carry those\n // filters legitimately for other actions — silently skip those, they\n // can't satisfy a set-group check.\n }\n return false;\n}\n\nexport function filterMatches(\n filter: CollabFilter,\n target: CollabTarget,\n id: IdentityClaims,\n): boolean {\n switch (filter.kind) {\n case 'all':\n return true;\n case 'self':\n return !!id.user_id && target.userId === id.user_id;\n case 'createdBy':\n return target.userId === filter.userId;\n case 'group':\n return target.groupId === filter.groupId && (id.groups?.includes(filter.groupId) ?? false);\n }\n}\n\n/**\n * Translate `pdf.permissions` (virtual scope) into the concrete\n * capabilities it represents under the current PDF bit configuration.\n *\n * Always adds `doc.open` and `doc.render` — these are cloud-only\n * capabilities with no PDF bit, but `pdf.permissions` is meant to be\n * the \"give the user a working session\" shorthand. Without them, a\n * token with just `['pdf.permissions']` would be useless.\n *\n * Reads are unconditional: ISO 32000 / Acrobat let any reader see\n * existing annotations and form values regardless of permission bits.\n * Bit 6 governs *writing*, not visibility.\n *\n * Bit-derived expansions follow ISO 32000:\n * bit 5 → doc.text.{select, copy, search}, doc.content.copy\n * bit 3 → doc.print\n * bit 12 → doc.print.high (requires bit 3 also set)\n * bit 4 → doc.pages.modify, doc.redact, doc.metadata.modify, doc.attachments.modify\n * bit 11 → doc.pages.assemble\n * bit 6 → doc.annotate.modify\n * bit 6/9 → doc.forms.fill\n * bit 6+4 → doc.forms.modify\n *\n * Note: this same expansion lives in builders.ts as\n * `materializePdfPermissions` for SDK-side use. The two MUST stay in\n * sync; a test in resolver.test.ts pins them together.\n */\nfunction addPdfPermissions(out: Set<DocCapability>, b: PdfBits): void {\n // Always — pdf.permissions means \"give me a working session\"\n out.add('doc.open');\n out.add('doc.render');\n // Reading existing annotations and form values is unconditional —\n // PDF bit 6 governs writes, not visibility.\n out.add('doc.annotate.read');\n out.add('doc.forms.read');\n\n if (b.bit5) {\n out.add('doc.text.select');\n out.add('doc.text.copy');\n out.add('doc.text.search');\n out.add('doc.content.copy');\n }\n if (b.bit3) out.add('doc.print');\n if (b.bit12 && b.bit3) out.add('doc.print.high');\n if (b.bit4) {\n out.add('doc.pages.modify');\n out.add('doc.redact');\n out.add('doc.metadata.modify');\n out.add('doc.attachments.modify');\n }\n if (b.bit11) out.add('doc.pages.assemble');\n if (b.bit6) {\n out.add('doc.annotate.modify');\n }\n if (b.bit6 || b.bit9) out.add('doc.forms.fill');\n if (b.bit6 && b.bit4) out.add('doc.forms.modify');\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,eAAb,cAAkC,MAAM;CACtC,YACE,OACA,QACA;EACA,MAAM,kBAAkB,MAAM,KAAK,QAAQ;EAH3B,KAAA,QAAA;EAIhB,KAAK,OAAO;CACd;AACF;;;;;;;;;AAUA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YACE,UACA,SACA;EACA,MAAM,oBAAoB,UAAU,KAAK,QAAQ,KAAK,GAAG,IAAI,UAAU;EAHvD,KAAA,WAAA;EACA,KAAA,UAAA;EAGhB,KAAK,OAAO;CACd;AACF;;;;;;;;AASA,IAAa,kBAAb,cAAqC,MAAM;CACzC,YAAY,OAAe;EACzB,MAAM,UAAU,MAAM,mDAAmD;EACzE,KAAK,OAAO;CACd;AACF;;;;;;;;;;;;;ACnCA,MAAM,qCAAiD,IAAI,IAAI;CAC7D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;;;;AAeD,SAAgB,WAAW,KAA0B;CACnD,IAAI,QAAQ,KAAK,OAAO,EAAE,MAAM,WAAW;CAC3C,IAAI,QAAQ,mBAAmB,OAAO;EAAE,MAAM;EAAW,MAAM;CAAkB;CACjF,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO,YAAY,GAAG;CAC7C,OAAO,gBAAgB,GAAG;AAC5B;;;;;;;AAQA,SAAgB,mBAAmB,KAAkC;CACnE,KAAK,MAAM,KAAK,KAAK,WAAW,CAAC;AACnC;AAEA,SAAS,YAAY,KAA0B;CAG7C,MAAM,OAAO,IAAI,QAAQ,GAAG;CAC5B,MAAM,OAAO,IAAI,QAAQ,KAAK,OAAO,CAAC;CACtC,IAAI,SAAS,MAAM,SAAS,IAC1B,MAAM,IAAI,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AgB;CAExB,IAAI,EAAE,MAAM;EACV,IAAI,IAAI,iBAAiB;EACzB,IAAI,IAAI,eAAe;EACvB,IAAI,IAAI,iBAAiB;EACzB,IAAI,IAAI,kBAAkB;CAC5B;CACA,IAAI,EAAE,MAAM,IAAI,IAAI,WAAW;CAC/B,IAAI,EAAE,SAAS,EAAE,MAAM,IAAI,IAAI,gBAAgB;CAC/C,IAAI,EAAE,MAAM;EACV,IAAI,IAAI,kBAAkB;EAC1B,IAAI,IAAI,YAAY;EACpB,IAAI,IAAI,qBAAqB;EAC7B,IAAI,IAAI,wBAAwB;CAClC;CACA,IAAI,EAAE,OAAO,IAAI,IAAI,oBAAoB;CACzC,IAAI,EAAE,MACJ,IAAI,IAAI,qBAAqB;CAE/B,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,IAAI,gBAAgB;CAC9C,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,IAAI,kBAAkB;AAClD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver-D-jumvgM.cjs","names":[],"sources":["../src/auth/scope/errors.ts","../src/auth/scope/parser.ts","../src/auth/scope/resolver.ts"],"sourcesContent":["/**\n * Thrown by {@link parseScope} / {@link validateScopeArray} when a scope\n * string does not match any known grammar (capability, collab, virtual,\n * or wildcard).\n *\n * Carries the offending scope verbatim so route/JWT-layer error\n * handlers can echo it to the customer.\n */\nexport class InvalidScope extends Error {\n constructor(\n public readonly scope: string,\n reason: string,\n ) {\n super(`invalid scope \"${scope}\": ${reason}`);\n this.name = 'InvalidScope';\n }\n}\n\n/**\n * Thrown by route guards and engine-local enforcement when a capability\n * or collab action is denied for the current request/handle.\n *\n * `required` names what the caller needed (e.g., \"doc.render\" or\n * \"annotations:update\"). `context` is an optional label such as \"local\"\n * or \"/v1/docs/.../pages/2/render\".\n */\nexport class PermissionDenied extends Error {\n constructor(\n public readonly required: string,\n public readonly context?: string,\n ) {\n super(`permission denied${context ? ` (${context})` : ''}: ${required}`);\n this.name = 'PermissionDenied';\n }\n}\n\n/**\n * Thrown at engine-local open time when the supplied scope includes\n * collab filters (`:self`, `:group=...`) but the identity claims needed\n * to resolve them are missing. Fails loudly at open so the configuration\n * mistake is visible immediately instead of producing silent denies at\n * every annotation mutation.\n */\nexport class MissingIdentity extends Error {\n constructor(scope: string) {\n super(`scope \"${scope}\" requires identity claims (user_id and/or groups)`);\n this.name = 'MissingIdentity';\n }\n}\n","import { InvalidScope } from './errors';\nimport type { CollabAction, CollabFilter, DocCapability, ParsedScope } from './types';\n\n/**\n * Closed set of recognized capability strings. Membership is the\n * authoritative source of truth — adding a new capability requires\n * extending the `DocCapability` union AND adding it here. The parser\n * rejects anything outside this set.\n *\n * Removed legacy names (e.g., `doc.read`, `doc.edit-pages`, `doc.save`)\n * are deliberately absent so any JWT carrying them fails at verify\n * time with a clear error.\n */\nconst KNOWN_CAPABILITIES: ReadonlySet<DocCapability> = new Set([\n 'doc.open',\n 'doc.render',\n 'doc.text.select',\n 'doc.text.copy',\n 'doc.text.search',\n 'doc.content.copy',\n 'doc.download',\n 'doc.download.flattened',\n 'doc.print',\n 'doc.print.high',\n 'doc.pages.modify',\n 'doc.pages.assemble',\n 'doc.forms.read',\n 'doc.forms.fill',\n 'doc.forms.modify',\n 'doc.forms.submit',\n 'doc.annotate.read',\n 'doc.annotate.modify',\n 'doc.metadata.modify',\n 'doc.attachments.modify',\n 'doc.redact',\n]);\n\n/**\n * Parse a single scope string into a structured `ParsedScope`.\n *\n * Recognised shapes:\n * - `\"*\"` → wildcard\n * - `\"pdf.permissions\"` → virtual (expands at resolve time)\n * - `\"a.b.c...\"` (dotted) → capability\n * - `\"entity:action:filter\"` (colons) → collab\n *\n * Throws {@link InvalidScope} for any string that fails to match one of\n * those shapes, or whose capability/entity/action/filter is not in the\n * closed enum.\n */\nexport function parseScope(raw: string): ParsedScope {\n if (raw === '*') return { kind: 'wildcard' };\n if (raw === 'pdf.permissions') return { kind: 'virtual', name: 'pdf.permissions' };\n if (raw.includes(':')) return parseCollab(raw);\n return parseCapability(raw);\n}\n\n/**\n * Validate every entry in a scope array by attempting to parse it.\n * Throws on the first invalid string. Discards the parse output —\n * callers re-parse at resolution time to keep the array as the\n * authoritative payload.\n */\nexport function validateScopeArray(raw: ReadonlyArray<string>): void {\n for (const s of raw) parseScope(s);\n}\n\nfunction parseCollab(raw: string): ParsedScope {\n // Split on the FIRST two colons only. Filter values may contain\n // colons (UUIDs with `urn:uuid:...`, subject ids like `auth0|user:1`).\n const idx1 = raw.indexOf(':');\n const idx2 = raw.indexOf(':', idx1 + 1);\n if (idx1 === -1 || idx2 === -1) {\n throw new InvalidScope(raw, 'collab scope requires entity:action:filter');\n }\n const entity = raw.slice(0, idx1);\n const action = raw.slice(idx1 + 1, idx2);\n const filterStr = raw.slice(idx2 + 1);\n\n if (entity !== 'annotations') {\n throw new InvalidScope(raw, `unknown collab entity: ${entity}`);\n }\n if (\n action !== 'create' &&\n action !== 'update' &&\n action !== 'delete' &&\n action !== 'set-group' &&\n action !== '*'\n ) {\n throw new InvalidScope(raw, `unknown collab action: ${action}`);\n }\n const filter = parseFilter(filterStr, raw);\n\n // `set-group` is a group-assignment authority, not a per-record collab\n // filter. The only meaningful filter values are `all` (assign to any\n // group) and `group=X` (assign to group X). `:self` and `:createdBy=Y`\n // can't be sensibly applied to \"what group is this annotation in\", so\n // we reject them at parse time rather than silently always-denying.\n if (action === 'set-group' && (filter.kind === 'self' || filter.kind === 'createdBy')) {\n throw new InvalidScope(\n raw,\n `set-group only supports :all or :group=<id> filters (got :${filter.kind})`,\n );\n }\n\n return {\n kind: 'collab',\n entity,\n action: action as CollabAction | '*',\n filter,\n };\n}\n\nfunction parseFilter(s: string, raw: string): CollabFilter {\n if (s === 'all') return { kind: 'all' };\n if (s === 'self') return { kind: 'self' };\n if (s.startsWith('createdBy=')) {\n const v = s.slice('createdBy='.length);\n if (!v) throw new InvalidScope(raw, 'createdBy= requires a value');\n return { kind: 'createdBy', userId: v };\n }\n if (s.startsWith('group=')) {\n const v = s.slice('group='.length);\n if (!v) throw new InvalidScope(raw, 'group= requires a value');\n return { kind: 'group', groupId: v };\n }\n throw new InvalidScope(raw, `unknown filter: ${s}`);\n}\n\n// Capability shape: lowercase dotted segments, e.g. \"doc.text.copy\".\n// Validates shape first, then membership in the closed set.\nconst CAPABILITY_SHAPE = /^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$/;\n\nfunction parseCapability(raw: string): ParsedScope {\n if (!CAPABILITY_SHAPE.test(raw)) {\n throw new InvalidScope(raw, 'invalid capability name shape');\n }\n if (!KNOWN_CAPABILITIES.has(raw as DocCapability)) {\n throw new InvalidScope(raw, `unknown capability: ${raw}`);\n }\n return { kind: 'capability', name: raw as DocCapability };\n}\n","import { parseScope } from './parser';\nimport type {\n CollabAction,\n CollabFilter,\n DocCapability,\n IdentityClaims,\n ParsedScope,\n PdfBits,\n} from './types';\n\n/**\n * Resolved collab subject — the per-record identity bits used to test\n * collab filters against. Sourced from the target record's stored\n * `/EMBD_Metadata/UserID` and `/GroupID` at mutation time.\n */\nexport interface CollabTarget {\n userId?: string;\n groupId?: string;\n}\n\n/**\n * True iff the given capability is granted by the scope array plus the\n * PDF bits visible via `pdf.permissions` expansion.\n *\n * Wildcard `*` short-circuits to true. Anything not explicitly granted\n * (or expanded from `pdf.permissions`) is denied.\n */\nexport function checkCapability(\n capability: DocCapability,\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): boolean {\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n return expandedCapabilities(parsed, pdfBits).has(capability);\n}\n\n/**\n * True iff the scope grants AT LEAST ONE of `capabilities`. Convenience\n * for routes like `/text` (`doc.text.copy` OR `doc.text.search`) and\n * `/geometry` (`doc.text.select` OR `doc.text.search`).\n */\nexport function checkAnyCapability(\n capabilities: ReadonlyArray<DocCapability>,\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): boolean {\n return capabilities.some((c) => checkCapability(c, rawScope, pdfBits));\n}\n\n/**\n * True iff the scope grants the collab action against the target record.\n *\n * Narrowing model. For each action independently:\n * 1. wildcard `*` → allow (global escape hatch)\n * 2. if any collab scope applies to this action → NARROW: only those\n * collab filters decide. If none match the target, deny — even if\n * `doc.annotate.modify` is also present. This is what makes\n * `[modify, update:self]` correctly mean \"edit own only\" rather\n * than \"edit anyone via modify-bypass.\"\n * 3. otherwise, if `doc.annotate.modify` is present → allow. This is\n * the broad PDF-bit-derived default for create/update/delete when\n * no per-action collab filter has been written.\n * 4. otherwise → deny.\n *\n * For create: `target` should be built by the caller from JWT identity\n * (`{ userId: caller.user_id, groupId: caller.group_id }`). `:self` and\n * `:all` then trivially pass; `:group=X` is the meaningful filter (only\n * matches when the caller's default group is X).\n *\n * For update / delete: `target` is the existing row's owner.\n */\nexport function checkCollab(\n action: CollabAction,\n target: CollabTarget,\n rawScope: ReadonlyArray<string>,\n identity: IdentityClaims,\n pdfBits: PdfBits,\n): boolean {\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n\n const applicableCollab = parsed.filter(\n (s): s is Extract<ParsedScope, { kind: 'collab' }> =>\n s.kind === 'collab' &&\n s.entity === 'annotations' &&\n (s.action === action || s.action === '*'),\n );\n\n if (applicableCollab.length > 0) {\n // Narrow: presence of any applicable collab scope shadows\n // `modify`-as-default for this action.\n return applicableCollab.some((s) => filterMatches(s.filter, target, identity));\n }\n\n // No collab scope for this action — fall back to the broad default.\n return expandedCapabilities(parsed, pdfBits).has('doc.annotate.modify');\n}\n\n/**\n * Compute the full set of granted capabilities after expanding\n * `pdf.permissions` and applying implication rules.\n *\n * Implications applied:\n * - `doc.annotate.modify` implies `doc.annotate.read` (you can't\n * sensibly modify what you can't see).\n * - `doc.forms.modify` implies `doc.forms.fill` and `doc.forms.read`.\n * - `doc.forms.fill` implies `doc.forms.read`.\n * - any annotation collab scope implies `doc.annotate.read`, because\n * mutation routes need to see the target row to evaluate the\n * collab filter against its current owner.\n *\n * Does NOT short-circuit on wildcard — callers do that themselves\n * before calling this. Returning the expanded set is useful for the\n * `/access` response's `effectiveScope` and for advisory UI surfacing.\n */\nexport function expandedCapabilities(\n parsed: ReadonlyArray<ParsedScope>,\n pdfBits: PdfBits,\n): Set<DocCapability> {\n const out = new Set<DocCapability>();\n let hasAnnotationCollab = false;\n\n for (const s of parsed) {\n if (s.kind === 'capability') {\n out.add(s.name);\n } else if (s.kind === 'virtual' && s.name === 'pdf.permissions') {\n addPdfPermissions(out, pdfBits);\n } else if (s.kind === 'collab' && s.entity === 'annotations') {\n hasAnnotationCollab = true;\n }\n }\n\n // Implications (apply after the explicit additions above)\n if (out.has('doc.annotate.modify')) out.add('doc.annotate.read');\n if (out.has('doc.forms.modify')) {\n out.add('doc.forms.fill');\n out.add('doc.forms.read');\n }\n if (out.has('doc.forms.fill')) out.add('doc.forms.read');\n if (hasAnnotationCollab) out.add('doc.annotate.read');\n\n return out;\n}\n\n/**\n * Convenience wrapper: takes the raw scope array, parses each entry,\n * returns the expanded capability set. Exposed for the `/access`\n * endpoint and for the SDK helper that surfaces `effectiveScope`.\n */\nexport function expandRawScope(\n rawScope: ReadonlyArray<string>,\n pdfBits: PdfBits,\n): Set<DocCapability> {\n return expandedCapabilities(rawScope.map(parseScope), pdfBits);\n}\n\n/**\n * Test a single collab filter against a target record + the caller's\n * identity. Pure function — no side effects, no implicit rules.\n *\n * all → always matches\n * self → matches if identity.user_id === target.userId\n * createdBy=<X> → matches if target.userId === X\n * group=<X> → matches if target.groupId === X\n * AND identity.groups includes X\n *\n * The group-membership check on `group=X` prevents a token from\n * matching annotations in a group it doesn't belong to, even if the\n * target row carries that groupId.\n */\n/**\n * Authority to assign a specific groupId to an annotation.\n *\n * Set-group is decoupled from `doc.annotate.modify`. The reasoning:\n * capabilities like `modify` describe row access — what kind of write\n * you can do to which existing rows — and map to PDF permission bits.\n * Set-group is a cloud-only *assignment authority*: which destination\n * group can you put an annotation into? There is no PDF-bit\n * counterpart, so it doesn't inherit from `modify`.\n *\n * Resolution order:\n * 1. newGroupId === callerDefaultGroupId → true (no real reassignment\n * is happening; the annotation gets the caller's default group)\n * 2. wildcard `*` → true (global escape hatch)\n * 3. `annotations:set-group:all` → true\n * 4. `annotations:set-group:group=<newGroupId>` → true\n * 5. `annotations:*:all` or `annotations:*:group=<newGroupId>` → true\n * (action wildcard includes set-group)\n * 6. otherwise → false\n *\n * Note: independent from membership. A user with\n * `set-group:group=legal` can assign annotations to the legal group\n * even if they're not a member — that's the whole point.\n */\nexport function checkSetGroup(\n newGroupId: string,\n callerDefaultGroupId: string | undefined,\n rawScope: ReadonlyArray<string>,\n _pdfBits: PdfBits,\n): boolean {\n // No authority needed when the caller is assigning their default group.\n if (newGroupId === callerDefaultGroupId) return true;\n\n const parsed = rawScope.map(parseScope);\n if (parsed.some((s) => s.kind === 'wildcard')) return true;\n\n for (const s of parsed) {\n if (s.kind !== 'collab') continue;\n if (s.entity !== 'annotations') continue;\n if (s.action !== 'set-group' && s.action !== '*') continue;\n if (s.filter.kind === 'all') return true;\n if (s.filter.kind === 'group' && s.filter.groupId === newGroupId) return true;\n // :self and :createdBy are rejected at parse time for set-group, so\n // they never appear here. The action-wildcard path could carry those\n // filters legitimately for other actions — silently skip those, they\n // can't satisfy a set-group check.\n }\n return false;\n}\n\nexport function filterMatches(\n filter: CollabFilter,\n target: CollabTarget,\n id: IdentityClaims,\n): boolean {\n switch (filter.kind) {\n case 'all':\n return true;\n case 'self':\n return !!id.user_id && target.userId === id.user_id;\n case 'createdBy':\n return target.userId === filter.userId;\n case 'group':\n return target.groupId === filter.groupId && (id.groups?.includes(filter.groupId) ?? false);\n }\n}\n\n/**\n * Translate `pdf.permissions` (virtual scope) into the concrete\n * capabilities it represents under the current PDF bit configuration.\n *\n * Always adds `doc.open` and `doc.render` — these are cloud-only\n * capabilities with no PDF bit, but `pdf.permissions` is meant to be\n * the \"give the user a working session\" shorthand. Without them, a\n * token with just `['pdf.permissions']` would be useless.\n *\n * Reads are unconditional: ISO 32000 / Acrobat let any reader see\n * existing annotations and form values regardless of permission bits.\n * Bit 6 governs *writing*, not visibility.\n *\n * Bit-derived expansions follow ISO 32000:\n * bit 5 → doc.text.{select, copy, search}, doc.content.copy\n * bit 3 → doc.print\n * bit 12 → doc.print.high (requires bit 3 also set)\n * bit 4 → doc.pages.modify, doc.redact, doc.metadata.modify, doc.attachments.modify\n * bit 11 → doc.pages.assemble\n * bit 6 → doc.annotate.modify\n * bit 6/9 → doc.forms.fill\n * bit 6+4 → doc.forms.modify\n *\n * Note: this same expansion lives in builders.ts as\n * `materializePdfPermissions` for SDK-side use. The two MUST stay in\n * sync; a test in resolver.test.ts pins them together.\n */\nfunction addPdfPermissions(out: Set<DocCapability>, b: PdfBits): void {\n // Always — pdf.permissions means \"give me a working session\"\n out.add('doc.open');\n out.add('doc.render');\n // Reading existing annotations and form values is unconditional —\n // PDF bit 6 governs writes, not visibility.\n out.add('doc.annotate.read');\n out.add('doc.forms.read');\n\n if (b.bit5) {\n out.add('doc.text.select');\n out.add('doc.text.copy');\n out.add('doc.text.search');\n out.add('doc.content.copy');\n }\n if (b.bit3) out.add('doc.print');\n if (b.bit12 && b.bit3) out.add('doc.print.high');\n if (b.bit4) {\n out.add('doc.pages.modify');\n out.add('doc.redact');\n out.add('doc.metadata.modify');\n out.add('doc.attachments.modify');\n }\n if (b.bit11) out.add('doc.pages.assemble');\n if (b.bit6) {\n out.add('doc.annotate.modify');\n }\n if (b.bit6 || b.bit9) out.add('doc.forms.fill');\n if (b.bit6 && b.bit4) out.add('doc.forms.modify');\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,eAAb,cAAkC,MAAM;CACtC,YACE,OACA,QACA;EACA,MAAM,kBAAkB,MAAM,KAAK,QAAQ;EAH3B,KAAA,QAAA;EAIhB,KAAK,OAAO;CACd;AACF;;;;;;;;;AAUA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,YACE,UACA,SACA;EACA,MAAM,oBAAoB,UAAU,KA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