@assinafy/cli 2.6.1 → 2.7.1
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/CONTRIBUTING.md +1 -1
- package/README.en.md +50 -20
- package/README.md +78 -391
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/api.cjs +221 -37
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +220 -37
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +352 -75
- package/dist/types/api/client.d.ts +2 -0
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api/contract-types.d.ts +110 -0
- package/dist/types/api/contract-types.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +2 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/resources/assignments.d.ts +2 -2
- package/dist/types/api/resources/assignments.d.ts.map +1 -1
- package/dist/types/api/resources/authentication.d.ts +3 -3
- package/dist/types/api/resources/authentication.d.ts.map +1 -1
- package/dist/types/api/resources/contracts.d.ts +19 -0
- package/dist/types/api/resources/contracts.d.ts.map +1 -0
- package/dist/types/api/resources/documents.d.ts +3 -3
- package/dist/types/api/resources/documents.d.ts.map +1 -1
- package/dist/types/api/resources/webhooks.d.ts +4 -3
- package/dist/types/api/resources/webhooks.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +69 -18
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/api/utils.d.ts +3 -1
- package/dist/types/api/utils.d.ts.map +1 -1
- package/docs/README.md +2 -1
- package/docs/api-operations.json +49 -1
- package/docs/api-reference.md +1446 -295
- package/docs/contracts.md +128 -0
- package/docs/documents.md +7 -4
- package/docs/oauth-guide.md +5 -5
- package/docs/releasing.md +38 -12
- package/docs/sdk-reference.md +154 -13
- package/package.json +2 -2
package/dist/api.js
CHANGED
|
@@ -192,6 +192,11 @@ function requireIso8601(value, name = "timestamp") {
|
|
|
192
192
|
}
|
|
193
193
|
return value;
|
|
194
194
|
}
|
|
195
|
+
function requireExpiration(value, name = "expires_at") {
|
|
196
|
+
const timestamp = /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T23:59:00Z` : /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(value) ? `${value}Z` : value;
|
|
197
|
+
requireIso8601(timestamp, name);
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
195
200
|
function requireEmail(value) {
|
|
196
201
|
if (!value || !EMAIL_RE.test(value)) {
|
|
197
202
|
throw new ValidationError("Invalid email address", { email: value });
|
|
@@ -421,7 +426,7 @@ function buildAssignmentPayload(payload, options = {}) {
|
|
|
421
426
|
method,
|
|
422
427
|
signers: normalisedSigners,
|
|
423
428
|
message: payload.message,
|
|
424
|
-
expires_at: payload.expires_at === void 0 ? void 0 :
|
|
429
|
+
expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
|
|
425
430
|
copy_receivers: payload.copy_receivers,
|
|
426
431
|
entries: payload.entries
|
|
427
432
|
});
|
|
@@ -559,13 +564,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
559
564
|
}
|
|
560
565
|
/**
|
|
561
566
|
* Update the expiration date of an existing assignment.
|
|
562
|
-
*
|
|
563
|
-
*
|
|
567
|
+
* Accepts an ISO 8601 timestamp, a UTC date/time without an offset, a date
|
|
568
|
+
* (23:59 UTC), or `null` to clear the expiration.
|
|
564
569
|
*/
|
|
565
570
|
async resetExpiration(documentId, assignmentId, expiresAt) {
|
|
566
571
|
const docId = this.requireId(documentId, "Document ID");
|
|
567
572
|
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
568
|
-
if (expiresAt !== null)
|
|
573
|
+
if (expiresAt !== null) requireExpiration(expiresAt, "expiresAt");
|
|
569
574
|
return this.call(
|
|
570
575
|
"Failed to update assignment expiration",
|
|
571
576
|
() => this.http.put(`/documents/${docId}/assignments/${asgId}/reset-expiration`, {
|
|
@@ -617,7 +622,7 @@ function requireReauth(payload) {
|
|
|
617
622
|
return payload;
|
|
618
623
|
}
|
|
619
624
|
var AuthenticationResource = class extends BaseResource {
|
|
620
|
-
/** `POST /login` —
|
|
625
|
+
/** `POST /login` — return an authenticated session or a two-factor challenge. */
|
|
621
626
|
async login(email, password) {
|
|
622
627
|
if (!email) throw new ValidationError("email is required");
|
|
623
628
|
if (!password) throw new ValidationError("password is required");
|
|
@@ -760,6 +765,156 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
760
765
|
}
|
|
761
766
|
};
|
|
762
767
|
|
|
768
|
+
// src/api/resources/contracts.ts
|
|
769
|
+
var statuses = ["draft", "active", "expired", "terminated"];
|
|
770
|
+
var ContractResource = class extends BaseResource {
|
|
771
|
+
/** List terms, optionally embedding documents; supports pagination and comma-separated statuses. */
|
|
772
|
+
async list(params = {}, accountId) {
|
|
773
|
+
const id = this.accountId(accountId);
|
|
774
|
+
const status = Array.isArray(params.status) ? params.status.join(",") : params.status;
|
|
775
|
+
if (status !== void 0 && (typeof status !== "string" || status.split(",").some((s) => !statuses.includes(s)))) {
|
|
776
|
+
throw new ValidationError("status must contain draft, active, expired or terminated");
|
|
777
|
+
}
|
|
778
|
+
for (const field of ["end_date_from", "end_date_to"]) {
|
|
779
|
+
if (params[field] !== void 0) requireDate(params[field], field, 0);
|
|
780
|
+
}
|
|
781
|
+
if (params.ending_within_days !== void 0)
|
|
782
|
+
requireInteger(params.ending_within_days, "ending_within_days", 0, 3650);
|
|
783
|
+
requireSort(params.sort, ["end_date", "-end_date", "updated_at", "-updated_at"]);
|
|
784
|
+
if (params.expand !== void 0 && params.expand !== "document")
|
|
785
|
+
throw new ValidationError("expand must be document");
|
|
786
|
+
return this.callList(
|
|
787
|
+
"Failed to list contracts",
|
|
788
|
+
() => this.http.get(`/accounts/${id}/contracts`, { params: cleanParams({ ...params, status }) })
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
/** Read a document's own terms or its amendment link. Missing terms return ApiError 404. */
|
|
792
|
+
async get(documentId, accountId) {
|
|
793
|
+
const id = this.accountId(accountId);
|
|
794
|
+
const did = this.requireId(documentId, "Document ID");
|
|
795
|
+
return this.call(
|
|
796
|
+
"Failed to get contract",
|
|
797
|
+
() => this.http.get(`/accounts/${id}/documents/${did}/contract`)
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
/** Set only supplied terms, or link/update/unlink a pending amendment. Preserve null clearing. */
|
|
801
|
+
async set(documentId, payload, accountId) {
|
|
802
|
+
const id = this.accountId(accountId);
|
|
803
|
+
const did = this.requireId(documentId, "Document ID");
|
|
804
|
+
requireBody(payload, true);
|
|
805
|
+
validateTerms(payload);
|
|
806
|
+
return this.call(
|
|
807
|
+
"Failed to set contract terms",
|
|
808
|
+
() => this.http.put(`/accounts/${id}/documents/${did}/contract`, payload)
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
/** Read the root contract and its amendments from any document in that family. */
|
|
812
|
+
async related(documentId, accountId) {
|
|
813
|
+
const id = this.accountId(accountId);
|
|
814
|
+
const did = this.requireId(documentId, "Document ID");
|
|
815
|
+
return this.call(
|
|
816
|
+
"Failed to get related contracts",
|
|
817
|
+
() => this.http.get(`/accounts/${id}/documents/${did}/contract/related`)
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
/** Advance from the supplied current term or to a later end date. No automatic retry. */
|
|
821
|
+
async renew(documentId, payload, accountId) {
|
|
822
|
+
const id = this.accountId(accountId);
|
|
823
|
+
const did = this.requireId(documentId, "Document ID");
|
|
824
|
+
requireBody(payload, true);
|
|
825
|
+
if (payload.term === void 0 && !payload.end_date)
|
|
826
|
+
throw new ValidationError("Renewal requires term or end_date");
|
|
827
|
+
if (payload.term !== void 0)
|
|
828
|
+
requireInteger(payload.term, "term", 1, Number.MAX_SAFE_INTEGER);
|
|
829
|
+
validateTerms({ ...payload, end_date: payload.end_date === "" ? null : payload.end_date });
|
|
830
|
+
return this.call(
|
|
831
|
+
"Failed to renew contract",
|
|
832
|
+
() => this.http.post(`/accounts/${id}/documents/${did}/contract/renew`, payload)
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
/** Terminate existing terms; an optional reason is recorded in document activities. */
|
|
836
|
+
async terminate(documentId, payload = {}, accountId) {
|
|
837
|
+
const id = this.accountId(accountId);
|
|
838
|
+
const did = this.requireId(documentId, "Document ID");
|
|
839
|
+
requireBody(payload);
|
|
840
|
+
if (payload.reason != null && (typeof payload.reason !== "string" || [...payload.reason].length > 500))
|
|
841
|
+
throw new ValidationError("reason must be text of at most 500 characters");
|
|
842
|
+
if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
|
|
843
|
+
return this.call(
|
|
844
|
+
"Failed to terminate contract",
|
|
845
|
+
() => this.http.post(`/accounts/${id}/documents/${did}/contract/terminate`, payload)
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
function requireBody(value, nonempty = false) {
|
|
850
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
851
|
+
throw new ValidationError("Contract body must be a JSON object");
|
|
852
|
+
}
|
|
853
|
+
if (nonempty && !Object.values(value).some((v) => v !== void 0))
|
|
854
|
+
throw new ValidationError("At least one contract attribute is required");
|
|
855
|
+
}
|
|
856
|
+
function requireDate(value, field, minYear = 1e3) {
|
|
857
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value) || Number(value.slice(0, 4)) < minYear)
|
|
858
|
+
throw new ValidationError(`${field} must be a YYYY-MM-DD date from year ${minYear}`);
|
|
859
|
+
requireIso8601(`${value}T00:00:00Z`, field);
|
|
860
|
+
}
|
|
861
|
+
function requireInteger(value, field, min, max) {
|
|
862
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min || value > max)
|
|
863
|
+
throw new ValidationError(`${field} must be an integer from ${min} to ${max}`);
|
|
864
|
+
}
|
|
865
|
+
function validateTerms(payload) {
|
|
866
|
+
for (const field of ["start_date", "end_date"])
|
|
867
|
+
if (payload[field] != null) requireDate(payload[field], field);
|
|
868
|
+
if (payload.start_date && payload.end_date && payload.end_date < payload.start_date)
|
|
869
|
+
throw new ValidationError("end_date must not precede start_date");
|
|
870
|
+
if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
|
|
871
|
+
if (payload.status !== void 0 && !statuses.includes(payload.status))
|
|
872
|
+
throw new ValidationError("Invalid contract status");
|
|
873
|
+
if (payload.relation_type !== void 0 && !["amendment", "renewal", "termination"].includes(payload.relation_type))
|
|
874
|
+
throw new ValidationError("Invalid relation_type");
|
|
875
|
+
if (payload.auto_renew != null && typeof payload.auto_renew !== "boolean")
|
|
876
|
+
throw new ValidationError("auto_renew must be boolean or null");
|
|
877
|
+
if (payload.renewal_term_months != null)
|
|
878
|
+
requireInteger(payload.renewal_term_months, "renewal_term_months", 1, 600);
|
|
879
|
+
if (payload.notice_period_days != null)
|
|
880
|
+
requireInteger(payload.notice_period_days, "notice_period_days", 0, 3650);
|
|
881
|
+
if (payload.value != null && (typeof payload.value !== "number" || !Number.isFinite(payload.value) || payload.value < 0 || payload.value > 999999999999999e-2 || Number(payload.value.toFixed(2)) !== payload.value))
|
|
882
|
+
throw new ValidationError(
|
|
883
|
+
"value must be from 0 to 9999999999999.99 with at most two decimal places"
|
|
884
|
+
);
|
|
885
|
+
for (const [field, max] of [
|
|
886
|
+
["counterparty_name", 255],
|
|
887
|
+
["counterparty_taxpayer_id", 20],
|
|
888
|
+
["owner_id", Infinity],
|
|
889
|
+
["parent_document_id", Infinity]
|
|
890
|
+
]) {
|
|
891
|
+
const value = payload[field];
|
|
892
|
+
if (value != null && (typeof value !== "string" || [...value].length > max))
|
|
893
|
+
throw new ValidationError(`${field} must be text of at most ${max} characters`);
|
|
894
|
+
}
|
|
895
|
+
if (payload.currency != null && (typeof payload.currency !== "string" || !/^[a-z]{3}$/i.test(payload.currency)))
|
|
896
|
+
throw new ValidationError("currency must be a three-letter code");
|
|
897
|
+
if (payload.metadata != null) {
|
|
898
|
+
requireBody(payload.metadata);
|
|
899
|
+
const entries = Object.entries(payload.metadata);
|
|
900
|
+
if (entries.length > 50 || entries.some(
|
|
901
|
+
([key, value]) => !/^[a-z\d_.-]{1,40}$/i.test(key) || typeof value !== "string" || [...value].length > 500
|
|
902
|
+
))
|
|
903
|
+
throw new ValidationError(
|
|
904
|
+
"metadata requires at most 50 valid keys with text values of at most 500 characters"
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
if (payload.external_references != null) {
|
|
908
|
+
if (!Array.isArray(payload.external_references) || payload.external_references.length > 20)
|
|
909
|
+
throw new ValidationError("external_references must be a list of at most 20 items");
|
|
910
|
+
for (const reference of payload.external_references) {
|
|
911
|
+
requireBody(reference);
|
|
912
|
+
if (typeof reference.system !== "string" || !/^[a-z\d_.-]{1,64}$/i.test(reference.system) || typeof reference.id !== "string" || !reference.id || [...reference.id].length > 255 || /[\u{10000}-\u{10ffff}]/u.test(reference.id))
|
|
913
|
+
throw new ValidationError("Each external reference requires a valid system and id");
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
763
918
|
// src/api/resources/documents.ts
|
|
764
919
|
import { promises as fs } from "fs";
|
|
765
920
|
import path from "path";
|
|
@@ -855,7 +1010,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
855
1010
|
if (!name?.trim()) throw new ValidationError("name is required");
|
|
856
1011
|
return this.call(
|
|
857
1012
|
"Failed to rename document",
|
|
858
|
-
() => this.http.patch(`/documents/${id}`, { name })
|
|
1013
|
+
() => this.http.patch(`/documents/${id}`, { name }, { params: { expand: "assignment" } })
|
|
859
1014
|
);
|
|
860
1015
|
}
|
|
861
1016
|
/** Alias for {@link details}. */
|
|
@@ -943,12 +1098,13 @@ var DocumentResource = class extends BaseResource {
|
|
|
943
1098
|
})
|
|
944
1099
|
);
|
|
945
1100
|
}
|
|
946
|
-
/** Fetch the document activity log. */
|
|
947
|
-
async activities(documentId) {
|
|
1101
|
+
/** Fetch one page of the document activity log (20 entries by default). */
|
|
1102
|
+
async activities(documentId, params = {}) {
|
|
948
1103
|
const id = this.requireId(documentId, "Document ID");
|
|
1104
|
+
requireSort(params.sort, ["id", "-id"]);
|
|
949
1105
|
const result = await this.call(
|
|
950
1106
|
"Failed to fetch document activities",
|
|
951
|
-
() => this.http.get(`/documents/${id}/activities
|
|
1107
|
+
() => this.http.get(`/documents/${id}/activities`, { params: cleanParams({ ...params }) })
|
|
952
1108
|
);
|
|
953
1109
|
return result ?? [];
|
|
954
1110
|
}
|
|
@@ -1014,8 +1170,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
1014
1170
|
async createFromTemplate(templateId, signers, options = {}, accountId) {
|
|
1015
1171
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1016
1172
|
const accId = this.accountId(accountId);
|
|
1017
|
-
validateTemplateSigners(signers, {
|
|
1018
|
-
if (options.expires_at !== void 0)
|
|
1173
|
+
validateTemplateSigners(signers, { requireIdentity: true });
|
|
1174
|
+
if (options.expires_at !== void 0) requireExpiration(options.expires_at);
|
|
1019
1175
|
if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
|
|
1020
1176
|
throw new ValidationError("editor_fields must contain field_id and value");
|
|
1021
1177
|
}
|
|
@@ -1034,7 +1190,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
1034
1190
|
async estimateCostFromTemplate(templateId, signers, accountId) {
|
|
1035
1191
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1036
1192
|
const accId = this.accountId(accountId);
|
|
1037
|
-
validateTemplateSigners(signers, {
|
|
1193
|
+
validateTemplateSigners(signers, { requireIdentity: false });
|
|
1038
1194
|
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
1039
1195
|
return this.call(
|
|
1040
1196
|
"Failed to estimate cost from template",
|
|
@@ -1120,8 +1276,18 @@ var DocumentResource = class extends BaseResource {
|
|
|
1120
1276
|
"Failed to fetch template",
|
|
1121
1277
|
() => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
|
|
1122
1278
|
);
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1279
|
+
const nonSignerRoles = new Set(
|
|
1280
|
+
template.roles?.filter(
|
|
1281
|
+
(role) => role.assignment_type === "Editor" || role.assignment_type === "CopyReceiver"
|
|
1282
|
+
).map((role) => role.id)
|
|
1283
|
+
);
|
|
1284
|
+
const method = template.pages?.some(
|
|
1285
|
+
(page) => page.fields.some((field) => !nonSignerRoles.has(field.role_id))
|
|
1286
|
+
) ? "collect" : "virtual";
|
|
1287
|
+
validateDigitalCertificateMethod(
|
|
1288
|
+
method,
|
|
1289
|
+
signers.filter((signer) => !nonSignerRoles.has(signer.role_id))
|
|
1290
|
+
);
|
|
1125
1291
|
}
|
|
1126
1292
|
};
|
|
1127
1293
|
function validateTemplateSigners(signers, options) {
|
|
@@ -1134,17 +1300,20 @@ function validateTemplateSigners(signers, options) {
|
|
|
1134
1300
|
if (typeof signer.role_id !== "string" || !signer.role_id) {
|
|
1135
1301
|
throw new ValidationError("each template signer requires role_id");
|
|
1136
1302
|
}
|
|
1137
|
-
if (
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
if (options.
|
|
1142
|
-
|
|
1303
|
+
if (signer.id !== void 0) {
|
|
1304
|
+
if (typeof signer.id !== "string" || !signer.id) {
|
|
1305
|
+
throw new ValidationError("each template signer requires a valid id");
|
|
1306
|
+
}
|
|
1307
|
+
} else if (options.requireIdentity) {
|
|
1308
|
+
if (typeof signer.email !== "string") {
|
|
1309
|
+
throw new ValidationError("each template signer requires an id or email");
|
|
1310
|
+
}
|
|
1311
|
+
requireEmail(signer.email);
|
|
1312
|
+
if (signer.name !== void 0 && (typeof signer.name !== "string" || !signer.name.trim())) {
|
|
1313
|
+
throw new ValidationError("template signer name cannot be blank");
|
|
1314
|
+
}
|
|
1143
1315
|
}
|
|
1144
1316
|
}
|
|
1145
|
-
if (options.requireId) {
|
|
1146
|
-
validateSigningSteps(signers);
|
|
1147
|
-
}
|
|
1148
1317
|
}
|
|
1149
1318
|
async function loadSource(source) {
|
|
1150
1319
|
if ("buffer" in source) {
|
|
@@ -2065,7 +2234,11 @@ var NOTIFICATION_PREFERENCE_CODES = [
|
|
|
2065
2234
|
"DocumentExpirationReset",
|
|
2066
2235
|
"DocumentProcessingFailed",
|
|
2067
2236
|
"TemplateProcessingFailed",
|
|
2068
|
-
"SignerWhatsappFailed"
|
|
2237
|
+
"SignerWhatsappFailed",
|
|
2238
|
+
"ContractRenewalNotice",
|
|
2239
|
+
"ContractExpiring",
|
|
2240
|
+
"ContractExpired",
|
|
2241
|
+
"ContractRenewed"
|
|
2069
2242
|
];
|
|
2070
2243
|
|
|
2071
2244
|
// src/api/resources/users.ts
|
|
@@ -2121,7 +2294,7 @@ var DEFAULT_EVENTS = [
|
|
|
2121
2294
|
"signer_rejected_document",
|
|
2122
2295
|
"document_processing_failed"
|
|
2123
2296
|
];
|
|
2124
|
-
function validateWebhookFields(payload) {
|
|
2297
|
+
function validateWebhookFields(payload, requireHttps = false) {
|
|
2125
2298
|
if (payload.url !== void 0) {
|
|
2126
2299
|
let webhookUrl;
|
|
2127
2300
|
try {
|
|
@@ -2132,6 +2305,9 @@ function validateWebhookFields(payload) {
|
|
|
2132
2305
|
if (webhookUrl.protocol !== "http:" && webhookUrl.protocol !== "https:") {
|
|
2133
2306
|
throw new ValidationError("Webhook URL must be a valid HTTP(S) URL");
|
|
2134
2307
|
}
|
|
2308
|
+
if (requireHttps && webhookUrl.protocol !== "https:") {
|
|
2309
|
+
throw new ValidationError("Webhook URL must use HTTPS");
|
|
2310
|
+
}
|
|
2135
2311
|
}
|
|
2136
2312
|
if (payload.email !== void 0) requireEmail(payload.email);
|
|
2137
2313
|
if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event))) {
|
|
@@ -2154,7 +2330,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2154
2330
|
*/
|
|
2155
2331
|
async register(payload, accountId) {
|
|
2156
2332
|
if (!payload.url) throw new ValidationError("Webhook URL is required");
|
|
2157
|
-
validateWebhookFields({ ...payload, email: payload.email ?? "" });
|
|
2333
|
+
validateWebhookFields({ ...payload, email: payload.email ?? "" }, true);
|
|
2158
2334
|
const id = this.accountId(accountId);
|
|
2159
2335
|
const body = {
|
|
2160
2336
|
url: payload.url,
|
|
@@ -2205,7 +2381,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2205
2381
|
*/
|
|
2206
2382
|
async createEndpoint(payload, accountId) {
|
|
2207
2383
|
if (!payload.url) throw new ValidationError("Webhook URL is required");
|
|
2208
|
-
validateWebhookFields({ ...payload, email: payload.email ?? "" });
|
|
2384
|
+
validateWebhookFields({ ...payload, email: payload.email ?? "" }, true);
|
|
2209
2385
|
const id = this.accountId(accountId);
|
|
2210
2386
|
const body = { ...payload, events: payload.events ?? DEFAULT_EVENTS };
|
|
2211
2387
|
this.logger.info("Creating webhook endpoint", { eventCount: body.events.length });
|
|
@@ -2227,6 +2403,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2227
2403
|
* `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
|
|
2228
2404
|
* the fields sent. Enabling signing creates a secret when none exists;
|
|
2229
2405
|
* disabling it discards the secret.
|
|
2406
|
+
* Enabling signing returns the new secret once, including to OAuth applications.
|
|
2230
2407
|
*/
|
|
2231
2408
|
async updateEndpoint(endpointId, payload, accountId) {
|
|
2232
2409
|
const id = this.accountId(accountId);
|
|
@@ -2234,7 +2411,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2234
2411
|
if (!payload || typeof payload !== "object" || Object.keys(payload).length === 0) {
|
|
2235
2412
|
throw new ValidationError("At least one webhook endpoint field is required");
|
|
2236
2413
|
}
|
|
2237
|
-
validateWebhookFields(payload);
|
|
2414
|
+
validateWebhookFields(payload, true);
|
|
2238
2415
|
return this.call(
|
|
2239
2416
|
"Failed to update webhook endpoint",
|
|
2240
2417
|
() => this.http.put(`/accounts/${id}/webhooks/endpoints/${eid}`, payload)
|
|
@@ -2273,7 +2450,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2273
2450
|
}
|
|
2274
2451
|
/**
|
|
2275
2452
|
* `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
|
|
2276
|
-
* The old secret stops working immediately.
|
|
2453
|
+
* The old secret stops working immediately. Requires `webhooks:write` for OAuth.
|
|
2277
2454
|
*/
|
|
2278
2455
|
async rotateEndpointSecret(endpointId, accountId) {
|
|
2279
2456
|
const id = this.accountId(accountId);
|
|
@@ -2525,6 +2702,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2525
2702
|
logger;
|
|
2526
2703
|
webhookSecret;
|
|
2527
2704
|
documents;
|
|
2705
|
+
contracts;
|
|
2528
2706
|
signers;
|
|
2529
2707
|
workspaces;
|
|
2530
2708
|
assignments;
|
|
@@ -2591,6 +2769,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2591
2769
|
maxRedirects: 0
|
|
2592
2770
|
});
|
|
2593
2771
|
this.documents = new DocumentResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2772
|
+
this.contracts = new ContractResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2594
2773
|
this.signers = new SignerResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2595
2774
|
this.workspaces = new WorkspaceResource(this.axiosInstance, void 0, this.logger);
|
|
2596
2775
|
this.assignments = new AssignmentResource(
|
|
@@ -2648,12 +2827,11 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2648
2827
|
if (!Array.isArray(options.signers) || options.signers.length === 0) {
|
|
2649
2828
|
throw new ValidationError("At least one signer is required");
|
|
2650
2829
|
}
|
|
2651
|
-
if (options.expiresAt !== void 0)
|
|
2830
|
+
if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
|
|
2652
2831
|
const preparedSigners = options.signers.map((signer) => {
|
|
2653
2832
|
if (!signer || typeof signer !== "object") {
|
|
2654
2833
|
throw new ValidationError("Each signer must be an object");
|
|
2655
2834
|
}
|
|
2656
|
-
validateSignerOptions(signer);
|
|
2657
2835
|
const payload = { full_name: signer.name };
|
|
2658
2836
|
if (signer.email !== void 0) payload.email = signer.email;
|
|
2659
2837
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
@@ -2662,7 +2840,14 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2662
2840
|
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2663
2841
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2664
2842
|
validateCreateSignerPayload(payload);
|
|
2665
|
-
|
|
2843
|
+
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2844
|
+
const reference = {
|
|
2845
|
+
verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
|
|
2846
|
+
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2847
|
+
step: signer.step
|
|
2848
|
+
};
|
|
2849
|
+
validateSignerOptions(reference);
|
|
2850
|
+
return { reference, payload };
|
|
2666
2851
|
});
|
|
2667
2852
|
validateSigningSteps(options.signers);
|
|
2668
2853
|
this.logger.info("Starting upload + signature workflow", {
|
|
@@ -2678,15 +2863,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2678
2863
|
await this.documents.waitUntilReady(document.id);
|
|
2679
2864
|
}
|
|
2680
2865
|
const assignmentSigners = [];
|
|
2681
|
-
for (const {
|
|
2866
|
+
for (const { reference, payload } of preparedSigners) {
|
|
2682
2867
|
const created = await this.signers.create(payload, options.accountId);
|
|
2683
2868
|
signerIds.push(created.id);
|
|
2684
|
-
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2685
2869
|
assignmentSigners.push({
|
|
2686
2870
|
id: created.id,
|
|
2687
|
-
|
|
2688
|
-
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2689
|
-
step: signer.step
|
|
2871
|
+
...reference
|
|
2690
2872
|
});
|
|
2691
2873
|
}
|
|
2692
2874
|
const assignmentPayload = {
|
|
@@ -2724,6 +2906,7 @@ export {
|
|
|
2724
2906
|
AssinafyClient,
|
|
2725
2907
|
AssinafyError,
|
|
2726
2908
|
AuthenticationResource,
|
|
2909
|
+
ContractResource,
|
|
2727
2910
|
DocumentResource,
|
|
2728
2911
|
FieldsResource,
|
|
2729
2912
|
NOTIFICATION_PREFERENCE_CODES,
|