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