@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.cjs +242 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +243 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -435,6 +435,24 @@ var CloudDocumentFormsService = class {
|
|
|
435
435
|
return this.absorbMutation(result, "form.fieldUpdated");
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
|
+
setSignatureAppearance(ref, appearance) {
|
|
439
|
+
const rejected = this.rejectIfClosed();
|
|
440
|
+
if (rejected) return rejected;
|
|
441
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
442
|
+
const bytes = new ArrayBuffer(appearance.pdf.byteLength);
|
|
443
|
+
new Uint8Array(bytes).set(appearance.pdf);
|
|
444
|
+
const form = buildMutationForm({
|
|
445
|
+
resource: "r0",
|
|
446
|
+
pageIndex: appearance.pageIndex ?? 0
|
|
447
|
+
}, { r0: {
|
|
448
|
+
bytes,
|
|
449
|
+
mimeType: "application/pdf",
|
|
450
|
+
name: "appearance.pdf"
|
|
451
|
+
} });
|
|
452
|
+
const result = await this.http.postMultipartJson(_embedpdf_engine_core_wire.wirePaths.layerFormFieldSignatureAppearance(this.docId, this.layerName, (0, _embedpdf_engine_core_runtime.encodeFieldRefKey)(ref)), form, (raw) => _embedpdf_engine_core_wire.FormFieldUpdateResultSchema.parse(raw), signal);
|
|
453
|
+
return this.absorbMutation(result, "form.fieldUpdated");
|
|
454
|
+
});
|
|
455
|
+
}
|
|
438
456
|
deleteField(ref) {
|
|
439
457
|
const rejected = this.rejectIfClosed();
|
|
440
458
|
if (rejected) return rejected;
|
|
@@ -560,6 +578,31 @@ var CloudDocumentPagesService = class {
|
|
|
560
578
|
return result;
|
|
561
579
|
});
|
|
562
580
|
}
|
|
581
|
+
setName(input) {
|
|
582
|
+
return this.runNameMutation(_embedpdf_engine_core_wire.wirePaths.layerPagesNames(this.docId, this.layerName), input, input.name, input.pageObjectNumber);
|
|
583
|
+
}
|
|
584
|
+
removeName(input) {
|
|
585
|
+
return this.runNameMutation(_embedpdf_engine_core_wire.wirePaths.layerPagesNamesDelete(this.docId, this.layerName), input, input.name, null);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Named pages are LAYOUT: both verbs share the page-move patch exactly —
|
|
589
|
+
* docVersion + layoutVersion advance, no per-page pin changes, so the
|
|
590
|
+
* cached manifest is patched in place and the fresh layout is published.
|
|
591
|
+
*/
|
|
592
|
+
runNameMutation(path, body, name, pageObjectNumber) {
|
|
593
|
+
if (this.isClosed()) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.DocNotOpen, `document ${this.docId} is closed`));
|
|
594
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
595
|
+
const result = await this.http.postJson(path, body, (raw) => _embedpdf_engine_core_wire.PageNameResultSchema.parse(raw), signal);
|
|
596
|
+
if (result.cache) this.manifest.applyPageStructure(result.cache);
|
|
597
|
+
this.publisher.publishLocal({
|
|
598
|
+
type: "pages.named",
|
|
599
|
+
name,
|
|
600
|
+
pageObjectNumber,
|
|
601
|
+
...result
|
|
602
|
+
});
|
|
603
|
+
return result;
|
|
604
|
+
});
|
|
605
|
+
}
|
|
563
606
|
rotate(pageObjectNumbers, rotation) {
|
|
564
607
|
if (this.isClosed()) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.DocNotOpen, `document ${this.docId} is closed`));
|
|
565
608
|
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
@@ -990,6 +1033,176 @@ function identityFromClaims(claims) {
|
|
|
990
1033
|
return Object.keys(out).length > 0 ? out : null;
|
|
991
1034
|
}
|
|
992
1035
|
//#endregion
|
|
1036
|
+
//#region src/document/CloudDocumentSignaturesService.ts
|
|
1037
|
+
/**
|
|
1038
|
+
* Cloud-side digital signatures. Two kinds of read, two kinds of URL:
|
|
1039
|
+
*
|
|
1040
|
+
* - The LAYER view (`list`, and `analyze` of the working copy) is pinned
|
|
1041
|
+
* by the manifest's `docVersion`, like every other layer read: a
|
|
1042
|
+
* signature is a layer state change, the immutable URL moves with it.
|
|
1043
|
+
* - Signed BYTES (`contents`, `digest`, `revisionBytes`, and `analyze`
|
|
1044
|
+
* of history) belong to a base VERSION and are content-addressed by
|
|
1045
|
+
* the manifest's `baseSha`: immutable forever, shared by every layer
|
|
1046
|
+
* and every caller.
|
|
1047
|
+
*
|
|
1048
|
+
* Signing is the server's two-phase protocol over the same wire shapes
|
|
1049
|
+
* the local engine uses. `prepare` and `complete` change the manifest in
|
|
1050
|
+
* ways no delta carries (a publish moves `baseSha` itself), so both
|
|
1051
|
+
* refresh it before returning.
|
|
1052
|
+
*/
|
|
1053
|
+
var CloudDocumentSignaturesService = class {
|
|
1054
|
+
constructor(http, docId, layerName, isClosed, manifest, publisher) {
|
|
1055
|
+
this.http = http;
|
|
1056
|
+
this.docId = docId;
|
|
1057
|
+
this.layerName = layerName;
|
|
1058
|
+
this.isClosed = isClosed;
|
|
1059
|
+
this.manifest = manifest;
|
|
1060
|
+
this.publisher = publisher;
|
|
1061
|
+
}
|
|
1062
|
+
list() {
|
|
1063
|
+
const rejected = this.closedRejection();
|
|
1064
|
+
if (rejected) return rejected;
|
|
1065
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => this.http.getJsonWithRefresh(async (s) => {
|
|
1066
|
+
const manifest = await this.manifest.get(s);
|
|
1067
|
+
return _embedpdf_engine_core_wire.wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
|
|
1068
|
+
}, (raw) => _embedpdf_engine_core_wire.SignatureSnapshotSchema.parse(raw), async (s) => {
|
|
1069
|
+
await this.manifest.refresh(s);
|
|
1070
|
+
}, signal));
|
|
1071
|
+
}
|
|
1072
|
+
contents(field) {
|
|
1073
|
+
const rejected = this.closedRejection();
|
|
1074
|
+
if (rejected) return rejected;
|
|
1075
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1076
|
+
const manifest = await this.manifest.get(signal);
|
|
1077
|
+
const name = await this.fieldName(field, signal);
|
|
1078
|
+
return this.http.getBytes(_embedpdf_engine_core_wire.wirePaths.docVersionSignatureContents(this.docId, manifest.baseSha, name), signal);
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
digest(field, algorithm) {
|
|
1082
|
+
const rejected = this.closedRejection();
|
|
1083
|
+
if (rejected) return rejected;
|
|
1084
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1085
|
+
const manifest = await this.manifest.get(signal);
|
|
1086
|
+
const name = await this.fieldName(field, signal);
|
|
1087
|
+
return this.http.getBytes(_embedpdf_engine_core_wire.wirePaths.docVersionSignatureDigest(this.docId, manifest.baseSha, name, algorithm), signal);
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
revisionBytes(revisionIndex) {
|
|
1091
|
+
const rejected = this.closedRejection();
|
|
1092
|
+
if (rejected) return rejected;
|
|
1093
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1094
|
+
const manifest = await this.manifest.get(signal);
|
|
1095
|
+
return this.http.getBytes(_embedpdf_engine_core_wire.wirePaths.docVersionRevision(this.docId, manifest.baseSha, revisionIndex), signal);
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* `until: 'working-copy'` (or unset while the layer holds edits) judges
|
|
1100
|
+
* the layer's pending edits against the base at the layer URL; anything
|
|
1101
|
+
* else is history of the base version and resolves at the version URL.
|
|
1102
|
+
*/
|
|
1103
|
+
analyze(input) {
|
|
1104
|
+
const rejected = this.closedRejection();
|
|
1105
|
+
if (rejected) return rejected;
|
|
1106
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1107
|
+
const manifest = await this.manifest.get(signal);
|
|
1108
|
+
if (input.until === "working-copy" || input.until === void 0 && manifest.working) return this.http.getJsonWithRefresh(async (s) => {
|
|
1109
|
+
const current = await this.manifest.get(s);
|
|
1110
|
+
return _embedpdf_engine_core_wire.wirePaths.layerSignaturesAnalysis(this.docId, this.layerName, {
|
|
1111
|
+
docVersion: current.docVersion,
|
|
1112
|
+
since: input.since,
|
|
1113
|
+
...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
|
|
1114
|
+
...input.detail !== void 0 ? { detail: input.detail } : {}
|
|
1115
|
+
});
|
|
1116
|
+
}, (raw) => _embedpdf_engine_core_wire.ChangeAnalysisSchema.parse(raw), async (s) => {
|
|
1117
|
+
await this.manifest.refresh(s);
|
|
1118
|
+
}, signal);
|
|
1119
|
+
return this.http.getJson(_embedpdf_engine_core_wire.wirePaths.docVersionAnalysis(this.docId, manifest.baseSha, {
|
|
1120
|
+
since: input.since,
|
|
1121
|
+
...typeof input.until === "object" ? { until: input.until.revisionIndex } : {},
|
|
1122
|
+
...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
|
|
1123
|
+
...input.detail !== void 0 ? { detail: input.detail } : {}
|
|
1124
|
+
}), (raw) => _embedpdf_engine_core_wire.ChangeAnalysisSchema.parse(raw), signal);
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
prepare(input) {
|
|
1128
|
+
const rejected = this.closedRejection();
|
|
1129
|
+
if (rejected) return rejected;
|
|
1130
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1131
|
+
const { appearance, ...rest } = input;
|
|
1132
|
+
const form = buildMutationForm({
|
|
1133
|
+
...rest,
|
|
1134
|
+
...appearance ? { appearance: {
|
|
1135
|
+
resource: "appearance",
|
|
1136
|
+
...appearance.pageIndex !== void 0 ? { pageIndex: appearance.pageIndex } : {}
|
|
1137
|
+
} } : {}
|
|
1138
|
+
}, appearance ? { appearance: {
|
|
1139
|
+
bytes: appearance.pdf.slice().buffer,
|
|
1140
|
+
mimeType: "application/pdf",
|
|
1141
|
+
name: "appearance.pdf"
|
|
1142
|
+
} } : {});
|
|
1143
|
+
const prepared = await this.http.postMultipartJson(_embedpdf_engine_core_wire.wirePaths.layerSignaturesPrepare(this.docId, this.layerName), form, (raw) => (0, _embedpdf_engine_core_wire.decodePrepared)(_embedpdf_engine_core_wire.SignaturePreparedWireSchema.parse(raw)), signal);
|
|
1144
|
+
await this.manifest.refresh(signal);
|
|
1145
|
+
this.publisher.publishLocal({
|
|
1146
|
+
type: "signature.prepared",
|
|
1147
|
+
signingId: prepared.signingId,
|
|
1148
|
+
field: input.field
|
|
1149
|
+
});
|
|
1150
|
+
return prepared;
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
complete(input) {
|
|
1154
|
+
const rejected = this.closedRejection();
|
|
1155
|
+
if (rejected) return rejected;
|
|
1156
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1157
|
+
const result = await this.http.postJson(_embedpdf_engine_core_wire.wirePaths.layerSignatureComplete(this.docId, this.layerName, input.signingId), {
|
|
1158
|
+
cms: (0, _embedpdf_engine_core_wire.toBase64)(input.cms),
|
|
1159
|
+
expectedVersion: input.expectedVersion
|
|
1160
|
+
}, (raw) => _embedpdf_engine_core_wire.SignatureCompleteResultSchema.parse(raw), signal);
|
|
1161
|
+
await this.manifest.refresh(signal);
|
|
1162
|
+
if (result.status === "completed") {
|
|
1163
|
+
this.publisher.publishLocal({
|
|
1164
|
+
type: "signature.completed",
|
|
1165
|
+
signingId: input.signingId,
|
|
1166
|
+
...result
|
|
1167
|
+
});
|
|
1168
|
+
this.publisher.publishLocal({
|
|
1169
|
+
type: "document.versioned",
|
|
1170
|
+
version: result.version
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
return result;
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
abort(signingId) {
|
|
1177
|
+
const rejected = this.closedRejection();
|
|
1178
|
+
if (rejected) return rejected;
|
|
1179
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1180
|
+
const result = await this.http.deleteJson(_embedpdf_engine_core_wire.wirePaths.layerSignatureAbort(this.docId, this.layerName, signingId), (raw) => _embedpdf_engine_core_wire.SignatureAbortResultSchema.parse(raw), signal);
|
|
1181
|
+
if (result.status === "aborted") this.publisher.publishLocal({
|
|
1182
|
+
type: "signature.aborted",
|
|
1183
|
+
signingId
|
|
1184
|
+
});
|
|
1185
|
+
return result;
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
/** Version routes address a field by its fully qualified name; an object-number ref is resolved through the snapshot. */
|
|
1189
|
+
async fieldName(field, signal) {
|
|
1190
|
+
if (field.kind === "fqn") return field.name;
|
|
1191
|
+
const match = (await this.http.getJsonWithRefresh(async (s) => {
|
|
1192
|
+
const manifest = await this.manifest.get(s);
|
|
1193
|
+
return _embedpdf_engine_core_wire.wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
|
|
1194
|
+
}, (raw) => _embedpdf_engine_core_wire.SignatureSnapshotSchema.parse(raw), async (s) => {
|
|
1195
|
+
await this.manifest.refresh(s);
|
|
1196
|
+
}, signal)).signatures.find((s) => s.field.kind === "objectNumber" && s.field.fieldObjectNumber === field.fieldObjectNumber);
|
|
1197
|
+
if (!match) throw new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.NotFound, `no signature field #${field.fieldObjectNumber}`);
|
|
1198
|
+
return match.fieldName;
|
|
1199
|
+
}
|
|
1200
|
+
closedRejection() {
|
|
1201
|
+
if (!this.isClosed()) return null;
|
|
1202
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.DocNotOpen, `document ${this.docId} is closed`));
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
//#endregion
|
|
993
1206
|
//#region src/document/CloudMetadataService.ts
|
|
994
1207
|
var CloudMetadataService = class {
|
|
995
1208
|
constructor(http, docId, layerName, isClosed, manifest, publisher) {
|
|
@@ -1185,6 +1398,29 @@ var CloudPageAnnotationsService = class {
|
|
|
1185
1398
|
return this.absorbMutation(result, "annotation.moved");
|
|
1186
1399
|
});
|
|
1187
1400
|
}
|
|
1401
|
+
flatten(refs, usage = "display") {
|
|
1402
|
+
if (this.isClosed()) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.DocNotOpen, `document ${this.docId} is closed`));
|
|
1403
|
+
for (const r of refs) if (r.pageObjectNumber !== this.pageObjectNumber) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.InvalidArg, `flatten ref points at page ${r.pageObjectNumber}; service is bound to page ${this.pageObjectNumber}`));
|
|
1404
|
+
const path = _embedpdf_engine_core_wire.wirePaths.layerPageAnnotationsFlatten(this.docId, this.layerName, this.pageObjectNumber);
|
|
1405
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => {
|
|
1406
|
+
const result = await this.http.postJson(path, {
|
|
1407
|
+
refs,
|
|
1408
|
+
usage
|
|
1409
|
+
}, (raw) => _embedpdf_engine_core_wire.AnnotationFlattenResultSchema.parse(raw), signal);
|
|
1410
|
+
if (result.meta === null) return result;
|
|
1411
|
+
this.manifest.apply(result.meta, ["content", "annotations"]);
|
|
1412
|
+
this.publisher.publishLocal({
|
|
1413
|
+
type: "annotations.flattened",
|
|
1414
|
+
...result
|
|
1415
|
+
});
|
|
1416
|
+
return result;
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
exportAppearance(refs) {
|
|
1420
|
+
if (this.isClosed()) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.DocNotOpen, `document ${this.docId} is closed`));
|
|
1421
|
+
for (const r of refs) if (r.pageObjectNumber !== this.pageObjectNumber) return _embedpdf_engine_core_runtime.AbortablePromise.rejectReason(new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.InvalidArg, `exportAppearance ref points at page ${r.pageObjectNumber}; service is bound to page ${this.pageObjectNumber}`));
|
|
1422
|
+
return _embedpdf_engine_core_runtime.AbortablePromise.run(async (signal) => this.http.postJsonBytes(_embedpdf_engine_core_wire.wirePaths.layerPageAnnotationsAppearance(this.docId, this.layerName, this.pageObjectNumber), { refs }, signal));
|
|
1423
|
+
}
|
|
1188
1424
|
/**
|
|
1189
1425
|
* Patch the cached manifest, then publish the mutation to the document's
|
|
1190
1426
|
* event stream (in that order — listeners reading the manifest in their
|
|
@@ -1514,7 +1750,8 @@ function auditRowToEvent(row, mySessionId) {
|
|
|
1514
1750
|
origin,
|
|
1515
1751
|
...row.payload
|
|
1516
1752
|
};
|
|
1517
|
-
case "form.updateField":
|
|
1753
|
+
case "form.updateField":
|
|
1754
|
+
case "form.setSignatureAppearance": return {
|
|
1518
1755
|
type: "form.fieldUpdated",
|
|
1519
1756
|
origin,
|
|
1520
1757
|
...row.payload
|
|
@@ -1654,6 +1891,7 @@ var CloudDocumentHandle = class {
|
|
|
1654
1891
|
_defineProperty(this, "annotations", void 0);
|
|
1655
1892
|
_defineProperty(this, "actions", void 0);
|
|
1656
1893
|
_defineProperty(this, "attachments", void 0);
|
|
1894
|
+
_defineProperty(this, "signatures", void 0);
|
|
1657
1895
|
_defineProperty(this, "forms", void 0);
|
|
1658
1896
|
_defineProperty(this, "search", void 0);
|
|
1659
1897
|
_defineProperty(this, "pages", void 0);
|
|
@@ -1723,6 +1961,7 @@ var CloudDocumentHandle = class {
|
|
|
1723
1961
|
this.annotations = new CloudDocumentAnnotationsService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1724
1962
|
this.actions = new CloudDocumentActionsService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1725
1963
|
this.attachments = new CloudDocumentAttachmentsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
1964
|
+
this.signatures = new CloudDocumentSignaturesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
1726
1965
|
this.forms = new CloudDocumentFormsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
1727
1966
|
this.search = new CloudDocumentSearchService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1728
1967
|
this.pages = new CloudDocumentPagesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
@@ -1825,6 +2064,8 @@ var CloudDocumentHandle = class {
|
|
|
1825
2064
|
...this.manifestCache,
|
|
1826
2065
|
docVersion: delta?.docVersion ?? this.manifestCache.docVersion,
|
|
1827
2066
|
...delta?.annotationsVersion !== void 0 ? { annotationsVersion: delta.annotationsVersion } : {},
|
|
2067
|
+
...delta?.layerVersion !== void 0 ? { layerVersion: delta.layerVersion } : {},
|
|
2068
|
+
...delta?.working !== void 0 ? { working: delta.working } : {},
|
|
1828
2069
|
pages: Array.from(byPageObjectNumber.values()).sort((a, b) => a.state.pageObjectNumber - b.state.pageObjectNumber)
|
|
1829
2070
|
};
|
|
1830
2071
|
}
|