@cloudpdf/engine 3.0.0-next.12 → 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 +194 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +195 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
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;
|
|
@@ -1015,6 +1033,176 @@ function identityFromClaims(claims) {
|
|
|
1015
1033
|
return Object.keys(out).length > 0 ? out : null;
|
|
1016
1034
|
}
|
|
1017
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
|
|
1018
1206
|
//#region src/document/CloudMetadataService.ts
|
|
1019
1207
|
var CloudMetadataService = class {
|
|
1020
1208
|
constructor(http, docId, layerName, isClosed, manifest, publisher) {
|
|
@@ -1562,7 +1750,8 @@ function auditRowToEvent(row, mySessionId) {
|
|
|
1562
1750
|
origin,
|
|
1563
1751
|
...row.payload
|
|
1564
1752
|
};
|
|
1565
|
-
case "form.updateField":
|
|
1753
|
+
case "form.updateField":
|
|
1754
|
+
case "form.setSignatureAppearance": return {
|
|
1566
1755
|
type: "form.fieldUpdated",
|
|
1567
1756
|
origin,
|
|
1568
1757
|
...row.payload
|
|
@@ -1702,6 +1891,7 @@ var CloudDocumentHandle = class {
|
|
|
1702
1891
|
_defineProperty(this, "annotations", void 0);
|
|
1703
1892
|
_defineProperty(this, "actions", void 0);
|
|
1704
1893
|
_defineProperty(this, "attachments", void 0);
|
|
1894
|
+
_defineProperty(this, "signatures", void 0);
|
|
1705
1895
|
_defineProperty(this, "forms", void 0);
|
|
1706
1896
|
_defineProperty(this, "search", void 0);
|
|
1707
1897
|
_defineProperty(this, "pages", void 0);
|
|
@@ -1771,6 +1961,7 @@ var CloudDocumentHandle = class {
|
|
|
1771
1961
|
this.annotations = new CloudDocumentAnnotationsService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1772
1962
|
this.actions = new CloudDocumentActionsService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1773
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);
|
|
1774
1965
|
this.forms = new CloudDocumentFormsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
1775
1966
|
this.search = new CloudDocumentSearchService(http, id, layerName, () => this.closed, this.manifestAccessor);
|
|
1776
1967
|
this.pages = new CloudDocumentPagesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
|
|
@@ -1873,6 +2064,8 @@ var CloudDocumentHandle = class {
|
|
|
1873
2064
|
...this.manifestCache,
|
|
1874
2065
|
docVersion: delta?.docVersion ?? this.manifestCache.docVersion,
|
|
1875
2066
|
...delta?.annotationsVersion !== void 0 ? { annotationsVersion: delta.annotationsVersion } : {},
|
|
2067
|
+
...delta?.layerVersion !== void 0 ? { layerVersion: delta.layerVersion } : {},
|
|
2068
|
+
...delta?.working !== void 0 ? { working: delta.working } : {},
|
|
1876
2069
|
pages: Array.from(byPageObjectNumber.values()).sort((a, b) => a.state.pageObjectNumber - b.state.pageObjectNumber)
|
|
1877
2070
|
};
|
|
1878
2071
|
}
|