@verdocs/js-sdk 6.4.3 → 6.4.5
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.mts +38 -28
- package/dist/index.d.ts +38 -28
- package/dist/index.js +42 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -45
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +2 -3
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -268,51 +268,6 @@ function blobToBase64(image) {
|
|
|
268
268
|
function rescale(r, n) {
|
|
269
269
|
return r * n;
|
|
270
270
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Utility function to sort fields by page, then by Y coordinate, then by X coordinate.
|
|
273
|
-
* NOTE: This function mutates the input array.
|
|
274
|
-
*/
|
|
275
|
-
function sortFields(fields) {
|
|
276
|
-
fields.sort((a, b) => {
|
|
277
|
-
const aPage = a.page || 0;
|
|
278
|
-
const bPage = b.page || 0;
|
|
279
|
-
const aX = a.x || 0;
|
|
280
|
-
const aY = (a.y || 0) + (a.height || 0);
|
|
281
|
-
const bX = b.x || 0;
|
|
282
|
-
const bY = (b.y || 0) + (b.height || 0);
|
|
283
|
-
if (aPage !== bPage) {
|
|
284
|
-
return aPage - bPage;
|
|
285
|
-
}
|
|
286
|
-
// NOTE: Logic looks a little strange X vs Y. It's because we go top down,
|
|
287
|
-
// left to right. But Y coordinates are inverted in PDFs. The reason for
|
|
288
|
-
// the division is because no human makes perfect templates and frequently
|
|
289
|
-
// two fields on the "same line" will be slightly offset vertically.
|
|
290
|
-
const divaY = Math.floor(aY / 5);
|
|
291
|
-
const divbY = Math.floor(bY / 5);
|
|
292
|
-
if (divaY !== divbY) {
|
|
293
|
-
return divbY - divaY;
|
|
294
|
-
}
|
|
295
|
-
return aX - bX;
|
|
296
|
-
});
|
|
297
|
-
return fields;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Utility function to sort documents by their order, falling back to created_at.
|
|
301
|
-
* NOTE: This function mutates the input array.
|
|
302
|
-
*/
|
|
303
|
-
function sortDocuments(documents) {
|
|
304
|
-
return documents.sort((a, b) =>
|
|
305
|
-
// The Date conversion is unnecessary 90% of the time but is safer, and this isn't something
|
|
306
|
-
// we do much of so in reality it has almmost no impact.
|
|
307
|
-
a.order !== b.order ? a.order - b.order : new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Utility function to sort documents by their order, falling back to created_at.
|
|
311
|
-
* NOTE: This function mutates the input array.
|
|
312
|
-
*/
|
|
313
|
-
function sortRecipients(recipients) {
|
|
314
|
-
return recipients?.sort((a, b) => (a.sequence !== b.sequence ? b.sequence - a.sequence : b.order - a.order));
|
|
315
|
-
}
|
|
316
271
|
|
|
317
272
|
/**
|
|
318
273
|
* Given a File, extract the file's content as a base64 encoded data URL. The response will have a prefix that
|
|
@@ -1811,6 +1766,48 @@ const getEnvelopes = (endpoint, params) => endpoint.api //
|
|
|
1811
1766
|
*/
|
|
1812
1767
|
const getEnvelopesZip = (endpoint, envelope_ids) => endpoint.api //
|
|
1813
1768
|
.get(`/v2/envelopes/zip/${envelope_ids.join(',')}`, { responseType: 'blob', timeout: 120000 });
|
|
1769
|
+
/**
|
|
1770
|
+
* Utility function to sort fields by page, then by Y coordinate, then by X coordinate.
|
|
1771
|
+
* NOTE: This function mutates the input array.
|
|
1772
|
+
*/
|
|
1773
|
+
function sortFields(fields) {
|
|
1774
|
+
fields.sort((a, b) => {
|
|
1775
|
+
const aPage = a.page || 0;
|
|
1776
|
+
const bPage = b.page || 0;
|
|
1777
|
+
const aX = a.x || 0;
|
|
1778
|
+
const aY = (a.y || 0) + (a.height || 0);
|
|
1779
|
+
const bX = b.x || 0;
|
|
1780
|
+
const bY = (b.y || 0) + (b.height || 0);
|
|
1781
|
+
if (aPage !== bPage) {
|
|
1782
|
+
return aPage - bPage;
|
|
1783
|
+
}
|
|
1784
|
+
const divaY = Math.floor(aY / 5);
|
|
1785
|
+
const divbY = Math.floor(bY / 5);
|
|
1786
|
+
if (divaY !== divbY) {
|
|
1787
|
+
// Unlike the other properties, Y coordinates have 0,0 at the BOTTOM LEFT corner, so
|
|
1788
|
+
// we need to sort descending (b first) on this one.
|
|
1789
|
+
return divbY - divaY;
|
|
1790
|
+
}
|
|
1791
|
+
return aX - bX;
|
|
1792
|
+
});
|
|
1793
|
+
return fields;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Utility function to sort documents by their order, falling back to created_at.
|
|
1797
|
+
* NOTE: This function mutates the input array.
|
|
1798
|
+
*/
|
|
1799
|
+
function sortDocuments(documents) {
|
|
1800
|
+
// The Date conversion is unnecessary 90% of the time but is safer, and this isn't something
|
|
1801
|
+
// we do much of so in reality it has almmost no impact.
|
|
1802
|
+
return documents.sort((a, b) => a.order - b.order || new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Utility function to sort documents by their order, falling back to created_at.
|
|
1806
|
+
* NOTE: This function mutates the input array.
|
|
1807
|
+
*/
|
|
1808
|
+
function sortRecipients(recipients) {
|
|
1809
|
+
return recipients?.sort((a, b) => a.sequence - b.sequence || a.order - b.order);
|
|
1810
|
+
}
|
|
1814
1811
|
|
|
1815
1812
|
const canPerformTemplateAction = (profile, action, template) => {
|
|
1816
1813
|
if (!template && !action.includes('create')) {
|