@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.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 });
|
|
@@ -480,7 +486,7 @@ function buildAssignmentPayload(payload, options = {}) {
|
|
|
480
486
|
method,
|
|
481
487
|
signers: normalisedSigners,
|
|
482
488
|
message: payload.message,
|
|
483
|
-
expires_at: payload.expires_at === void 0 ? void 0 :
|
|
489
|
+
expires_at: payload.expires_at === void 0 ? void 0 : requireExpiration(payload.expires_at),
|
|
484
490
|
copy_receivers: payload.copy_receivers,
|
|
485
491
|
entries: payload.entries
|
|
486
492
|
});
|
|
@@ -618,13 +624,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
618
624
|
}
|
|
619
625
|
/**
|
|
620
626
|
* Update the expiration date of an existing assignment.
|
|
621
|
-
*
|
|
622
|
-
*
|
|
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.
|
|
623
629
|
*/
|
|
624
630
|
async resetExpiration(documentId, assignmentId, expiresAt) {
|
|
625
631
|
const docId = this.requireId(documentId, "Document ID");
|
|
626
632
|
const asgId = this.requireId(assignmentId, "Assignment ID");
|
|
627
|
-
if (expiresAt !== null)
|
|
633
|
+
if (expiresAt !== null) requireExpiration(expiresAt, "expiresAt");
|
|
628
634
|
return this.call(
|
|
629
635
|
"Failed to update assignment expiration",
|
|
630
636
|
() => this.http.put(`/documents/${docId}/assignments/${asgId}/reset-expiration`, {
|
|
@@ -676,7 +682,7 @@ function requireReauth(payload) {
|
|
|
676
682
|
return payload;
|
|
677
683
|
}
|
|
678
684
|
var AuthenticationResource = class extends BaseResource {
|
|
679
|
-
/** `POST /login` —
|
|
685
|
+
/** `POST /login` — return an authenticated session or a two-factor challenge. */
|
|
680
686
|
async login(email, password) {
|
|
681
687
|
if (!email) throw new ValidationError("email is required");
|
|
682
688
|
if (!password) throw new ValidationError("password is required");
|
|
@@ -819,6 +825,156 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
819
825
|
}
|
|
820
826
|
};
|
|
821
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
|
+
|
|
822
978
|
// src/api/resources/documents.ts
|
|
823
979
|
var import_node_fs = require("fs");
|
|
824
980
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -914,7 +1070,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
914
1070
|
if (!name?.trim()) throw new ValidationError("name is required");
|
|
915
1071
|
return this.call(
|
|
916
1072
|
"Failed to rename document",
|
|
917
|
-
() => this.http.patch(`/documents/${id}`, { name })
|
|
1073
|
+
() => this.http.patch(`/documents/${id}`, { name }, { params: { expand: "assignment" } })
|
|
918
1074
|
);
|
|
919
1075
|
}
|
|
920
1076
|
/** Alias for {@link details}. */
|
|
@@ -1002,12 +1158,13 @@ var DocumentResource = class extends BaseResource {
|
|
|
1002
1158
|
})
|
|
1003
1159
|
);
|
|
1004
1160
|
}
|
|
1005
|
-
/** Fetch the document activity log. */
|
|
1006
|
-
async activities(documentId) {
|
|
1161
|
+
/** Fetch one page of the document activity log (20 entries by default). */
|
|
1162
|
+
async activities(documentId, params = {}) {
|
|
1007
1163
|
const id = this.requireId(documentId, "Document ID");
|
|
1164
|
+
requireSort(params.sort, ["id", "-id"]);
|
|
1008
1165
|
const result = await this.call(
|
|
1009
1166
|
"Failed to fetch document activities",
|
|
1010
|
-
() => this.http.get(`/documents/${id}/activities
|
|
1167
|
+
() => this.http.get(`/documents/${id}/activities`, { params: cleanParams({ ...params }) })
|
|
1011
1168
|
);
|
|
1012
1169
|
return result ?? [];
|
|
1013
1170
|
}
|
|
@@ -1073,8 +1230,8 @@ var DocumentResource = class extends BaseResource {
|
|
|
1073
1230
|
async createFromTemplate(templateId, signers, options = {}, accountId) {
|
|
1074
1231
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1075
1232
|
const accId = this.accountId(accountId);
|
|
1076
|
-
validateTemplateSigners(signers, {
|
|
1077
|
-
if (options.expires_at !== void 0)
|
|
1233
|
+
validateTemplateSigners(signers, { requireIdentity: true });
|
|
1234
|
+
if (options.expires_at !== void 0) requireExpiration(options.expires_at);
|
|
1078
1235
|
if (options.editor_fields !== void 0 && (!Array.isArray(options.editor_fields) || options.editor_fields.some((field) => !field?.field_id || typeof field.value !== "string"))) {
|
|
1079
1236
|
throw new ValidationError("editor_fields must contain field_id and value");
|
|
1080
1237
|
}
|
|
@@ -1093,7 +1250,7 @@ var DocumentResource = class extends BaseResource {
|
|
|
1093
1250
|
async estimateCostFromTemplate(templateId, signers, accountId) {
|
|
1094
1251
|
const tmplId = this.requireId(templateId, "Template ID");
|
|
1095
1252
|
const accId = this.accountId(accountId);
|
|
1096
|
-
validateTemplateSigners(signers, {
|
|
1253
|
+
validateTemplateSigners(signers, { requireIdentity: false });
|
|
1097
1254
|
await this.validateCertificateTemplateMethod(tmplId, accId, signers);
|
|
1098
1255
|
return this.call(
|
|
1099
1256
|
"Failed to estimate cost from template",
|
|
@@ -1179,8 +1336,18 @@ var DocumentResource = class extends BaseResource {
|
|
|
1179
1336
|
"Failed to fetch template",
|
|
1180
1337
|
() => this.http.get(`/accounts/${accountId}/templates/${templateId}`)
|
|
1181
1338
|
);
|
|
1182
|
-
const
|
|
1183
|
-
|
|
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
|
+
);
|
|
1184
1351
|
}
|
|
1185
1352
|
};
|
|
1186
1353
|
function validateTemplateSigners(signers, options) {
|
|
@@ -1193,17 +1360,20 @@ function validateTemplateSigners(signers, options) {
|
|
|
1193
1360
|
if (typeof signer.role_id !== "string" || !signer.role_id) {
|
|
1194
1361
|
throw new ValidationError("each template signer requires role_id");
|
|
1195
1362
|
}
|
|
1196
|
-
if (
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
if (options.
|
|
1201
|
-
|
|
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
|
+
}
|
|
1202
1375
|
}
|
|
1203
1376
|
}
|
|
1204
|
-
if (options.requireId) {
|
|
1205
|
-
validateSigningSteps(signers);
|
|
1206
|
-
}
|
|
1207
1377
|
}
|
|
1208
1378
|
async function loadSource(source) {
|
|
1209
1379
|
if ("buffer" in source) {
|
|
@@ -2124,7 +2294,11 @@ var NOTIFICATION_PREFERENCE_CODES = [
|
|
|
2124
2294
|
"DocumentExpirationReset",
|
|
2125
2295
|
"DocumentProcessingFailed",
|
|
2126
2296
|
"TemplateProcessingFailed",
|
|
2127
|
-
"SignerWhatsappFailed"
|
|
2297
|
+
"SignerWhatsappFailed",
|
|
2298
|
+
"ContractRenewalNotice",
|
|
2299
|
+
"ContractExpiring",
|
|
2300
|
+
"ContractExpired",
|
|
2301
|
+
"ContractRenewed"
|
|
2128
2302
|
];
|
|
2129
2303
|
|
|
2130
2304
|
// src/api/resources/users.ts
|
|
@@ -2286,6 +2460,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2286
2460
|
* `PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}` — update only
|
|
2287
2461
|
* the fields sent. Enabling signing creates a secret when none exists;
|
|
2288
2462
|
* disabling it discards the secret.
|
|
2463
|
+
* Enabling signing returns the new secret once, including to OAuth applications.
|
|
2289
2464
|
*/
|
|
2290
2465
|
async updateEndpoint(endpointId, payload, accountId) {
|
|
2291
2466
|
const id = this.accountId(accountId);
|
|
@@ -2332,7 +2507,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
2332
2507
|
}
|
|
2333
2508
|
/**
|
|
2334
2509
|
* `POST …/endpoints/{endpointId}/secret/rotate` — replace the signing secret.
|
|
2335
|
-
* The old secret stops working immediately.
|
|
2510
|
+
* The old secret stops working immediately. Requires `webhooks:write` for OAuth.
|
|
2336
2511
|
*/
|
|
2337
2512
|
async rotateEndpointSecret(endpointId, accountId) {
|
|
2338
2513
|
const id = this.accountId(accountId);
|
|
@@ -2584,6 +2759,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2584
2759
|
logger;
|
|
2585
2760
|
webhookSecret;
|
|
2586
2761
|
documents;
|
|
2762
|
+
contracts;
|
|
2587
2763
|
signers;
|
|
2588
2764
|
workspaces;
|
|
2589
2765
|
assignments;
|
|
@@ -2650,6 +2826,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2650
2826
|
maxRedirects: 0
|
|
2651
2827
|
});
|
|
2652
2828
|
this.documents = new DocumentResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2829
|
+
this.contracts = new ContractResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2653
2830
|
this.signers = new SignerResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
2654
2831
|
this.workspaces = new WorkspaceResource(this.axiosInstance, void 0, this.logger);
|
|
2655
2832
|
this.assignments = new AssignmentResource(
|
|
@@ -2707,12 +2884,11 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2707
2884
|
if (!Array.isArray(options.signers) || options.signers.length === 0) {
|
|
2708
2885
|
throw new ValidationError("At least one signer is required");
|
|
2709
2886
|
}
|
|
2710
|
-
if (options.expiresAt !== void 0)
|
|
2887
|
+
if (options.expiresAt !== void 0) requireExpiration(options.expiresAt, "expiresAt");
|
|
2711
2888
|
const preparedSigners = options.signers.map((signer) => {
|
|
2712
2889
|
if (!signer || typeof signer !== "object") {
|
|
2713
2890
|
throw new ValidationError("Each signer must be an object");
|
|
2714
2891
|
}
|
|
2715
|
-
validateSignerOptions(signer);
|
|
2716
2892
|
const payload = { full_name: signer.name };
|
|
2717
2893
|
if (signer.email !== void 0) payload.email = signer.email;
|
|
2718
2894
|
const phone = signer.whatsapp_phone_number ?? signer.phone;
|
|
@@ -2721,7 +2897,14 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2721
2897
|
if (signer.government_id !== void 0) payload.government_id = signer.government_id;
|
|
2722
2898
|
if (signer.metadata !== void 0) payload.metadata = signer.metadata;
|
|
2723
2899
|
validateCreateSignerPayload(payload);
|
|
2724
|
-
|
|
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 };
|
|
2725
2908
|
});
|
|
2726
2909
|
validateSigningSteps(options.signers);
|
|
2727
2910
|
this.logger.info("Starting upload + signature workflow", {
|
|
@@ -2737,15 +2920,12 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2737
2920
|
await this.documents.waitUntilReady(document.id);
|
|
2738
2921
|
}
|
|
2739
2922
|
const assignmentSigners = [];
|
|
2740
|
-
for (const {
|
|
2923
|
+
for (const { reference, payload } of preparedSigners) {
|
|
2741
2924
|
const created = await this.signers.create(payload, options.accountId);
|
|
2742
2925
|
signerIds.push(created.id);
|
|
2743
|
-
const useWhatsapp = phone !== void 0 && signer.email === void 0;
|
|
2744
2926
|
assignmentSigners.push({
|
|
2745
2927
|
id: created.id,
|
|
2746
|
-
|
|
2747
|
-
notification_methods: signer.notification_methods ?? (useWhatsapp ? ["Whatsapp"] : void 0),
|
|
2748
|
-
step: signer.step
|
|
2928
|
+
...reference
|
|
2749
2929
|
});
|
|
2750
2930
|
}
|
|
2751
2931
|
const assignmentPayload = {
|
|
@@ -2784,6 +2964,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
2784
2964
|
AssinafyClient,
|
|
2785
2965
|
AssinafyError,
|
|
2786
2966
|
AuthenticationResource,
|
|
2967
|
+
ContractResource,
|
|
2787
2968
|
DocumentResource,
|
|
2788
2969
|
FieldsResource,
|
|
2789
2970
|
NOTIFICATION_PREFERENCE_CODES,
|