@arbidocs/react 0.4.101 → 0.4.102

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.
@@ -300,8 +300,8 @@ var MarkupStoreError = class extends Error {
300
300
  status;
301
301
  };
302
302
  var detailOf = (error, fallback) => {
303
- const detail = error?.detail;
304
- return typeof detail === "string" ? detail : fallback;
303
+ const detail2 = error?.detail;
304
+ return typeof detail2 === "string" ? detail2 : fallback;
305
305
  };
306
306
  async function call(request) {
307
307
  try {
@@ -715,8 +715,8 @@ function isLegibleSignatureBox(rect) {
715
715
  var SIGNATURES_PATH = "/v1/document/{document_ext_id}/signatures";
716
716
  var SIGNATURES_KEY = ["get", SIGNATURES_PATH];
717
717
  function errorDetail(error, fallback) {
718
- const detail = error?.detail;
719
- return typeof detail === "string" ? detail : fallback;
718
+ const detail2 = error?.detail;
719
+ return typeof detail2 === "string" ? detail2 : fallback;
720
720
  }
721
721
  async function fetchDocumentSignatures(client, documentRef) {
722
722
  const { docId, version } = chunkT4IJHRRD_cjs.parseVersionRef(documentRef);
@@ -747,14 +747,14 @@ var SigningError = class extends Error {
747
747
  this.reason = reason;
748
748
  }
749
749
  };
750
- function signingErrorReason(detail) {
751
- if (/still being prepared/i.test(detail)) return "preparing";
752
- if (/no longer the current version/i.test(detail)) return "stale";
750
+ function signingErrorReason(detail2) {
751
+ if (/still being prepared/i.test(detail2)) return "preparing";
752
+ if (/no longer the current version/i.test(detail2)) return "stale";
753
753
  return "failed";
754
754
  }
755
755
  function signingError(error, fallback) {
756
- const detail = errorDetail(error, fallback);
757
- return new SigningError(detail, signingErrorReason(detail));
756
+ const detail2 = errorDetail(error, fallback);
757
+ return new SigningError(detail2, signingErrorReason(detail2));
758
758
  }
759
759
  var PREPARE_RETRIES = 3;
760
760
  var PREPARE_RETRY_DELAY_MS = 1500;
@@ -858,14 +858,269 @@ async function matchSignedCopy(file, verification) {
858
858
  const signature = verification.signatures.find((s) => s.sha256.toLowerCase() === hash);
859
859
  return signature ? { kind: "earlier", signature } : { kind: "none" };
860
860
  }
861
+ var SIGNATURE_FIELD_TYPES = [
862
+ "signature",
863
+ "initials",
864
+ "date",
865
+ "name"
866
+ ];
867
+ var FIELD_TYPE_LABELS = {
868
+ signature: "Signature",
869
+ initials: "Initials",
870
+ date: "Date signed",
871
+ name: "Name"
872
+ };
873
+ var DEFAULT_FIELD_SIZE = {
874
+ signature: { width: 0.28, height: 0.05 },
875
+ initials: { width: 0.1, height: 0.04 },
876
+ date: { width: 0.2, height: 0.03 },
877
+ name: { width: 0.28, height: 0.03 }
878
+ };
879
+ var MARK_FIELD_TYPES = ["signature", "initials"];
880
+ var REQUESTS_KEY = ["signature-requests"];
881
+ function detail(error, fallback) {
882
+ const d = error?.detail;
883
+ if (typeof d === "string") return d;
884
+ if (Array.isArray(d) && d[0] && typeof d[0] === "object" && "msg" in d[0]) {
885
+ return String(d[0].msg);
886
+ }
887
+ return fallback;
888
+ }
889
+ function newFieldId() {
890
+ return `f${Math.random().toString(36).slice(2, 10)}`;
891
+ }
892
+ function initialsOf(name) {
893
+ return name.split(/\s+/).filter(Boolean).map((part) => part[0].toUpperCase()).join("").slice(0, 4);
894
+ }
895
+ function fieldsInSigningOrder(fields, signer) {
896
+ return fields.filter((f) => f.signer === signer).sort((a, b) => a.page - b.page || a.y - b.y || a.x - b.x);
897
+ }
898
+ function sendBlocker(fields) {
899
+ if (fields.length === 0) return "Place at least one field.";
900
+ const signers = [...new Set(fields.map((f) => f.signer))];
901
+ for (const signer of signers) {
902
+ if (!fields.some((f) => f.signer === signer && MARK_FIELD_TYPES.includes(f.type))) {
903
+ return "Every signer needs a signature or initials field.";
904
+ }
905
+ }
906
+ return null;
907
+ }
908
+ function fieldsFromSuggestions(suggestions, assign) {
909
+ return suggestions.flatMap((s) => {
910
+ const signer = assign[s.group];
911
+ if (!signer) return [];
912
+ return [
913
+ {
914
+ id: newFieldId(),
915
+ type: s.type,
916
+ page: s.page,
917
+ x: s.x,
918
+ y: s.y,
919
+ width: s.width,
920
+ height: s.height,
921
+ signer,
922
+ required: true
923
+ }
924
+ ];
925
+ });
926
+ }
927
+ async function fetchDocumentSignatureRequests(client, documentId) {
928
+ const { data, error } = await client.GET("/v1/document/{document_ext_id}/signature-requests", {
929
+ params: { path: { document_ext_id: documentId } }
930
+ });
931
+ if (!data) throw new Error(detail(error, "The signature requests could not be read"));
932
+ return data;
933
+ }
934
+ function useDocumentSignatureRequests(documentId, enabled = true) {
935
+ const { client } = useDocumentTools();
936
+ return reactQuery.useQuery({
937
+ queryKey: [...REQUESTS_KEY, "document", documentId],
938
+ queryFn: () => fetchDocumentSignatureRequests(client, documentId),
939
+ enabled: enabled && !!documentId,
940
+ staleTime: 15e3
941
+ });
942
+ }
943
+ function useSignatureRequestsAwaitingMe(enabled = true) {
944
+ const { client } = useDocumentTools();
945
+ return reactQuery.useQuery({
946
+ queryKey: [...REQUESTS_KEY, "awaiting-me"],
947
+ queryFn: async () => {
948
+ const { data, error } = await client.GET("/v1/signature-requests", {
949
+ params: { query: { awaiting_me: true } }
950
+ });
951
+ if (!data) throw new Error(detail(error, "The signature requests could not be read"));
952
+ return data;
953
+ },
954
+ enabled,
955
+ staleTime: 15e3
956
+ });
957
+ }
958
+ function useSignatureRequest(requestId) {
959
+ const { client } = useDocumentTools();
960
+ return reactQuery.useQuery({
961
+ queryKey: [...REQUESTS_KEY, "one", requestId],
962
+ queryFn: async () => {
963
+ const { data, error } = await client.GET("/v1/signature-requests/{request_ext_id}", {
964
+ params: { path: { request_ext_id: requestId } }
965
+ });
966
+ if (!data) throw new Error(detail(error, "The signature request could not be read"));
967
+ return data;
968
+ },
969
+ enabled: !!requestId
970
+ });
971
+ }
972
+ async function suggestSignatureFields(client, documentId, version) {
973
+ const { data, error } = await client.GET(
974
+ "/v1/document/{document_ext_id}/signature-fields/suggest",
975
+ {
976
+ params: { path: { document_ext_id: documentId }, ...version ? { query: { version } } : {} }
977
+ }
978
+ );
979
+ if (!data) throw new Error(detail(error, "Signature blocks could not be read"));
980
+ return data.fields;
981
+ }
982
+ async function saveSignatureRequest(client, { documentId, version, fields, message, requestId, send }) {
983
+ if (!requestId) {
984
+ const { data, error } = await client.POST("/v1/document/{document_ext_id}/signature-requests", {
985
+ params: { path: { document_ext_id: documentId } },
986
+ body: { fields, message: message || null, send, ...version ? { version } : {} }
987
+ });
988
+ if (!data) throw new Error(detail(error, "The signature request could not be saved"));
989
+ return data;
990
+ }
991
+ const path = { request_ext_id: requestId };
992
+ const updated = await client.PATCH("/v1/signature-requests/{request_ext_id}", {
993
+ params: { path },
994
+ body: { fields, message: message ?? null }
995
+ });
996
+ if (!updated.data) throw new Error(detail(updated.error, "The draft could not be saved"));
997
+ if (!send) return updated.data;
998
+ const sent = await client.POST("/v1/signature-requests/{request_ext_id}/send", {
999
+ params: { path }
1000
+ });
1001
+ if (!sent.data) throw new Error(detail(sent.error, "The request could not be sent"));
1002
+ return sent.data;
1003
+ }
1004
+ function useInvalidateRequests() {
1005
+ const queryClient = reactQuery.useQueryClient();
1006
+ return () => queryClient.invalidateQueries({ queryKey: REQUESTS_KEY });
1007
+ }
1008
+ function useSaveSignatureRequest() {
1009
+ const { client } = useDocumentTools();
1010
+ const invalidate = useInvalidateRequests();
1011
+ return reactQuery.useMutation({
1012
+ mutationFn: (vars) => saveSignatureRequest(client, vars),
1013
+ onSuccess: invalidate
1014
+ });
1015
+ }
1016
+ function useVoidSignatureRequest() {
1017
+ const { client } = useDocumentTools();
1018
+ const invalidate = useInvalidateRequests();
1019
+ return reactQuery.useMutation({
1020
+ mutationFn: async (requestId) => {
1021
+ const { data, error } = await client.POST("/v1/signature-requests/{request_ext_id}/void", {
1022
+ params: { path: { request_ext_id: requestId } }
1023
+ });
1024
+ if (!data) throw new Error(detail(error, "The request could not be voided"));
1025
+ return data;
1026
+ },
1027
+ onSuccess: invalidate
1028
+ });
1029
+ }
1030
+ function useDeclineSignatureRequest() {
1031
+ const { client } = useDocumentTools();
1032
+ const invalidate = useInvalidateRequests();
1033
+ return reactQuery.useMutation({
1034
+ mutationFn: async ({ requestId, reason }) => {
1035
+ const { data, error } = await client.POST("/v1/signature-requests/{request_ext_id}/decline", {
1036
+ params: { path: { request_ext_id: requestId } },
1037
+ body: { reason: reason || null }
1038
+ });
1039
+ if (!data) throw new Error(detail(error, "Could not decline"));
1040
+ return data;
1041
+ },
1042
+ onSuccess: invalidate
1043
+ });
1044
+ }
1045
+ async function signSignatureRequest(client$1, deploymentDomain, { request, pdfBlob, email, password, adopted, fields }) {
1046
+ const path = { request_ext_id: request.external_id };
1047
+ const body = { adopted, fields };
1048
+ const prepared = await client$1.POST("/v1/signature-requests/{request_ext_id}/sign/prepare", {
1049
+ params: { path },
1050
+ body
1051
+ });
1052
+ if (!prepared.data) {
1053
+ throw new SigningError(detail(prepared.error, "Could not prepare signing"), "failed");
1054
+ }
1055
+ const { statement, intent, source_sha256, timestamp } = prepared.data;
1056
+ if (source_sha256 !== request.source_sha256 || await sha256Hex(pdfBlob) !== source_sha256) {
1057
+ throw new SigningError("The document changed since it was sent. Ask for it again.", "stale");
1058
+ }
1059
+ if (intent !== intentText({ name: adopted.name })) {
1060
+ throw new Error("Signing statement mismatch; not signed.");
1061
+ }
1062
+ const identity = await client.unlockIdentityWithPassword(email, password, deploymentDomain);
1063
+ const signed = await client$1.POST("/v1/signature-requests/{request_ext_id}/sign", {
1064
+ params: { path },
1065
+ body: { ...body, timestamp, signature: client.signMessage(statement, identity) }
1066
+ });
1067
+ if (!signed.data) throw new SigningError(detail(signed.error, "Signing failed"), "failed");
1068
+ return signed.data;
1069
+ }
1070
+ function useSignSignatureRequest() {
1071
+ const env = useDocumentTools();
1072
+ const invalidate = useInvalidateRequests();
1073
+ const queryClient = reactQuery.useQueryClient();
1074
+ return reactQuery.useMutation({
1075
+ mutationFn: (vars) => {
1076
+ if (!env.deploymentDomain) throw new Error("Signing is not set up: no deployment domain");
1077
+ return signSignatureRequest(env.client, env.deploymentDomain, vars);
1078
+ },
1079
+ onSuccess: async (result) => {
1080
+ await invalidate();
1081
+ if (result.completed && result.request.doc_ext_id) {
1082
+ await env.onDocumentsChanged?.([result.request.doc_ext_id], "signed");
1083
+ await queryClient.invalidateQueries({
1084
+ queryKey: ["get", "/v1/document/{document_ext_id}/signatures"]
1085
+ });
1086
+ }
1087
+ }
1088
+ });
1089
+ }
1090
+ function useSignerCandidates(enabled = true) {
1091
+ const { client, user } = useDocumentTools();
1092
+ return reactQuery.useQuery({
1093
+ queryKey: [...REQUESTS_KEY, "candidates"],
1094
+ queryFn: async () => {
1095
+ const { data, error } = await client.GET("/v1/workspace/users");
1096
+ if (!data) throw new Error(detail(error, "The workspace members could not be read"));
1097
+ const people = data.filter((m) => m.user.external_id.startsWith("usr-") && m.role !== "guest").map((m) => ({
1098
+ externalId: m.user.external_id,
1099
+ name: [m.user.given_name, m.user.family_name].filter(Boolean).join(" ") || m.user.email,
1100
+ email: m.user.email,
1101
+ role: String(m.role)
1102
+ }));
1103
+ const me = user?.email?.toLowerCase();
1104
+ return [...people].sort(
1105
+ (a, b) => Number(b.email.toLowerCase() === me) - Number(a.email.toLowerCase() === me)
1106
+ );
1107
+ },
1108
+ enabled,
1109
+ staleTime: 6e4
1110
+ });
1111
+ }
861
1112
 
1113
+ exports.DEFAULT_FIELD_SIZE = DEFAULT_FIELD_SIZE;
862
1114
  exports.DocumentFetchError = DocumentFetchError;
863
1115
  exports.DocumentToolsProvider = DocumentToolsProvider;
1116
+ exports.FIELD_TYPE_LABELS = FIELD_TYPE_LABELS;
864
1117
  exports.LEGACY_LAYER_PREFIX = LEGACY_LAYER_PREFIX;
1118
+ exports.MARK_FIELD_TYPES = MARK_FIELD_TYPES;
865
1119
  exports.MAX_MERGE_ATTEMPTS = MAX_MERGE_ATTEMPTS;
866
1120
  exports.MarkupDownloadError = MarkupDownloadError;
867
1121
  exports.MarkupStoreError = MarkupStoreError;
868
1122
  exports.PRODUCTIONS_FOLDER = PRODUCTIONS_FOLDER;
1123
+ exports.SIGNATURE_FIELD_TYPES = SIGNATURE_FIELD_TYPES;
869
1124
  exports.SIGNED_LOCKED_REASON = SIGNED_LOCKED_REASON;
870
1125
  exports.SIGNED_UNCHANGED = SIGNED_UNCHANGED;
871
1126
  exports.SignatureVerificationError = SignatureVerificationError;
@@ -883,13 +1138,17 @@ exports.defaultCertificateUrl = defaultCertificateUrl;
883
1138
  exports.downloadBlob = downloadBlob;
884
1139
  exports.fetchDocumentFile = fetchDocumentFile;
885
1140
  exports.fetchDocumentPdf = fetchDocumentPdf;
1141
+ exports.fetchDocumentSignatureRequests = fetchDocumentSignatureRequests;
886
1142
  exports.fetchDocumentSignatures = fetchDocumentSignatures;
887
1143
  exports.fetchMarkupPdf = fetchMarkupPdf;
888
1144
  exports.fetchProductionPdf = fetchProductionPdf;
889
1145
  exports.fetchSignatureVerification = fetchSignatureVerification;
1146
+ exports.fieldsFromSuggestions = fieldsFromSuggestions;
1147
+ exports.fieldsInSigningOrder = fieldsInSigningOrder;
890
1148
  exports.forgetLegacyLayer = forgetLegacyLayer;
891
1149
  exports.frozenCopyName = frozenCopyName;
892
1150
  exports.hasNoRendition = hasNoRendition;
1151
+ exports.initialsOf = initialsOf;
893
1152
  exports.intentText = intentText;
894
1153
  exports.isLegibleSignatureBox = isLegibleSignatureBox;
895
1154
  exports.isPdfDocument = isPdfDocument;
@@ -898,6 +1157,7 @@ exports.isSignedVersion = isSignedVersion;
898
1157
  exports.marksByVersion = marksByVersion;
899
1158
  exports.matchSignedCopy = matchSignedCopy;
900
1159
  exports.migrateLegacyLayer = migrateLegacyLayer;
1160
+ exports.newFieldId = newFieldId;
901
1161
  exports.openThreadsOf = openThreadsOf;
902
1162
  exports.productionDocumentName = productionDocumentName;
903
1163
  exports.productionFileName = productionFileName;
@@ -907,18 +1167,30 @@ exports.productionTitle = productionTitle;
907
1167
  exports.readLegacyLayer = readLegacyLayer;
908
1168
  exports.redactionLogName = redactionLogName;
909
1169
  exports.saveProductionFiles = saveProductionFiles;
1170
+ exports.saveSignatureRequest = saveSignatureRequest;
1171
+ exports.sendBlocker = sendBlocker;
910
1172
  exports.sha256Hex = sha256Hex;
911
1173
  exports.signDocument = signDocument;
1174
+ exports.signSignatureRequest = signSignatureRequest;
1175
+ exports.suggestSignatureFields = suggestSignatureFields;
912
1176
  exports.toAppearance = toAppearance;
913
1177
  exports.uploadFrozenCopy = uploadFrozenCopy;
914
1178
  exports.uploadQueryString = uploadQueryString;
1179
+ exports.useDeclineSignatureRequest = useDeclineSignatureRequest;
915
1180
  exports.useDocumentMarkup = useDocumentMarkup;
1181
+ exports.useDocumentSignatureRequests = useDocumentSignatureRequests;
916
1182
  exports.useDocumentSignatures = useDocumentSignatures;
917
1183
  exports.useDocumentTools = useDocumentTools;
918
1184
  exports.useIsOnline = useIsOnline;
919
1185
  exports.useOptionalDocumentTools = useOptionalDocumentTools;
1186
+ exports.useSaveSignatureRequest = useSaveSignatureRequest;
920
1187
  exports.useSignDocument = useSignDocument;
1188
+ exports.useSignSignatureRequest = useSignSignatureRequest;
1189
+ exports.useSignatureRequest = useSignatureRequest;
1190
+ exports.useSignatureRequestsAwaitingMe = useSignatureRequestsAwaitingMe;
921
1191
  exports.useSignatureVerification = useSignatureVerification;
1192
+ exports.useSignerCandidates = useSignerCandidates;
1193
+ exports.useVoidSignatureRequest = useVoidSignatureRequest;
922
1194
  exports.versionsWithMarkup = versionsWithMarkup;
923
1195
  //# sourceMappingURL=index.cjs.map
924
1196
  //# sourceMappingURL=index.cjs.map