@assinafy/cli 2.6.1 → 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 +214 -33
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +213 -33
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +344 -67
- 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/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
|
|
@@ -2227,6 +2400,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2227
2400
|
* `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
|
|
2228
2401
|
* the fields sent. Enabling signing creates a secret when none exists;
|
|
2229
2402
|
* disabling it discards the secret.
|
|
2403
|
+
* Enabling signing returns the new secret once, including to OAuth applications.
|
|
2230
2404
|
*/
|
|
2231
2405
|
async updateEndpoint(endpointId, payload, accountId) {
|
|
2232
2406
|
const id = this.accountId(accountId);
|
|
@@ -2273,7 +2447,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2273
2447
|
}
|
|
2274
2448
|
/**
|
|
2275
2449
|
* `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
|
|
2276
|
-
* The old secret stops working immediately.
|
|
2450
|
+
* The old secret stops working immediately. Requires `webhooks:write` for OAuth.
|
|
2277
2451
|
*/
|
|
2278
2452
|
async rotateEndpointSecret(endpointId, accountId) {
|
|
2279
2453
|
const id = this.accountId(accountId);
|
|
@@ -2525,6 +2699,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2525
2699
|
logger;
|
|
2526
2700
|
webhookSecret;
|
|
2527
2701
|
documents;
|
|
2702
|
+
contracts;
|
|
2528
2703
|
signers;
|
|
2529
2704
|
workspaces;
|
|
2530
2705
|
assignments;
|
|
@@ -2591,6 +2766,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2591
2766
|
maxRedirects: 0
|
|
2592
2767
|
});
|
|
2593
2768
|
this.documents = new DocumentResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2769
|
+
this.contracts = new ContractResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2594
2770
|
this.signers = new SignerResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2595
2771
|
this.workspaces = new WorkspaceResource(this.axiosInstance, void 0, this.logger);
|
|
2596
2772
|
this.assignments = new AssignmentResource(
|
|
@@ -2648,12 +2824,11 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2648
2824
|
if (!Array.isArray(options.signers) || options.signers.length === 0) {
|
|
2649
2825
|
throw new ValidationError("At least one signer is required");
|
|
2650
2826
|
}
|
|
2651
|
-
if (options.expiresAt !== void 0)
|
|
2827
|
+
if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
|
|
2652
2828
|
const preparedSigners = options.signers.map((signer) => {
|
|
2653
2829
|
if (!signer || typeof signer !== "object") {
|
|
2654
2830
|
throw new ValidationError("Each signer must be an object");
|
|
2655
2831
|
}
|
|
2656
|
-
validateSignerOptions(signer);
|
|
2657
2832
|
const payload = { full_name: signer.name };
|
|
2658
2833
|
if (signer.email !== void 0) payload.email = signer.email;
|
|
2659
2834
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
@@ -2662,7 +2837,14 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2662
2837
|
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2663
2838
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2664
2839
|
validateCreateSignerPayload(payload);
|
|
2665
|
-
|
|
2840
|
+
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2841
|
+
const reference = {
|
|
2842
|
+
verification_method: signer.verification_method ?? (useWhatsapp ? "Whatsapp" : void 0),
|
|
2843
|
+
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2844
|
+
step: signer.step
|
|
2845
|
+
};
|
|
2846
|
+
validateSignerOptions(reference);
|
|
2847
|
+
return { reference, payload };
|
|
2666
2848
|
});
|
|
2667
2849
|
validateSigningSteps(options.signers);
|
|
2668
2850
|
this.logger.info("Starting upload + signature workflow", {
|
|
@@ -2678,15 +2860,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2678
2860
|
await this.documents.waitUntilReady(document.id);
|
|
2679
2861
|
}
|
|
2680
2862
|
const assignmentSigners = [];
|
|
2681
|
-
for (const {
|
|
2863
|
+
for (const { reference, payload } of preparedSigners) {
|
|
2682
2864
|
const created = await this.signers.create(payload, options.accountId);
|
|
2683
2865
|
signerIds.push(created.id);
|
|
2684
|
-
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2685
2866
|
assignmentSigners.push({
|
|
2686
2867
|
id: created.id,
|
|
2687
|
-
|
|
2688
|
-
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2689
|
-
step: signer.step
|
|
2868
|
+
...reference
|
|
2690
2869
|
});
|
|
2691
2870
|
}
|
|
2692
2871
|
const assignmentPayload = {
|
|
@@ -2724,6 +2903,7 @@ export {
|
|
|
2724
2903
|
AssinafyClient,
|
|
2725
2904
|
AssinafyError,
|
|
2726
2905
|
AuthenticationResource,
|
|
2906
|
+
ContractResource,
|
|
2727
2907
|
DocumentResource,
|
|
2728
2908
|
FieldsResource,
|
|
2729
2909
|
NOTIFICATION_PREFERENCE_CODES,
|