@verdocs/js-sdk 4.1.14 → 4.1.15
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 +76 -45
- package/dist/index.d.ts +76 -45
- package/dist/index.js +89 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -57
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1501,11 +1501,11 @@ const deleteEnvelopeReminder = (endpoint, envelopeId, reminderId) => endpoint.ap
|
|
|
1501
1501
|
/**
|
|
1502
1502
|
* Check to see if the user owns the envelope.
|
|
1503
1503
|
*/
|
|
1504
|
-
const userIsEnvelopeOwner = (
|
|
1504
|
+
const userIsEnvelopeOwner = (profile, envelope) => envelope.profile_id === profile?.id;
|
|
1505
1505
|
/**
|
|
1506
1506
|
* Check to see if the user owns the envelope.
|
|
1507
1507
|
*/
|
|
1508
|
-
const userIsEnvelopeRecipient = (
|
|
1508
|
+
const userIsEnvelopeRecipient = (profile, envelope) => envelope.profile_id === profile?.id;
|
|
1509
1509
|
/**
|
|
1510
1510
|
* Check to see if the envelope has pending actions.
|
|
1511
1511
|
*/
|
|
@@ -1517,14 +1517,14 @@ const envelopeIsComplete = (envelope) => envelope.status !== 'complete';
|
|
|
1517
1517
|
/**
|
|
1518
1518
|
* Check to see if the user owns the envelope.
|
|
1519
1519
|
*/
|
|
1520
|
-
const userCanCancelEnvelope = (
|
|
1520
|
+
const userCanCancelEnvelope = (profile, envelope) => userIsEnvelopeOwner(profile, envelope) &&
|
|
1521
1521
|
envelope.status !== 'complete' &&
|
|
1522
1522
|
envelope.status !== 'declined' &&
|
|
1523
1523
|
envelope.status !== 'canceled';
|
|
1524
1524
|
/**
|
|
1525
1525
|
* Check to see if the user owns the envelope.
|
|
1526
1526
|
*/
|
|
1527
|
-
const userCanFinishEnvelope = (
|
|
1527
|
+
const userCanFinishEnvelope = (profile, envelope) => userIsEnvelopeOwner(profile, envelope) &&
|
|
1528
1528
|
envelope.status !== 'complete' &&
|
|
1529
1529
|
envelope.status !== 'declined' &&
|
|
1530
1530
|
envelope.status !== 'canceled';
|
|
@@ -1550,15 +1550,15 @@ const userCanAct = (email, recipientsWithActions) => {
|
|
|
1550
1550
|
/**
|
|
1551
1551
|
* Returns true if the user can act.
|
|
1552
1552
|
*/
|
|
1553
|
-
const userCanSignNow = (
|
|
1554
|
-
if (!
|
|
1553
|
+
const userCanSignNow = (profile, envelope) => {
|
|
1554
|
+
if (!profile) {
|
|
1555
1555
|
return false;
|
|
1556
1556
|
}
|
|
1557
1557
|
const recipientsWithActions = getRecipientsWithActions(envelope);
|
|
1558
|
-
const myRecipient = recipientsWithActions.find((r) => r.profile_id ===
|
|
1558
|
+
const myRecipient = recipientsWithActions.find((r) => r.profile_id === profile?.id || r.email === profile?.email);
|
|
1559
1559
|
return (myRecipient &&
|
|
1560
1560
|
envelopeIsActive(envelope) &&
|
|
1561
|
-
userIsEnvelopeRecipient(
|
|
1561
|
+
userIsEnvelopeRecipient(profile, envelope) &&
|
|
1562
1562
|
recipientCanAct(myRecipient, recipientsWithActions));
|
|
1563
1563
|
};
|
|
1564
1564
|
const getNextRecipient = (envelope) => {
|
|
@@ -1614,9 +1614,9 @@ const deleteSignature = (endpoint, signatureId) => endpoint.api //
|
|
|
1614
1614
|
* Get a list of keys for a given organization. The caller must have admin access to the organization.
|
|
1615
1615
|
*
|
|
1616
1616
|
* ```typescript
|
|
1617
|
-
* import {
|
|
1617
|
+
* import {getApiKeys} from '@verdocs/js-sdk';
|
|
1618
1618
|
*
|
|
1619
|
-
* const keys = await
|
|
1619
|
+
* const keys = await getApiKeys(ORGID);
|
|
1620
1620
|
* ```
|
|
1621
1621
|
*/
|
|
1622
1622
|
const getApiKeys = (endpoint) => endpoint.api //
|
|
@@ -1626,9 +1626,9 @@ const getApiKeys = (endpoint) => endpoint.api //
|
|
|
1626
1626
|
* Create an API key.
|
|
1627
1627
|
*
|
|
1628
1628
|
* ```typescript
|
|
1629
|
-
* import {
|
|
1629
|
+
* import {createApiKey} from '@verdocs/js-sdk';
|
|
1630
1630
|
*
|
|
1631
|
-
* await
|
|
1631
|
+
* await createApiKey(ORGID, {name: NEWNAME});
|
|
1632
1632
|
* ```
|
|
1633
1633
|
*/
|
|
1634
1634
|
const createApiKey = (endpoint, params) => endpoint.api //
|
|
@@ -1638,9 +1638,9 @@ const createApiKey = (endpoint, params) => endpoint.api //
|
|
|
1638
1638
|
* Rotate the secret for an API key. The caller must have admin access to the organization.
|
|
1639
1639
|
*
|
|
1640
1640
|
* ```typescript
|
|
1641
|
-
* import {
|
|
1641
|
+
* import {rotateApiKey} from '@verdocs/js-sdk';
|
|
1642
1642
|
*
|
|
1643
|
-
* const {client_secret: newSecret} = await
|
|
1643
|
+
* const {client_secret: newSecret} = await rotateApiKey(ORGID, CLIENTID);
|
|
1644
1644
|
* ```
|
|
1645
1645
|
*/
|
|
1646
1646
|
const rotateApiKey = (endpoint, clientId) => endpoint.api //
|
|
@@ -1650,9 +1650,9 @@ const rotateApiKey = (endpoint, clientId) => endpoint.api //
|
|
|
1650
1650
|
* Update an API key to change its assigned Profile ID or Name.
|
|
1651
1651
|
*
|
|
1652
1652
|
* ```typescript
|
|
1653
|
-
* import {
|
|
1653
|
+
* import {updateApiKey} from '@verdocs/js-sdk';
|
|
1654
1654
|
*
|
|
1655
|
-
* await
|
|
1655
|
+
* await updateApiKey(ORGID, CLIENTID, {name: NEWNAME});
|
|
1656
1656
|
* ```
|
|
1657
1657
|
*/
|
|
1658
1658
|
const updateApiKey = (endpoint, clientId, params) => endpoint.api //
|
|
@@ -1662,9 +1662,9 @@ const updateApiKey = (endpoint, clientId, params) => endpoint.api //
|
|
|
1662
1662
|
* Delete an API key.
|
|
1663
1663
|
*
|
|
1664
1664
|
* ```typescript
|
|
1665
|
-
* import {
|
|
1665
|
+
* import {deleteApiKey} from '@verdocs/js-sdk';
|
|
1666
1666
|
*
|
|
1667
|
-
* await
|
|
1667
|
+
* await deleteApiKey(ORGID, CLIENTID);
|
|
1668
1668
|
* ```
|
|
1669
1669
|
*/
|
|
1670
1670
|
const deleteApiKey = (endpoint, clientId) => endpoint.api //
|
|
@@ -1788,19 +1788,37 @@ const declineOrganizationInvitation = (endpoint, email, token) => endpoint.api /
|
|
|
1788
1788
|
*/
|
|
1789
1789
|
/**
|
|
1790
1790
|
* Get a list of the members in the caller's organization.
|
|
1791
|
+
*
|
|
1792
|
+
* ```typescript
|
|
1793
|
+
* import {getOrganizationMembers} from '@verdocs/js-sdk';
|
|
1794
|
+
*
|
|
1795
|
+
* const members = await deleteOrganizationMember(VerdocsEndpoint.getDefault()});
|
|
1796
|
+
* ```
|
|
1791
1797
|
*/
|
|
1792
1798
|
const getOrganizationMembers = (endpoint) => endpoint.api //
|
|
1793
1799
|
.get(`/v2/organization-members`)
|
|
1794
1800
|
.then((r) => r.data);
|
|
1795
1801
|
/**
|
|
1796
1802
|
* Delete a member from the caller's organization. Note that the caller must be an admin or owner,
|
|
1797
|
-
* may not delete him/herself
|
|
1803
|
+
* may not delete him/herself.
|
|
1804
|
+
*
|
|
1805
|
+
* ```typescript
|
|
1806
|
+
* import {deleteOrganizationMember} from '@verdocs/js-sdk';
|
|
1807
|
+
*
|
|
1808
|
+
* await deleteOrganizationMember(VerdocsEndpoint.getDefault(), 'PROFILEID'});
|
|
1809
|
+
* ```
|
|
1798
1810
|
*/
|
|
1799
1811
|
const deleteOrganizationMember = (endpoint, profileId) => endpoint.api //
|
|
1800
1812
|
.delete(`/v2/organization-members/${profileId}`)
|
|
1801
1813
|
.then((r) => r.data);
|
|
1802
1814
|
/**
|
|
1803
1815
|
* Update a member.
|
|
1816
|
+
*
|
|
1817
|
+
* ```typescript
|
|
1818
|
+
* import {updateOrganizationMember} from '@verdocs/js-sdk';
|
|
1819
|
+
*
|
|
1820
|
+
* const result = await updateOrganizationMember(VerdocsEndpoint.getDefault(), 'PROFILEID', {roles:['member']});
|
|
1821
|
+
* ```
|
|
1804
1822
|
*/
|
|
1805
1823
|
const updateOrganizationMember = (endpoint, profileId, params) => endpoint.api //
|
|
1806
1824
|
.patch(`/v2/organization-members/${profileId}`, params)
|
|
@@ -1898,13 +1916,27 @@ const updateOrganizationThumbnail = (endpoint, organizationId, file, onUploadPro
|
|
|
1898
1916
|
* @module
|
|
1899
1917
|
*/
|
|
1900
1918
|
/**
|
|
1901
|
-
* Get the registered
|
|
1919
|
+
* Get the registered Webhook configuration for the caller's organization.
|
|
1920
|
+
*
|
|
1921
|
+
* ```typescript
|
|
1922
|
+
* import {getWebhooks} from '@verdocs/js-sdk';
|
|
1923
|
+
*
|
|
1924
|
+
* await getWebhooks(ORGID, params);
|
|
1925
|
+
* ```
|
|
1902
1926
|
*/
|
|
1903
1927
|
const getWebhooks = (endpoint) => endpoint.api //
|
|
1904
1928
|
.get(`/v2/webhooks/organization`)
|
|
1905
1929
|
.then((r) => r.data);
|
|
1906
1930
|
/**
|
|
1907
|
-
* Update the registered
|
|
1931
|
+
* Update the registered Webhook configuration for the caller's organization. Note that
|
|
1932
|
+
* Webhooks cannot currently be deleted, but may be easily disabled by setting `active`
|
|
1933
|
+
* to `false` and/or setting the `url` to an empty string.
|
|
1934
|
+
*
|
|
1935
|
+
* ```typescript
|
|
1936
|
+
* import {setWebhooks} from '@verdocs/js-sdk';
|
|
1937
|
+
*
|
|
1938
|
+
* await setWebhooks(ORGID, params);
|
|
1939
|
+
* ```
|
|
1908
1940
|
*/
|
|
1909
1941
|
const setWebhooks = (endpoint, params) => endpoint.api //
|
|
1910
1942
|
.patch(`/v2/webhooks/organization`, params)
|
|
@@ -1913,16 +1945,16 @@ const setWebhooks = (endpoint, params) => endpoint.api //
|
|
|
1913
1945
|
/**
|
|
1914
1946
|
* Confirm whether the user has all of the specified permissions.
|
|
1915
1947
|
*/
|
|
1916
|
-
const userHasPermissions = (
|
|
1948
|
+
const userHasPermissions = (profile, permissions) => permissions.every((perm) => (profile?.permissions || []).includes(perm));
|
|
1917
1949
|
|
|
1918
|
-
const canPerformTemplateAction = (
|
|
1950
|
+
const canPerformTemplateAction = (profile, action, template) => {
|
|
1919
1951
|
if (!template && !action.includes('create')) {
|
|
1920
1952
|
return { canPerform: false, message: 'Missing required template object' };
|
|
1921
1953
|
}
|
|
1922
1954
|
// We use BOGUS here to force the option-chain in things like template?.profile_id to NOT match profile?.profile_id because if both
|
|
1923
1955
|
// were undefined, they would actually match.
|
|
1924
|
-
const profile_id =
|
|
1925
|
-
const organization_id =
|
|
1956
|
+
const profile_id = profile?.id || 'BOGUS';
|
|
1957
|
+
const organization_id = profile?.organization_id || 'BOGUS';
|
|
1926
1958
|
if (!profile_id) {
|
|
1927
1959
|
return { canPerform: false, message: 'Active session required' };
|
|
1928
1960
|
}
|
|
@@ -1990,12 +2022,12 @@ const canPerformTemplateAction = (session, action, template) => {
|
|
|
1990
2022
|
default:
|
|
1991
2023
|
return { canPerform: false, message: 'Action is not defined' };
|
|
1992
2024
|
}
|
|
1993
|
-
if (hasRequiredPermissions(
|
|
2025
|
+
if (hasRequiredPermissions(profile, permissionsRequired)) {
|
|
1994
2026
|
return { canPerform: true, message: '' };
|
|
1995
2027
|
}
|
|
1996
2028
|
return { canPerform: false, message: `Insufficient access to perform '${action}'. Needed permissions: ${permissionsRequired.toString()}` };
|
|
1997
2029
|
};
|
|
1998
|
-
const hasRequiredPermissions = (
|
|
2030
|
+
const hasRequiredPermissions = (profile, permissions) => permissions.every((perm) => (profile?.permissions || []).includes(perm));
|
|
1999
2031
|
|
|
2000
2032
|
/**
|
|
2001
2033
|
* Add a field to a template.
|
|
@@ -2024,72 +2056,72 @@ const deleteField = (endpoint, templateId, fieldName) => endpoint.api //
|
|
|
2024
2056
|
/**
|
|
2025
2057
|
* Check to see if the user created the template.
|
|
2026
2058
|
*/
|
|
2027
|
-
const userIsTemplateCreator = (
|
|
2059
|
+
const userIsTemplateCreator = (profile, template) => profile && template && profile.id === template.profile_id;
|
|
2028
2060
|
/**
|
|
2029
2061
|
* Check to see if a template is "shared" with the user.
|
|
2030
2062
|
*/
|
|
2031
|
-
const userHasSharedTemplate = (
|
|
2063
|
+
const userHasSharedTemplate = (profile, template) => profile && template && !template.is_personal && profile.organization_id === template.organization_id;
|
|
2032
2064
|
/**
|
|
2033
2065
|
* Check to see if the user can create a personal/private template.
|
|
2034
2066
|
*/
|
|
2035
|
-
const userCanCreatePersonalTemplate = (
|
|
2067
|
+
const userCanCreatePersonalTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:personal']);
|
|
2036
2068
|
/**
|
|
2037
2069
|
* Check to see if the user can create an org-shared template.
|
|
2038
2070
|
*/
|
|
2039
|
-
const userCanCreateOrgTemplate = (
|
|
2071
|
+
const userCanCreateOrgTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:org']);
|
|
2040
2072
|
/**
|
|
2041
2073
|
* Check to see if the user can create a public template.
|
|
2042
2074
|
*/
|
|
2043
|
-
const userCanCreatePublicTemplate = (
|
|
2075
|
+
const userCanCreatePublicTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:public']);
|
|
2044
2076
|
/**
|
|
2045
2077
|
* Check to see if the user can read/view a template.
|
|
2046
2078
|
*/
|
|
2047
|
-
const userCanReadTemplate = (
|
|
2048
|
-
userIsTemplateCreator(
|
|
2049
|
-
(userHasSharedTemplate(
|
|
2079
|
+
const userCanReadTemplate = (profile, template) => template.is_public ||
|
|
2080
|
+
userIsTemplateCreator(profile, template) ||
|
|
2081
|
+
(userHasSharedTemplate(profile, template) && userHasPermissions(profile, ['template:member:read']));
|
|
2050
2082
|
/**
|
|
2051
2083
|
* Check to see if the user can update a tempate.
|
|
2052
2084
|
*/
|
|
2053
|
-
const userCanUpdateTemplate = (
|
|
2054
|
-
(userHasSharedTemplate(
|
|
2085
|
+
const userCanUpdateTemplate = (profile, template) => userIsTemplateCreator(profile, template) ||
|
|
2086
|
+
(userHasSharedTemplate(profile, template) && userHasPermissions(profile, ['template:member:read', 'template:member:write']));
|
|
2055
2087
|
/**
|
|
2056
2088
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2057
2089
|
*/
|
|
2058
|
-
const userCanMakeTemplatePrivate = (
|
|
2059
|
-
? userHasPermissions(
|
|
2060
|
-
: userHasPermissions(
|
|
2090
|
+
const userCanMakeTemplatePrivate = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2091
|
+
? userHasPermissions(profile, ['template:creator:create:personal'])
|
|
2092
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2061
2093
|
/**
|
|
2062
2094
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2063
2095
|
*/
|
|
2064
|
-
const userCanMakeTemplateShared = (
|
|
2065
|
-
? userHasPermissions(
|
|
2066
|
-
: userHasPermissions(
|
|
2096
|
+
const userCanMakeTemplateShared = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2097
|
+
? userHasPermissions(profile, ['template:creator:create:org'])
|
|
2098
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2067
2099
|
/**
|
|
2068
2100
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2069
2101
|
*/
|
|
2070
|
-
const userCanMakeTemplatePublic = (
|
|
2071
|
-
? userHasPermissions(
|
|
2072
|
-
: userHasPermissions(
|
|
2102
|
+
const userCanMakeTemplatePublic = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2103
|
+
? userHasPermissions(profile, ['template:creator:create:public'])
|
|
2104
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2073
2105
|
/**
|
|
2074
2106
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2075
2107
|
*/
|
|
2076
|
-
const userCanChangeOrgVisibility = (
|
|
2108
|
+
const userCanChangeOrgVisibility = (profile, template) => userIsTemplateCreator(profile, template) && userHasPermissions(profile, ['template:creator:create:personal']);
|
|
2077
2109
|
/**
|
|
2078
2110
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2079
2111
|
*/
|
|
2080
|
-
const userCanDeleteTemplate = (
|
|
2081
|
-
? userHasPermissions(
|
|
2082
|
-
: userHasPermissions(
|
|
2112
|
+
const userCanDeleteTemplate = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2113
|
+
? userHasPermissions(profile, ['template:creator:delete'])
|
|
2114
|
+
: userHasPermissions(profile, ['template:member:delete']);
|
|
2083
2115
|
/**
|
|
2084
2116
|
* Confirm whether the user can create an envelope using the specified template.
|
|
2085
2117
|
*/
|
|
2086
|
-
const userCanSendTemplate = (
|
|
2118
|
+
const userCanSendTemplate = (profile, template) => {
|
|
2087
2119
|
switch (template.sender) {
|
|
2088
2120
|
case 'creator':
|
|
2089
|
-
return userIsTemplateCreator(
|
|
2121
|
+
return userIsTemplateCreator(profile, template);
|
|
2090
2122
|
case 'organization_member':
|
|
2091
2123
|
case 'organization_member_as_creator':
|
|
2092
|
-
return userIsTemplateCreator(
|
|
2124
|
+
return userIsTemplateCreator(profile, template) || template.organization_id === profile?.organization_id;
|
|
2093
2125
|
default:
|
|
2094
2126
|
return true;
|
|
2095
2127
|
}
|
|
@@ -2097,19 +2129,19 @@ const userCanSendTemplate = (session, template) => {
|
|
|
2097
2129
|
/**
|
|
2098
2130
|
* Confirm whether the user can create a new template.
|
|
2099
2131
|
*/
|
|
2100
|
-
const userCanCreateTemplate = (
|
|
2132
|
+
const userCanCreateTemplate = (profile) => userCanCreatePersonalTemplate(profile) || userCanCreateOrgTemplate(profile) || userCanCreatePublicTemplate(profile);
|
|
2101
2133
|
/**
|
|
2102
2134
|
* Check to see if the user can "build" the template (use the field builder). The user must have write access to the
|
|
2103
2135
|
* template, and the template must have at least one signer role.
|
|
2104
2136
|
*/
|
|
2105
|
-
const userCanBuildTemplate = (
|
|
2137
|
+
const userCanBuildTemplate = (profile, template) => userCanUpdateTemplate(profile, template) && (template.roles || []).filter((role) => role.type === 'signer').length > 0;
|
|
2106
2138
|
const getFieldsForRole = (template, role_name) => (template.fields || []).filter((field) => field.role_name === role_name);
|
|
2107
2139
|
/**
|
|
2108
2140
|
* Check to see if the user can preview the template. The user must have read access to the template, the template must
|
|
2109
2141
|
* have at least one signer, and every signer must have at least one field.
|
|
2110
2142
|
*/
|
|
2111
|
-
const userCanPreviewTemplate = (
|
|
2112
|
-
const hasPermission = userCanReadTemplate(
|
|
2143
|
+
const userCanPreviewTemplate = (profile, template) => {
|
|
2144
|
+
const hasPermission = userCanReadTemplate(profile, template);
|
|
2113
2145
|
const signers = (template.roles || []).filter((role) => role.type === 'signer');
|
|
2114
2146
|
return hasPermission && signers.length > 0 && signers.every((signer) => getFieldsForRole(template, signer.name).length > 0);
|
|
2115
2147
|
};
|