@assinafy/cli 2.6.0 → 2.7.0
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 +38 -10
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/api.cjs +235 -34
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +234 -34
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +365 -68
- 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 +4 -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 +8 -2
- 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 +1454 -295
- package/docs/contracts.md +128 -0
- package/docs/documents.md +7 -4
- package/docs/oauth-guide.md +5 -5
- package/docs/sdk-reference.md +156 -15
- package/package.json +2 -2
package/dist/api.cjs
CHANGED
|
@@ -35,6 +35,7 @@ __export(api_exports, {
|
|
|
35
35
|
AssinafyClient: () => AssinafyClient,
|
|
36
36
|
AssinafyError: () => AssinafyError,
|
|
37
37
|
AuthenticationResource: () => AuthenticationResource,
|
|
38
|
+
ContractResource: () => ContractResource,
|
|
38
39
|
DocumentResource: () => DocumentResource,
|
|
39
40
|
FieldsResource: () => FieldsResource,
|
|
40
41
|
NOTIFICATION_PREFERENCE_CODES: () => NOTIFICATION_PREFERENCE_CODES,
|
|
@@ -251,6 +252,11 @@ function requireIso8601(value, name = "timestamp") {
|
|
|
251
252
|
}
|
|
252
253
|
return value;
|
|
253
254
|
}
|
|
255
|
+
function requireExpiration(value, name = "expires_at") {
|
|
256
|
+
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;
|
|
257
|
+
requireIso8601(timestamp, name);
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
254
260
|
function requireEmail(value) {
|
|
255
261
|
if (!value || !EMAIL_RE.test(value)) {
|
|
256
262
|
throw new ValidationError("Invalid email address", { email: value });
|
|
@@ -284,6 +290,13 @@ function validateSignerOptions(input) {
|
|
|
284
290
|
throw new ValidationError("step must be an integer");
|
|
285
291
|
}
|
|
286
292
|
}
|
|
293
|
+
function validateDigitalCertificateMethod(method, signers) {
|
|
294
|
+
if (method !== "virtual" && signers.some((signer) => signer.verification_method === "DigitalCertificate")) {
|
|
295
|
+
throw new ValidationError("DigitalCertificate signers require method: virtual", {
|
|
296
|
+
code: "digital_certificate_requires_virtual"
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
287
300
|
function validateSigningSteps(signers) {
|
|
288
301
|
const withSteps = signers.filter((signer) => signer.step !== void 0);
|
|
289
302
|
if (withSteps.length > 0) {
|
|
@@ -460,18 +473,20 @@ function buildAssignmentPayload(payload, options = {}) {
|
|
|
460
473
|
signers: payload.signers ?? payload.signer_ids ?? payload.signerIds
|
|
461
474
|
});
|
|
462
475
|
}
|
|
463
|
-
|
|
476
|
+
const method = payload.method ?? "virtual";
|
|
477
|
+
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
|
|
478
|
+
validateDigitalCertificateMethod(method, normalisedSigners);
|
|
479
|
+
if (method === "collect" && !Array.isArray(payload.entries)) {
|
|
464
480
|
throw new ValidationError("entries are required for collect assignments");
|
|
465
481
|
}
|
|
466
|
-
const normalisedSigners = signers.map((ref) => normaliseSignerRef(ref, options));
|
|
467
482
|
if (!options.skipDigitalCertificateStepValidation) {
|
|
468
483
|
validateSigningSteps(normalisedSigners);
|
|
469
484
|
}
|
|
470
485
|
return stripEmpty({
|
|
471
|
-
method
|
|
486
|
+
method,
|
|
472
487
|
signers: normalisedSigners,
|
|
473
488
|
message: payload.message,
|
|
474
|
-
expires_at: payload.expires_at === void 0 ? void 0 :
|
|
489
|
+
expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
|
|
475
490
|
copy_receivers: payload.copy_receivers,
|
|
476
491
|
entries: payload.entries
|
|
477
492
|
});
|
|
@@ -609,13 +624,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
609
624
|
}
|
|
610
625
|
/**
|
|
611
626
|
* Update the expiration date of an existing assignment.
|
|
612
|
-
*
|
|
613
|
-
*
|
|
627
|
+
* Accepts an ISO 8601 timestamp, a UTC date/time without an offset, a date
|
|
628
|
+
* (23:59 UTC), or `null` to clear the expiration.
|
|
614
629
|
*/
|
|
615
630
|
async resetExpiration(documentId, assignmentId, expiresAt) {
|
|
616
631
|
const docId = this.requireId(documentId, "Document ID");
|
|
617
632
|
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
618
|
-
if (expiresAt !== null)
|
|
633
|
+
if (expiresAt !== null) requireExpiration(expiresAt, "expiresAt");
|
|
619
634
|
return this.call(
|
|
620
635
|
"Failed to update assignment expiration",
|
|
621
636
|
() => this.http.put(`/documents/${docId}/assignments/${asgId}/reset-expiration`, {
|
|
@@ -667,7 +682,7 @@ function requireReauth(payload) {
|
|
|
667
682
|
return payload;
|
|
668
683
|
}
|
|
669
684
|
var AuthenticationResource = class extends BaseResource {
|
|
670
|
-
/** `POST /login` —
|
|
685
|
+
/** `POST /login` — return an authenticated session or a two-factor challenge. */
|
|
671
686
|
async login(email, password) {
|
|
672
687
|
if (!email) throw new ValidationError("email is required");
|
|
673
688
|
if (!password) throw new ValidationError("password is required");
|
|
@@ -810,6 +825,156 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
810
825
|
}
|
|
811
826
|
};
|
|
812
827
|
|
|
828
|
+
// src/api/resources/contracts.ts
|
|
829
|
+
var statuses = ["draft", "active", "expired", "terminated"];
|
|
830
|
+
var ContractResource = class extends BaseResource {
|
|
831
|
+
/** List terms, optionally embedding documents; supports pagination and comma-separated statuses. */
|
|
832
|
+
async list(params = {}, accountId) {
|
|
833
|
+
const id = this.accountId(accountId);
|
|
834
|
+
const status = Array.isArray(params.status) ? params.status.join(",") : params.status;
|
|
835
|
+
if (status !== void 0 && (typeof status !== "string" || status.split(",").some((s) => !statuses.includes(s)))) {
|
|
836
|
+
throw new ValidationError("status must contain draft, active, expired or terminated");
|
|
837
|
+
}
|
|
838
|
+
for (const field of ["end_date_from", "end_date_to"]) {
|
|
839
|
+
if (params[field] !== void 0) requireDate(params[field], field, 0);
|
|
840
|
+
}
|
|
841
|
+
if (params.ending_within_days !== void 0)
|
|
842
|
+
requireInteger(params.ending_within_days, "ending_within_days", 0, 3650);
|
|
843
|
+
requireSort(params.sort, ["end_date", "-end_date", "updated_at", "-updated_at"]);
|
|
844
|
+
if (params.expand !== void 0 && params.expand !== "document")
|
|
845
|
+
throw new ValidationError("expand must be document");
|
|
846
|
+
return this.callList(
|
|
847
|
+
"Failed to list contracts",
|
|
848
|
+
() => this.http.get(`/accounts/${id}/contracts`, { params: cleanParams({ ...params, status }) })
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
/** Read a document's own terms or its amendment link. Missing terms return ApiError 404. */
|
|
852
|
+
async get(documentId, accountId) {
|
|
853
|
+
const id = this.accountId(accountId);
|
|
854
|
+
const did = this.requireId(documentId, "Document ID");
|
|
855
|
+
return this.call(
|
|
856
|
+
"Failed to get contract",
|
|
857
|
+
() => this.http.get(`/accounts/${id}/documents/${did}/contract`)
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
/** Set only supplied terms, or link/update/unlink a pending amendment. Preserve null clearing. */
|
|
861
|
+
async set(documentId, payload, accountId) {
|
|
862
|
+
const id = this.accountId(accountId);
|
|
863
|
+
const did = this.requireId(documentId, "Document ID");
|
|
864
|
+
requireBody(payload, true);
|
|
865
|
+
validateTerms(payload);
|
|
866
|
+
return this.call(
|
|
867
|
+
"Failed to set contract terms",
|
|
868
|
+
() => this.http.put(`/accounts/${id}/documents/${did}/contract`, payload)
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
/** Read the root contract and its amendments from any document in that family. */
|
|
872
|
+
async related(documentId, accountId) {
|
|
873
|
+
const id = this.accountId(accountId);
|
|
874
|
+
const did = this.requireId(documentId, "Document ID");
|
|
875
|
+
return this.call(
|
|
876
|
+
"Failed to get related contracts",
|
|
877
|
+
() => this.http.get(`/accounts/${id}/documents/${did}/contract/related`)
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
/** Advance from the supplied current term or to a later end date. No automatic retry. */
|
|
881
|
+
async renew(documentId, payload, accountId) {
|
|
882
|
+
const id = this.accountId(accountId);
|
|
883
|
+
const did = this.requireId(documentId, "Document ID");
|
|
884
|
+
requireBody(payload, true);
|
|
885
|
+
if (payload.term === void 0 && !payload.end_date)
|
|
886
|
+
throw new ValidationError("Renewal requires term or end_date");
|
|
887
|
+
if (payload.term !== void 0)
|
|
888
|
+
requireInteger(payload.term, "term", 1, Number.MAX_SAFE_INTEGER);
|
|
889
|
+
validateTerms({ ...payload, end_date: payload.end_date === "" ? null : payload.end_date });
|
|
890
|
+
return this.call(
|
|
891
|
+
"Failed to renew contract",
|
|
892
|
+
() => this.http.post(`/accounts/${id}/documents/${did}/contract/renew`, payload)
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
/** Terminate existing terms; an optional reason is recorded in document activities. */
|
|
896
|
+
async terminate(documentId, payload = {}, accountId) {
|
|
897
|
+
const id = this.accountId(accountId);
|
|
898
|
+
const did = this.requireId(documentId, "Document ID");
|
|
899
|
+
requireBody(payload);
|
|
900
|
+
if (payload.reason != null && (typeof payload.reason !== "string" || [...payload.reason].length > 500))
|
|
901
|
+
throw new ValidationError("reason must be text of at most 500 characters");
|
|
902
|
+
if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
|
|
903
|
+
return this.call(
|
|
904
|
+
"Failed to terminate contract",
|
|
905
|
+
() => this.http.post(`/accounts/${id}/documents/${did}/contract/terminate`, payload)
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
function requireBody(value, nonempty = false) {
|
|
910
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
911
|
+
throw new ValidationError("Contract body must be a JSON object");
|
|
912
|
+
}
|
|
913
|
+
if (nonempty && !Object.values(value).some((v) => v !== void 0))
|
|
914
|
+
throw new ValidationError("At least one contract attribute is required");
|
|
915
|
+
}
|
|
916
|
+
function requireDate(value, field, minYear = 1e3) {
|
|
917
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value) || Number(value.slice(0, 4)) < minYear)
|
|
918
|
+
throw new ValidationError(`${field} must be a YYYY-MM-DD date from year ${minYear}`);
|
|
919
|
+
requireIso8601(`${value}T00:00:00Z`, field);
|
|
920
|
+
}
|
|
921
|
+
function requireInteger(value, field, min, max) {
|
|
922
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min || value > max)
|
|
923
|
+
throw new ValidationError(`${field} must be an integer from ${min} to ${max}`);
|
|
924
|
+
}
|
|
925
|
+
function validateTerms(payload) {
|
|
926
|
+
for (const field of ["start_date", "end_date"])
|
|
927
|
+
if (payload[field] != null) requireDate(payload[field], field);
|
|
928
|
+
if (payload.start_date && payload.end_date && payload.end_date < payload.start_date)
|
|
929
|
+
throw new ValidationError("end_date must not precede start_date");
|
|
930
|
+
if (payload.updated_at != null) requireIso8601(payload.updated_at, "updated_at");
|
|
931
|
+
if (payload.status !== void 0 && !statuses.includes(payload.status))
|
|
932
|
+
throw new ValidationError("Invalid contract status");
|
|
933
|
+
if (payload.relation_type !== void 0 && !["amendment", "renewal", "termination"].includes(payload.relation_type))
|
|
934
|
+
throw new ValidationError("Invalid relation_type");
|
|
935
|
+
if (payload.auto_renew != null && typeof payload.auto_renew !== "boolean")
|
|
936
|
+
throw new ValidationError("auto_renew must be boolean or null");
|
|
937
|
+
if (payload.renewal_term_months != null)
|
|
938
|
+
requireInteger(payload.renewal_term_months, "renewal_term_months", 1, 600);
|
|
939
|
+
if (payload.notice_period_days != null)
|
|
940
|
+
requireInteger(payload.notice_period_days, "notice_period_days", 0, 3650);
|
|
941
|
+
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))
|
|
942
|
+
throw new ValidationError(
|
|
943
|
+
"value must be from 0 to 9999999999999.99 with at most two decimal places"
|
|
944
|
+
);
|
|
945
|
+
for (const [field, max] of [
|
|
946
|
+
["counterparty_name", 255],
|
|
947
|
+
["counterparty_taxpayer_id", 20],
|
|
948
|
+
["owner_id", Infinity],
|
|
949
|
+
["parent_document_id", Infinity]
|
|
950
|
+
]) {
|
|
951
|
+
const value = payload[field];
|
|
952
|
+
if (value != null && (typeof value !== "string" || [...value].length > max))
|
|
953
|
+
throw new ValidationError(`${field} must be text of at most ${max} characters`);
|
|
954
|
+
}
|
|
955
|
+
if (payload.currency != null && (typeof payload.currency !== "string" || !/^[a-z]{3}$/i.test(payload.currency)))
|
|
956
|
+
throw new ValidationError("currency must be a three-letter code");
|
|
957
|
+
if (payload.metadata != null) {
|
|
958
|
+
requireBody(payload.metadata);
|
|
959
|
+
const entries = Object.entries(payload.metadata);
|
|
960
|
+
if (entries.length > 50 || entries.some(
|
|
961
|
+
([key, value]) => !/^[a-z\d_.-]{1,40}$/i.test(key) || typeof value !== "string" || [...value].length > 500
|
|
962
|
+
))
|
|
963
|
+
throw new ValidationError(
|
|
964
|
+
"metadata requires at most 50 valid keys with text values of at most 500 characters"
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
if (payload.external_references != null) {
|
|
968
|
+
if (!Array.isArray(payload.external_references) || payload.external_references.length > 20)
|
|
969
|
+
throw new ValidationError("external_references must be a list of at most 20 items");
|
|
970
|
+
for (const reference of payload.external_references) {
|
|
971
|
+
requireBody(reference);
|
|
972
|
+
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))
|
|
973
|
+
throw new ValidationError("Each external reference requires a valid system and id");
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
813
978
|
// src/api/resources/documents.ts
|
|
814
979
|
var import_node_fs = require("fs");
|
|
815
980
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -905,7 +1070,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
905
1070
|
if (!name?.trim()) throw new ValidationError("name is required");
|
|
906
1071
|
return this.call(
|
|
907
1072
|
"Failed to rename document",
|
|
908
|
-
() => this.http.patch(`/documents/${id}`, { name })
|
|
1073
|
+
() => this.http.patch(`/documents/${id}`, { name }, { params: { expand: "assignment" } })
|
|
909
1074
|
);
|
|
910
1075
|
}
|
|
911
1076
|
/** Alias for {@link details}. */
|
|
@@ -993,12 +1158,13 @@ var DocumentResource = class extends BaseResource {
|
|
|
993
1158
|
})
|
|
994
1159
|
);
|
|
995
1160
|
}
|
|
996
|
-
/** Fetch the document activity log. */
|
|
997
|
-
async activities(documentId) {
|
|
1161
|
+
/** Fetch one page of the document activity log (20 entries by default). */
|
|
1162
|
+
async activities(documentId, params = {}) {
|
|
998
1163
|
const id = this.requireId(documentId, "Document ID");
|
|
1164
|
+
requireSort(params.sort, ["id", "-id"]);
|
|
999
1165
|
const result = await this.call(
|
|
1000
1166
|
"Failed to fetch document activities",
|
|
1001
|
-
() => this.http.get(`/documents/${id}/activities
|
|
1167
|
+
() => this.http.get(`/documents/${id}/activities`, { params: cleanParams({ ...params }) })
|
|
1002
1168
|
);
|
|
1003
1169
|
return result ?? [];
|
|
1004
1170
|
}
|
|
@@ -1064,14 +1230,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
1064
1230
|
async createFromTemplate(templateId, signers, options = {}, accountId) {
|
|
1065
1231
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1066
1232
|
const accId = this.accountId(accountId);
|
|
1067
|
-
validateTemplateSigners(signers, {
|
|
1068
|
-
if (options.expires_at !== void 0)
|
|
1233
|
+
validateTemplateSigners(signers, { requireIdentity: true });
|
|
1234
|
+
if (options.expires_at !== void 0) requireExpiration(options.expires_at);
|
|
1069
1235
|
if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
|
|
1070
1236
|
throw new ValidationError("editor_fields must contain field_id and value");
|
|
1071
1237
|
}
|
|
1072
1238
|
if (options.tags !== void 0 && (!Array.isArray(options.tags) || options.tags.some((tag) => typeof tag !== "string" || !tag))) {
|
|
1073
1239
|
throw new ValidationError("tags must contain non-empty tag names");
|
|
1074
1240
|
}
|
|
1241
|
+
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
1075
1242
|
const body = { ...options, signers };
|
|
1076
1243
|
this.logger.info("Creating document from template", { templateId: tmplId, accountId: accId });
|
|
1077
1244
|
return this.call(
|
|
@@ -1083,7 +1250,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
1083
1250
|
async estimateCostFromTemplate(templateId, signers, accountId) {
|
|
1084
1251
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1085
1252
|
const accId = this.accountId(accountId);
|
|
1086
|
-
validateTemplateSigners(signers, {
|
|
1253
|
+
validateTemplateSigners(signers, { requireIdentity: false });
|
|
1254
|
+
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
1087
1255
|
return this.call(
|
|
1088
1256
|
"Failed to estimate cost from template",
|
|
1089
1257
|
() => this.http.post(`/accounts/${accId}/templates/${tmplId}/documents/estimate-cost`, { signers })
|
|
@@ -1162,6 +1330,25 @@ var DocumentResource = class extends BaseResource {
|
|
|
1162
1330
|
const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
|
|
1163
1331
|
return { signed, total, pending, percentage };
|
|
1164
1332
|
}
|
|
1333
|
+
async validateCertificateTemplateMethod(templateId, accountId, signers) {
|
|
1334
|
+
if (!signers.some((signer) => signer.verification_method === "DigitalCertificate")) return;
|
|
1335
|
+
const template = await this.call(
|
|
1336
|
+
"Failed to fetch template",
|
|
1337
|
+
() => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
|
|
1338
|
+
);
|
|
1339
|
+
const nonSignerRoles = new Set(
|
|
1340
|
+
template.roles?.filter(
|
|
1341
|
+
(role) => role.assignment_type === "Editor" || role.assignment_type === "CopyReceiver"
|
|
1342
|
+
).map((role) => role.id)
|
|
1343
|
+
);
|
|
1344
|
+
const method = template.pages?.some(
|
|
1345
|
+
(page) => page.fields.some((field) => !nonSignerRoles.has(field.role_id))
|
|
1346
|
+
) ? "collect" : "virtual";
|
|
1347
|
+
validateDigitalCertificateMethod(
|
|
1348
|
+
method,
|
|
1349
|
+
signers.filter((signer) => !nonSignerRoles.has(signer.role_id))
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1165
1352
|
};
|
|
1166
1353
|
function validateTemplateSigners(signers, options) {
|
|
1167
1354
|
if (!Array.isArray(signers)) throw new ValidationError("signers must be an array");
|
|
@@ -1173,17 +1360,20 @@ function validateTemplateSigners(signers, options) {
|
|
|
1173
1360
|
if (typeof signer.role_id !== "string" || !signer.role_id) {
|
|
1174
1361
|
throw new ValidationError("each template signer requires role_id");
|
|
1175
1362
|
}
|
|
1176
|
-
if (
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
if (options.
|
|
1181
|
-
|
|
1363
|
+
if (signer.id !== void 0) {
|
|
1364
|
+
if (typeof signer.id !== "string" || !signer.id) {
|
|
1365
|
+
throw new ValidationError("each template signer requires a valid id");
|
|
1366
|
+
}
|
|
1367
|
+
} else if (options.requireIdentity) {
|
|
1368
|
+
if (typeof signer.email !== "string") {
|
|
1369
|
+
throw new ValidationError("each template signer requires an id or email");
|
|
1370
|
+
}
|
|
1371
|
+
requireEmail(signer.email);
|
|
1372
|
+
if (signer.name !== void 0 && (typeof signer.name !== "string" || !signer.name.trim())) {
|
|
1373
|
+
throw new ValidationError("template signer name cannot be blank");
|
|
1374
|
+
}
|
|
1182
1375
|
}
|
|
1183
1376
|
}
|
|
1184
|
-
if (options.requireId) {
|
|
1185
|
-
validateSigningSteps(signers);
|
|
1186
|
-
}
|
|
1187
1377
|
}
|
|
1188
1378
|
async function loadSource(source) {
|
|
1189
1379
|
if ("buffer" in source) {
|
|
@@ -2104,7 +2294,11 @@ var NOTIFICATION_PREFERENCE_CODES = [
|
|
|
2104
2294
|
"DocumentExpirationReset",
|
|
2105
2295
|
"DocumentProcessingFailed",
|
|
2106
2296
|
"TemplateProcessingFailed",
|
|
2107
|
-
"SignerWhatsappFailed"
|
|
2297
|
+
"SignerWhatsappFailed",
|
|
2298
|
+
"ContractRenewalNotice",
|
|
2299
|
+
"ContractExpiring",
|
|
2300
|
+
"ContractExpired",
|
|
2301
|
+
"ContractRenewed"
|
|
2108
2302
|
];
|
|
2109
2303
|
|
|
2110
2304
|
// src/api/resources/users.ts
|
|
@@ -2266,6 +2460,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2266
2460
|
* `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
|
|
2267
2461
|
* the fields sent. Enabling signing creates a secret when none exists;
|
|
2268
2462
|
* disabling it discards the secret.
|
|
2463
|
+
* Enabling signing returns the new secret once, including to OAuth applications.
|
|
2269
2464
|
*/
|
|
2270
2465
|
async updateEndpoint(endpointId, payload, accountId) {
|
|
2271
2466
|
const id = this.accountId(accountId);
|
|
@@ -2312,7 +2507,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2312
2507
|
}
|
|
2313
2508
|
/**
|
|
2314
2509
|
* `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
|
|
2315
|
-
* The old secret stops working immediately.
|
|
2510
|
+
* The old secret stops working immediately. Requires `webhooks:write` for OAuth.
|
|
2316
2511
|
*/
|
|
2317
2512
|
async rotateEndpointSecret(endpointId, accountId) {
|
|
2318
2513
|
const id = this.accountId(accountId);
|
|
@@ -2564,6 +2759,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2564
2759
|
logger;
|
|
2565
2760
|
webhookSecret;
|
|
2566
2761
|
documents;
|
|
2762
|
+
contracts;
|
|
2567
2763
|
signers;
|
|
2568
2764
|
workspaces;
|
|
2569
2765
|
assignments;
|
|
@@ -2630,6 +2826,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2630
2826
|
maxRedirects: 0
|
|
2631
2827
|
});
|
|
2632
2828
|
this.documents = new DocumentResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2829
|
+
this.contracts = new ContractResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2633
2830
|
this.signers = new SignerResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2634
2831
|
this.workspaces = new WorkspaceResource(this.axiosInstance, void 0, this.logger);
|
|
2635
2832
|
this.assignments = new AssignmentResource(
|
|
@@ -2687,12 +2884,11 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2687
2884
|
if (!Array.isArray(options.signers) || options.signers.length === 0) {
|
|
2688
2885
|
throw new ValidationError("At least one signer is required");
|
|
2689
2886
|
}
|
|
2690
|
-
if (options.expiresAt !== void 0)
|
|
2887
|
+
if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
|
|
2691
2888
|
const preparedSigners = options.signers.map((signer) => {
|
|
2692
2889
|
if (!signer || typeof signer !== "object") {
|
|
2693
2890
|
throw new ValidationError("Each signer must be an object");
|
|
2694
2891
|
}
|
|
2695
|
-
validateSignerOptions(signer);
|
|
2696
2892
|
const payload = { full_name: signer.name };
|
|
2697
2893
|
if (signer.email !== void 0) payload.email = signer.email;
|
|
2698
2894
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
@@ -2701,7 +2897,14 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2701
2897
|
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2702
2898
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2703
2899
|
validateCreateSignerPayload(payload);
|
|
2704
|
-
|
|
2900
|
+
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2901
|
+
const reference = {
|
|
2902
|
+
verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
|
|
2903
|
+
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2904
|
+
step: signer.step
|
|
2905
|
+
};
|
|
2906
|
+
validateSignerOptions(reference);
|
|
2907
|
+
return { reference, payload };
|
|
2705
2908
|
});
|
|
2706
2909
|
validateSigningSteps(options.signers);
|
|
2707
2910
|
this.logger.info("Starting upload + signature workflow", {
|
|
@@ -2717,15 +2920,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2717
2920
|
await this.documents.waitUntilReady(document.id);
|
|
2718
2921
|
}
|
|
2719
2922
|
const assignmentSigners = [];
|
|
2720
|
-
for (const {
|
|
2923
|
+
for (const { reference, payload } of preparedSigners) {
|
|
2721
2924
|
const created = await this.signers.create(payload, options.accountId);
|
|
2722
2925
|
signerIds.push(created.id);
|
|
2723
|
-
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2724
2926
|
assignmentSigners.push({
|
|
2725
2927
|
id: created.id,
|
|
2726
|
-
|
|
2727
|
-
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2728
|
-
step: signer.step
|
|
2928
|
+
...reference
|
|
2729
2929
|
});
|
|
2730
2930
|
}
|
|
2731
2931
|
const assignmentPayload = {
|
|
@@ -2764,6 +2964,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2764
2964
|
AssinafyClient,
|
|
2765
2965
|
AssinafyError,
|
|
2766
2966
|
AuthenticationResource,
|
|
2967
|
+
ContractResource,
|
|
2767
2968
|
DocumentResource,
|
|
2768
2969
|
FieldsResource,
|
|
2769
2970
|
NOTIFICATION_PREFERENCE_CODES,
|