@cloudpdf/engine 3.0.0-next.11 → 3.0.0-next.13

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/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
1
+ import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentSignaturesService, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
2
2
  import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
3
3
  import { SessionEventPublisher } from "@embedpdf/engine-services";
4
4
  //#region src/transport/HttpClient.d.ts
@@ -318,6 +318,7 @@ declare class CloudDocumentHandle implements DocumentHandle$1 {
318
318
  readonly annotations: DocumentAnnotationsService$1;
319
319
  readonly actions: DocumentActionsService;
320
320
  readonly attachments: DocumentAttachmentsService;
321
+ readonly signatures: DocumentSignaturesService;
321
322
  readonly forms: DocumentFormsService;
322
323
  readonly search: CloudDocumentSearchService;
323
324
  readonly pages: DocumentPagesService$1;
@@ -513,6 +514,14 @@ declare class CloudDocumentPagesService implements DocumentPagesService$1 {
513
514
  */
514
515
  list(): AbortablePromise$1<PageListSnapshot>;
515
516
  move(pageObjectNumbers: PageObjectNumber[], destIndex: number): AbortablePromise$1<PageMoveResult>;
517
+ setName(input: PageNameInput): AbortablePromise$1<PageNameResult>;
518
+ removeName(input: PageRemoveNameInput): AbortablePromise$1<PageNameResult>;
519
+ /**
520
+ * Named pages are LAYOUT: both verbs share the page-move patch exactly —
521
+ * docVersion + layoutVersion advance, no per-page pin changes, so the
522
+ * cached manifest is patched in place and the fresh layout is published.
523
+ */
524
+ private runNameMutation;
516
525
  rotate(pageObjectNumbers: PageObjectNumber[], rotation: PageRotation): AbortablePromise$1<PageRotateResult>;
517
526
  delete(pageObjectNumbers: PageObjectNumber[]): AbortablePromise$1<PageDeleteResult>;
518
527
  insert(bytes: Uint8Array | ArrayBuffer, destIndex?: number): AbortablePromise$1<PageInsertResult>;
@@ -559,6 +568,8 @@ declare class CloudPageAnnotationsService implements PageAnnotationsService$1 {
559
568
  private patchMutation;
560
569
  delete(ref: AnnotationRef): AbortablePromise$1<AnnotationDeleteResult>;
561
570
  move(refs: AnnotationRef[], toIndex: number): AbortablePromise$1<AnnotationMoveResult>;
571
+ flatten(refs: AnnotationRef[], usage?: PageFlattenUsage): AbortablePromise$1<AnnotationFlattenResult>;
572
+ exportAppearance(refs: AnnotationRef[]): AbortablePromise$1<Uint8Array>;
562
573
  /**
563
574
  * Patch the cached manifest, then publish the mutation to the document's
564
575
  * event stream (in that order — listeners reading the manifest in their
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
1
+ import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentSignaturesService, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
2
2
  import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
3
3
  import { SessionEventPublisher } from "@embedpdf/engine-services";
4
4
  //#region src/transport/HttpClient.d.ts
@@ -318,6 +318,7 @@ declare class CloudDocumentHandle implements DocumentHandle$1 {
318
318
  readonly annotations: DocumentAnnotationsService$1;
319
319
  readonly actions: DocumentActionsService;
320
320
  readonly attachments: DocumentAttachmentsService;
321
+ readonly signatures: DocumentSignaturesService;
321
322
  readonly forms: DocumentFormsService;
322
323
  readonly search: CloudDocumentSearchService;
323
324
  readonly pages: DocumentPagesService$1;
@@ -513,6 +514,14 @@ declare class CloudDocumentPagesService implements DocumentPagesService$1 {
513
514
  */
514
515
  list(): AbortablePromise$1<PageListSnapshot>;
515
516
  move(pageObjectNumbers: PageObjectNumber[], destIndex: number): AbortablePromise$1<PageMoveResult>;
517
+ setName(input: PageNameInput): AbortablePromise$1<PageNameResult>;
518
+ removeName(input: PageRemoveNameInput): AbortablePromise$1<PageNameResult>;
519
+ /**
520
+ * Named pages are LAYOUT: both verbs share the page-move patch exactly —
521
+ * docVersion + layoutVersion advance, no per-page pin changes, so the
522
+ * cached manifest is patched in place and the fresh layout is published.
523
+ */
524
+ private runNameMutation;
516
525
  rotate(pageObjectNumbers: PageObjectNumber[], rotation: PageRotation): AbortablePromise$1<PageRotateResult>;
517
526
  delete(pageObjectNumbers: PageObjectNumber[]): AbortablePromise$1<PageDeleteResult>;
518
527
  insert(bytes: Uint8Array | ArrayBuffer, destIndex?: number): AbortablePromise$1<PageInsertResult>;
@@ -559,6 +568,8 @@ declare class CloudPageAnnotationsService implements PageAnnotationsService$1 {
559
568
  private patchMutation;
560
569
  delete(ref: AnnotationRef): AbortablePromise$1<AnnotationDeleteResult>;
561
570
  move(refs: AnnotationRef[], toIndex: number): AbortablePromise$1<AnnotationMoveResult>;
571
+ flatten(refs: AnnotationRef[], usage?: PageFlattenUsage): AbortablePromise$1<AnnotationFlattenResult>;
572
+ exportAppearance(refs: AnnotationRef[]): AbortablePromise$1<Uint8Array>;
562
573
  /**
563
574
  * Patch the cached manifest, then publish the mutation to the document's
564
575
  * event stream (in that order — listeners reading the manifest in their
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AbortError, AbortError as AbortError$1, AbortablePromise, AbortablePromise as AbortablePromise$1, CONTINUOUS_RENDER_POLICY, DEFAULT_PDF_SAVE_MODE, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineErrorCode as EngineErrorCode$1, canonicalSearchQuery, checkCapability, checkCollab, checkSetGroup, createPageImageHandle, decodePdfBits, encodeFieldRefKey, encodeStableIdKey, expandRawScope, normalizeAnnotationDraft, normalizeAnnotationPatch, normalizeAttachmentFileSource, passwordPromptFromState, searchContentEpoch, securityStateFromHead } from "@embedpdf/engine-core/runtime";
2
- import { AccessResponseSchema, AnnotationAppearanceManifestSchema, AnnotationCreateResultSchema, AnnotationDeleteResultSchema, AnnotationListPageSnapshotSchema, AnnotationListSnapshotAllPagesSchema, AnnotationMoveResultSchema, AnnotationUpdateResultSchema, AttachmentCreateResultSchema, AttachmentDeleteResultSchema, DEFAULT_LAYER_NAME, DocumentActionsSnapshotSchema, DocumentHeadSchema, DocumentManifestSchema, DocumentMetadataSchema, EmbeddedFileItemSchema, EngineErrorPayloadSchema, FormEffectsResultSchema, FormFieldCreateResultSchema, FormFieldDTOSchema, FormFieldDeleteResultSchema, FormFieldUpdateResultSchema, FormImportResultSchema, FormRepairResultSchema, FormSetValueResultSchema, FormSnapshotSchema, FormWidgetLinkResultSchema, MetadataUpdateResultSchema, PageDeleteResultSchema, PageFlattenResultSchema, PageGeometrySnapshotSchema, PageInsertResultSchema, PageListSnapshotSchema, PageMoveResultSchema, PageRotateResultSchema, PageTextSnapshotSchema, RedactionApplyResultSchema, SearchSliceSchema, WeakAnnotationSessionResponseSchema, annotationAppearancesImageOptionsToWire, applyCdnAccess, decodeSearchToken, decodeTokenText, encodeSearchToken, renderImageOptionsToWire, wirePaths } from "@embedpdf/engine-core/wire";
2
+ import { AccessResponseSchema, AnnotationAppearanceManifestSchema, AnnotationCreateResultSchema, AnnotationDeleteResultSchema, AnnotationFlattenResultSchema, AnnotationListPageSnapshotSchema, AnnotationListSnapshotAllPagesSchema, AnnotationMoveResultSchema, AnnotationUpdateResultSchema, AttachmentCreateResultSchema, AttachmentDeleteResultSchema, ChangeAnalysisSchema, DEFAULT_LAYER_NAME, DocumentActionsSnapshotSchema, DocumentHeadSchema, DocumentManifestSchema, DocumentMetadataSchema, EmbeddedFileItemSchema, EngineErrorPayloadSchema, FormEffectsResultSchema, FormFieldCreateResultSchema, FormFieldDTOSchema, FormFieldDeleteResultSchema, FormFieldUpdateResultSchema, FormImportResultSchema, FormRepairResultSchema, FormSetValueResultSchema, FormSnapshotSchema, FormWidgetLinkResultSchema, MetadataUpdateResultSchema, PageDeleteResultSchema, PageFlattenResultSchema, PageGeometrySnapshotSchema, PageInsertResultSchema, PageListSnapshotSchema, PageMoveResultSchema, PageNameResultSchema, PageRotateResultSchema, PageTextSnapshotSchema, RedactionApplyResultSchema, SearchSliceSchema, SignatureAbortResultSchema, SignatureCompleteResultSchema, SignaturePreparedWireSchema, SignatureSnapshotSchema, WeakAnnotationSessionResponseSchema, annotationAppearancesImageOptionsToWire, applyCdnAccess, decodePrepared, decodeSearchToken, decodeTokenText, encodeSearchToken, renderImageOptionsToWire, toBase64, wirePaths } from "@embedpdf/engine-core/wire";
3
3
  import { EventHub, SessionEventPublisher, generateUuid } from "@embedpdf/engine-services";
4
4
  //#region src/document/planes.ts
5
5
  /**
@@ -434,6 +434,24 @@ var CloudDocumentFormsService = class {
434
434
  return this.absorbMutation(result, "form.fieldUpdated");
435
435
  });
436
436
  }
437
+ setSignatureAppearance(ref, appearance) {
438
+ const rejected = this.rejectIfClosed();
439
+ if (rejected) return rejected;
440
+ return AbortablePromise$1.run(async (signal) => {
441
+ const bytes = new ArrayBuffer(appearance.pdf.byteLength);
442
+ new Uint8Array(bytes).set(appearance.pdf);
443
+ const form = buildMutationForm({
444
+ resource: "r0",
445
+ pageIndex: appearance.pageIndex ?? 0
446
+ }, { r0: {
447
+ bytes,
448
+ mimeType: "application/pdf",
449
+ name: "appearance.pdf"
450
+ } });
451
+ const result = await this.http.postMultipartJson(wirePaths.layerFormFieldSignatureAppearance(this.docId, this.layerName, encodeFieldRefKey(ref)), form, (raw) => FormFieldUpdateResultSchema.parse(raw), signal);
452
+ return this.absorbMutation(result, "form.fieldUpdated");
453
+ });
454
+ }
437
455
  deleteField(ref) {
438
456
  const rejected = this.rejectIfClosed();
439
457
  if (rejected) return rejected;
@@ -559,6 +577,31 @@ var CloudDocumentPagesService = class {
559
577
  return result;
560
578
  });
561
579
  }
580
+ setName(input) {
581
+ return this.runNameMutation(wirePaths.layerPagesNames(this.docId, this.layerName), input, input.name, input.pageObjectNumber);
582
+ }
583
+ removeName(input) {
584
+ return this.runNameMutation(wirePaths.layerPagesNamesDelete(this.docId, this.layerName), input, input.name, null);
585
+ }
586
+ /**
587
+ * Named pages are LAYOUT: both verbs share the page-move patch exactly —
588
+ * docVersion + layoutVersion advance, no per-page pin changes, so the
589
+ * cached manifest is patched in place and the fresh layout is published.
590
+ */
591
+ runNameMutation(path, body, name, pageObjectNumber) {
592
+ if (this.isClosed()) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
593
+ return AbortablePromise$1.run(async (signal) => {
594
+ const result = await this.http.postJson(path, body, (raw) => PageNameResultSchema.parse(raw), signal);
595
+ if (result.cache) this.manifest.applyPageStructure(result.cache);
596
+ this.publisher.publishLocal({
597
+ type: "pages.named",
598
+ name,
599
+ pageObjectNumber,
600
+ ...result
601
+ });
602
+ return result;
603
+ });
604
+ }
562
605
  rotate(pageObjectNumbers, rotation) {
563
606
  if (this.isClosed()) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
564
607
  return AbortablePromise$1.run(async (signal) => {
@@ -989,6 +1032,176 @@ function identityFromClaims(claims) {
989
1032
  return Object.keys(out).length > 0 ? out : null;
990
1033
  }
991
1034
  //#endregion
1035
+ //#region src/document/CloudDocumentSignaturesService.ts
1036
+ /**
1037
+ * Cloud-side digital signatures. Two kinds of read, two kinds of URL:
1038
+ *
1039
+ * - The LAYER view (`list`, and `analyze` of the working copy) is pinned
1040
+ * by the manifest's `docVersion`, like every other layer read: a
1041
+ * signature is a layer state change, the immutable URL moves with it.
1042
+ * - Signed BYTES (`contents`, `digest`, `revisionBytes`, and `analyze`
1043
+ * of history) belong to a base VERSION and are content-addressed by
1044
+ * the manifest's `baseSha`: immutable forever, shared by every layer
1045
+ * and every caller.
1046
+ *
1047
+ * Signing is the server's two-phase protocol over the same wire shapes
1048
+ * the local engine uses. `prepare` and `complete` change the manifest in
1049
+ * ways no delta carries (a publish moves `baseSha` itself), so both
1050
+ * refresh it before returning.
1051
+ */
1052
+ var CloudDocumentSignaturesService = class {
1053
+ constructor(http, docId, layerName, isClosed, manifest, publisher) {
1054
+ this.http = http;
1055
+ this.docId = docId;
1056
+ this.layerName = layerName;
1057
+ this.isClosed = isClosed;
1058
+ this.manifest = manifest;
1059
+ this.publisher = publisher;
1060
+ }
1061
+ list() {
1062
+ const rejected = this.closedRejection();
1063
+ if (rejected) return rejected;
1064
+ return AbortablePromise$1.run(async (signal) => this.http.getJsonWithRefresh(async (s) => {
1065
+ const manifest = await this.manifest.get(s);
1066
+ return wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
1067
+ }, (raw) => SignatureSnapshotSchema.parse(raw), async (s) => {
1068
+ await this.manifest.refresh(s);
1069
+ }, signal));
1070
+ }
1071
+ contents(field) {
1072
+ const rejected = this.closedRejection();
1073
+ if (rejected) return rejected;
1074
+ return AbortablePromise$1.run(async (signal) => {
1075
+ const manifest = await this.manifest.get(signal);
1076
+ const name = await this.fieldName(field, signal);
1077
+ return this.http.getBytes(wirePaths.docVersionSignatureContents(this.docId, manifest.baseSha, name), signal);
1078
+ });
1079
+ }
1080
+ digest(field, algorithm) {
1081
+ const rejected = this.closedRejection();
1082
+ if (rejected) return rejected;
1083
+ return AbortablePromise$1.run(async (signal) => {
1084
+ const manifest = await this.manifest.get(signal);
1085
+ const name = await this.fieldName(field, signal);
1086
+ return this.http.getBytes(wirePaths.docVersionSignatureDigest(this.docId, manifest.baseSha, name, algorithm), signal);
1087
+ });
1088
+ }
1089
+ revisionBytes(revisionIndex) {
1090
+ const rejected = this.closedRejection();
1091
+ if (rejected) return rejected;
1092
+ return AbortablePromise$1.run(async (signal) => {
1093
+ const manifest = await this.manifest.get(signal);
1094
+ return this.http.getBytes(wirePaths.docVersionRevision(this.docId, manifest.baseSha, revisionIndex), signal);
1095
+ });
1096
+ }
1097
+ /**
1098
+ * `until: 'working-copy'` (or unset while the layer holds edits) judges
1099
+ * the layer's pending edits against the base at the layer URL; anything
1100
+ * else is history of the base version and resolves at the version URL.
1101
+ */
1102
+ analyze(input) {
1103
+ const rejected = this.closedRejection();
1104
+ if (rejected) return rejected;
1105
+ return AbortablePromise$1.run(async (signal) => {
1106
+ const manifest = await this.manifest.get(signal);
1107
+ if (input.until === "working-copy" || input.until === void 0 && manifest.working) return this.http.getJsonWithRefresh(async (s) => {
1108
+ const current = await this.manifest.get(s);
1109
+ return wirePaths.layerSignaturesAnalysis(this.docId, this.layerName, {
1110
+ docVersion: current.docVersion,
1111
+ since: input.since,
1112
+ ...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
1113
+ ...input.detail !== void 0 ? { detail: input.detail } : {}
1114
+ });
1115
+ }, (raw) => ChangeAnalysisSchema.parse(raw), async (s) => {
1116
+ await this.manifest.refresh(s);
1117
+ }, signal);
1118
+ return this.http.getJson(wirePaths.docVersionAnalysis(this.docId, manifest.baseSha, {
1119
+ since: input.since,
1120
+ ...typeof input.until === "object" ? { until: input.until.revisionIndex } : {},
1121
+ ...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
1122
+ ...input.detail !== void 0 ? { detail: input.detail } : {}
1123
+ }), (raw) => ChangeAnalysisSchema.parse(raw), signal);
1124
+ });
1125
+ }
1126
+ prepare(input) {
1127
+ const rejected = this.closedRejection();
1128
+ if (rejected) return rejected;
1129
+ return AbortablePromise$1.run(async (signal) => {
1130
+ const { appearance, ...rest } = input;
1131
+ const form = buildMutationForm({
1132
+ ...rest,
1133
+ ...appearance ? { appearance: {
1134
+ resource: "appearance",
1135
+ ...appearance.pageIndex !== void 0 ? { pageIndex: appearance.pageIndex } : {}
1136
+ } } : {}
1137
+ }, appearance ? { appearance: {
1138
+ bytes: appearance.pdf.slice().buffer,
1139
+ mimeType: "application/pdf",
1140
+ name: "appearance.pdf"
1141
+ } } : {});
1142
+ const prepared = await this.http.postMultipartJson(wirePaths.layerSignaturesPrepare(this.docId, this.layerName), form, (raw) => decodePrepared(SignaturePreparedWireSchema.parse(raw)), signal);
1143
+ await this.manifest.refresh(signal);
1144
+ this.publisher.publishLocal({
1145
+ type: "signature.prepared",
1146
+ signingId: prepared.signingId,
1147
+ field: input.field
1148
+ });
1149
+ return prepared;
1150
+ });
1151
+ }
1152
+ complete(input) {
1153
+ const rejected = this.closedRejection();
1154
+ if (rejected) return rejected;
1155
+ return AbortablePromise$1.run(async (signal) => {
1156
+ const result = await this.http.postJson(wirePaths.layerSignatureComplete(this.docId, this.layerName, input.signingId), {
1157
+ cms: toBase64(input.cms),
1158
+ expectedVersion: input.expectedVersion
1159
+ }, (raw) => SignatureCompleteResultSchema.parse(raw), signal);
1160
+ await this.manifest.refresh(signal);
1161
+ if (result.status === "completed") {
1162
+ this.publisher.publishLocal({
1163
+ type: "signature.completed",
1164
+ signingId: input.signingId,
1165
+ ...result
1166
+ });
1167
+ this.publisher.publishLocal({
1168
+ type: "document.versioned",
1169
+ version: result.version
1170
+ });
1171
+ }
1172
+ return result;
1173
+ });
1174
+ }
1175
+ abort(signingId) {
1176
+ const rejected = this.closedRejection();
1177
+ if (rejected) return rejected;
1178
+ return AbortablePromise$1.run(async (signal) => {
1179
+ const result = await this.http.deleteJson(wirePaths.layerSignatureAbort(this.docId, this.layerName, signingId), (raw) => SignatureAbortResultSchema.parse(raw), signal);
1180
+ if (result.status === "aborted") this.publisher.publishLocal({
1181
+ type: "signature.aborted",
1182
+ signingId
1183
+ });
1184
+ return result;
1185
+ });
1186
+ }
1187
+ /** Version routes address a field by its fully qualified name; an object-number ref is resolved through the snapshot. */
1188
+ async fieldName(field, signal) {
1189
+ if (field.kind === "fqn") return field.name;
1190
+ const match = (await this.http.getJsonWithRefresh(async (s) => {
1191
+ const manifest = await this.manifest.get(s);
1192
+ return wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
1193
+ }, (raw) => SignatureSnapshotSchema.parse(raw), async (s) => {
1194
+ await this.manifest.refresh(s);
1195
+ }, signal)).signatures.find((s) => s.field.kind === "objectNumber" && s.field.fieldObjectNumber === field.fieldObjectNumber);
1196
+ if (!match) throw new EngineError$1(EngineErrorCode$1.NotFound, `no signature field #${field.fieldObjectNumber}`);
1197
+ return match.fieldName;
1198
+ }
1199
+ closedRejection() {
1200
+ if (!this.isClosed()) return null;
1201
+ return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
1202
+ }
1203
+ };
1204
+ //#endregion
992
1205
  //#region src/document/CloudMetadataService.ts
993
1206
  var CloudMetadataService = class {
994
1207
  constructor(http, docId, layerName, isClosed, manifest, publisher) {
@@ -1184,6 +1397,29 @@ var CloudPageAnnotationsService = class {
1184
1397
  return this.absorbMutation(result, "annotation.moved");
1185
1398
  });
1186
1399
  }
1400
+ flatten(refs, usage = "display") {
1401
+ if (this.isClosed()) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
1402
+ for (const r of refs) if (r.pageObjectNumber !== this.pageObjectNumber) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.InvalidArg, `flatten ref points at page ${r.pageObjectNumber}; service is bound to page ${this.pageObjectNumber}`));
1403
+ const path = wirePaths.layerPageAnnotationsFlatten(this.docId, this.layerName, this.pageObjectNumber);
1404
+ return AbortablePromise$1.run(async (signal) => {
1405
+ const result = await this.http.postJson(path, {
1406
+ refs,
1407
+ usage
1408
+ }, (raw) => AnnotationFlattenResultSchema.parse(raw), signal);
1409
+ if (result.meta === null) return result;
1410
+ this.manifest.apply(result.meta, ["content", "annotations"]);
1411
+ this.publisher.publishLocal({
1412
+ type: "annotations.flattened",
1413
+ ...result
1414
+ });
1415
+ return result;
1416
+ });
1417
+ }
1418
+ exportAppearance(refs) {
1419
+ if (this.isClosed()) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
1420
+ for (const r of refs) if (r.pageObjectNumber !== this.pageObjectNumber) return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.InvalidArg, `exportAppearance ref points at page ${r.pageObjectNumber}; service is bound to page ${this.pageObjectNumber}`));
1421
+ return AbortablePromise$1.run(async (signal) => this.http.postJsonBytes(wirePaths.layerPageAnnotationsAppearance(this.docId, this.layerName, this.pageObjectNumber), { refs }, signal));
1422
+ }
1187
1423
  /**
1188
1424
  * Patch the cached manifest, then publish the mutation to the document's
1189
1425
  * event stream (in that order — listeners reading the manifest in their
@@ -1513,7 +1749,8 @@ function auditRowToEvent(row, mySessionId) {
1513
1749
  origin,
1514
1750
  ...row.payload
1515
1751
  };
1516
- case "form.updateField": return {
1752
+ case "form.updateField":
1753
+ case "form.setSignatureAppearance": return {
1517
1754
  type: "form.fieldUpdated",
1518
1755
  origin,
1519
1756
  ...row.payload
@@ -1653,6 +1890,7 @@ var CloudDocumentHandle = class {
1653
1890
  _defineProperty(this, "annotations", void 0);
1654
1891
  _defineProperty(this, "actions", void 0);
1655
1892
  _defineProperty(this, "attachments", void 0);
1893
+ _defineProperty(this, "signatures", void 0);
1656
1894
  _defineProperty(this, "forms", void 0);
1657
1895
  _defineProperty(this, "search", void 0);
1658
1896
  _defineProperty(this, "pages", void 0);
@@ -1722,6 +1960,7 @@ var CloudDocumentHandle = class {
1722
1960
  this.annotations = new CloudDocumentAnnotationsService(http, id, layerName, () => this.closed, this.manifestAccessor);
1723
1961
  this.actions = new CloudDocumentActionsService(http, id, layerName, () => this.closed, this.manifestAccessor);
1724
1962
  this.attachments = new CloudDocumentAttachmentsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
1963
+ this.signatures = new CloudDocumentSignaturesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
1725
1964
  this.forms = new CloudDocumentFormsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
1726
1965
  this.search = new CloudDocumentSearchService(http, id, layerName, () => this.closed, this.manifestAccessor);
1727
1966
  this.pages = new CloudDocumentPagesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
@@ -1824,6 +2063,8 @@ var CloudDocumentHandle = class {
1824
2063
  ...this.manifestCache,
1825
2064
  docVersion: delta?.docVersion ?? this.manifestCache.docVersion,
1826
2065
  ...delta?.annotationsVersion !== void 0 ? { annotationsVersion: delta.annotationsVersion } : {},
2066
+ ...delta?.layerVersion !== void 0 ? { layerVersion: delta.layerVersion } : {},
2067
+ ...delta?.working !== void 0 ? { working: delta.working } : {},
1827
2068
  pages: Array.from(byPageObjectNumber.values()).sort((a, b) => a.state.pageObjectNumber - b.state.pageObjectNumber)
1828
2069
  };
1829
2070
  }