@assinafy/sdk 3.0.1 → 3.1.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/CHANGELOG.md +39 -1
- package/README.en.md +6 -0
- package/README.md +7 -0
- package/SECURITY.md +4 -2
- package/dist/index.d.mts +351 -21
- package/dist/index.d.ts +351 -21
- package/dist/index.js +412 -26
- package/dist/index.mjs +411 -26
- package/docs/API_COVERAGE.md +18 -1
- package/docs/COMPATIBILITY.md +29 -5
- package/docs/README.en.md +99 -8
- package/docs/README.md +99 -8
- package/docs/RELEASING.md +5 -3
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __export(index_exports, {
|
|
|
48
48
|
OAuthError: () => OAuthError,
|
|
49
49
|
OAuthResource: () => OAuthResource,
|
|
50
50
|
SDK_USER_AGENT: () => SDK_USER_AGENT,
|
|
51
|
+
ScheduledSendResource: () => ScheduledSendResource,
|
|
51
52
|
SignerDocumentsResource: () => SignerDocumentsResource,
|
|
52
53
|
SignerResource: () => SignerResource,
|
|
53
54
|
TagResource: () => TagResource,
|
|
@@ -763,7 +764,7 @@ var import_axios2 = __toESM(require("axios"));
|
|
|
763
764
|
// package.json
|
|
764
765
|
var package_default = {
|
|
765
766
|
name: "@assinafy/sdk",
|
|
766
|
-
version: "3.0
|
|
767
|
+
version: "3.1.0",
|
|
767
768
|
packageManager: "bun@1.4.4",
|
|
768
769
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
769
770
|
type: "commonjs",
|
|
@@ -786,16 +787,16 @@ var package_default = {
|
|
|
786
787
|
sideEffects: false,
|
|
787
788
|
scripts: {
|
|
788
789
|
build: "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
789
|
-
test: "bun test",
|
|
790
|
-
"test:coverage": "bun test --coverage",
|
|
791
|
-
lint: "eslint src
|
|
792
|
-
"lint:fix": "eslint src
|
|
790
|
+
test: "bun test src tests/api-contract.test.ts",
|
|
791
|
+
"test:coverage": "bun test src tests/api-contract.test.ts --coverage",
|
|
792
|
+
lint: "eslint src tests/api-contract.test.ts --max-warnings=0",
|
|
793
|
+
"lint:fix": "eslint src tests/api-contract.test.ts --fix",
|
|
793
794
|
"lint:pkg": "publint --strict && attw --pack .",
|
|
794
795
|
audit: "bun audit",
|
|
795
|
-
"audit:api": "bun
|
|
796
|
+
"audit:api": "ASSINAFY_CONTRACT_CHECK=1 bun test tests/api-contract.test.ts",
|
|
796
797
|
prepack: "bun run build",
|
|
797
798
|
prepublishOnly: "bun run verify && bun run audit",
|
|
798
|
-
typecheck: "bun ./node_modules/@typescript/native/bin/tsc --noEmit && bun ./node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.
|
|
799
|
+
typecheck: "bun ./node_modules/@typescript/native/bin/tsc --noEmit && bun ./node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.tests.json",
|
|
799
800
|
verify: "bun run typecheck && bun run lint && bun run test:coverage && bun run build && bun run lint:pkg"
|
|
800
801
|
},
|
|
801
802
|
keywords: [
|
|
@@ -835,20 +836,20 @@ var package_default = {
|
|
|
835
836
|
"@types/bun": "^1.4.4",
|
|
836
837
|
"@types/node": "^22.20.5",
|
|
837
838
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
838
|
-
eslint: "^10.
|
|
839
|
+
eslint: "^10.15.0",
|
|
839
840
|
publint: "^0.3.25",
|
|
840
|
-
tsup: "^
|
|
841
|
+
tsup: "^9.0.0",
|
|
841
842
|
typescript: "^6.0.3",
|
|
842
|
-
"typescript-eslint": "^8.72.
|
|
843
|
+
"typescript-eslint": "^8.72.2"
|
|
843
844
|
},
|
|
844
845
|
dependencies: {
|
|
845
|
-
axios: "^1.21.
|
|
846
|
+
axios: "^1.21.1"
|
|
846
847
|
},
|
|
847
848
|
overrides: {
|
|
848
849
|
esbuild: "0.28.2",
|
|
849
850
|
"follow-redirects": "1.16.2",
|
|
850
851
|
"brace-expansion": "5.0.12",
|
|
851
|
-
minimatch: "11.0.
|
|
852
|
+
minimatch: "11.0.9"
|
|
852
853
|
},
|
|
853
854
|
files: [
|
|
854
855
|
"dist",
|
|
@@ -1123,6 +1124,31 @@ var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
|
1123
1124
|
"Bypass"
|
|
1124
1125
|
]);
|
|
1125
1126
|
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1127
|
+
var SIGNER_CAPACITIES = /* @__PURE__ */ new Set([
|
|
1128
|
+
"Sign",
|
|
1129
|
+
"Approve",
|
|
1130
|
+
"Acknowledge",
|
|
1131
|
+
"Party",
|
|
1132
|
+
"Witness",
|
|
1133
|
+
"Intervening",
|
|
1134
|
+
"Receipt",
|
|
1135
|
+
"IssuerEndorserGuarantor",
|
|
1136
|
+
"IssuerEndorserGuarantorSurety",
|
|
1137
|
+
"Surety",
|
|
1138
|
+
"PartySurety",
|
|
1139
|
+
"JointDebtor",
|
|
1140
|
+
"PartyJointDebtor",
|
|
1141
|
+
"ContractingParty",
|
|
1142
|
+
"ContractedParty",
|
|
1143
|
+
"Landlord",
|
|
1144
|
+
"Tenant",
|
|
1145
|
+
"Buyer",
|
|
1146
|
+
"Seller",
|
|
1147
|
+
"AttorneyInFact",
|
|
1148
|
+
"LegalRepresentative",
|
|
1149
|
+
"Employer",
|
|
1150
|
+
"Employee"
|
|
1151
|
+
]);
|
|
1126
1152
|
var EMBEDDED_VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1127
1153
|
var DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD = "digital_certificate_requires_virtual_method";
|
|
1128
1154
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
@@ -1254,6 +1280,7 @@ function buildAssignmentEstimatePayload(payload) {
|
|
|
1254
1280
|
}
|
|
1255
1281
|
const normalisedSigners = signers.map((signer) => normaliseEstimateSigner(signer));
|
|
1256
1282
|
validateDigitalCertificateMethod(method, normalisedSigners);
|
|
1283
|
+
validateSigningOrder(normalisedSigners, "assignment cost signers");
|
|
1257
1284
|
return cleanParams({
|
|
1258
1285
|
method,
|
|
1259
1286
|
signers: normalisedSigners,
|
|
@@ -1275,6 +1302,7 @@ function normaliseSignerRef(ref) {
|
|
|
1275
1302
|
if (ref && typeof ref === "object") {
|
|
1276
1303
|
const input = ref;
|
|
1277
1304
|
validateAssignmentSignerOptions(input);
|
|
1305
|
+
validateSignerCapacity(input.sign_as);
|
|
1278
1306
|
const id = input.id ?? input.signer_id;
|
|
1279
1307
|
const normalised = cleanParams({
|
|
1280
1308
|
id,
|
|
@@ -1283,6 +1311,7 @@ function normaliseSignerRef(ref) {
|
|
|
1283
1311
|
embedded: input.embedded,
|
|
1284
1312
|
step: input.step
|
|
1285
1313
|
});
|
|
1314
|
+
if (input.sign_as !== void 0) normalised["sign_as"] = input.sign_as;
|
|
1286
1315
|
if (typeof id === "string" && id.trim().length > 0) {
|
|
1287
1316
|
return normalised;
|
|
1288
1317
|
}
|
|
@@ -1296,10 +1325,19 @@ function normaliseEstimateSigner(signer) {
|
|
|
1296
1325
|
}
|
|
1297
1326
|
const descriptor = signer;
|
|
1298
1327
|
validateAssignmentSignerOptions(descriptor);
|
|
1299
|
-
|
|
1328
|
+
validateSignerCapacity(descriptor.sign_as);
|
|
1329
|
+
const normalised = cleanParams({
|
|
1300
1330
|
verification_method: descriptor.verification_method,
|
|
1301
|
-
notification_methods: descriptor.notification_methods
|
|
1331
|
+
notification_methods: descriptor.notification_methods,
|
|
1332
|
+
step: descriptor.step
|
|
1302
1333
|
});
|
|
1334
|
+
if (descriptor.sign_as !== void 0) normalised["sign_as"] = descriptor.sign_as;
|
|
1335
|
+
return normalised;
|
|
1336
|
+
}
|
|
1337
|
+
function validateSignerCapacity(value) {
|
|
1338
|
+
if (value !== void 0 && value !== null && !SIGNER_CAPACITIES.has(value)) {
|
|
1339
|
+
throw new ValidationError("sign_as must be a supported signer capacity or null");
|
|
1340
|
+
}
|
|
1303
1341
|
}
|
|
1304
1342
|
function normaliseAssignmentEntries(entries) {
|
|
1305
1343
|
if (!Array.isArray(entries)) {
|
|
@@ -1537,6 +1575,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1537
1575
|
* This route takes no `Idempotency-Key`: a document takes one assignment,
|
|
1538
1576
|
* so a retry after a lost response answers `400` and charges nothing —
|
|
1539
1577
|
* read the document to see whether the first request went through.
|
|
1578
|
+
* @param payload.signers[].sign_as - Staging capacity printed on the certificate; omitted/null means `Sign`.
|
|
1540
1579
|
* @returns The created {@link IAssignment}: `signers` (rich, with `step` /
|
|
1541
1580
|
* `notified` / `verification_method`), `items` (one row per signer × field),
|
|
1542
1581
|
* a `summary` count block, and per-signer `signing_urls`. Response shape:
|
|
@@ -1675,9 +1714,11 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1675
1714
|
* ```
|
|
1676
1715
|
*
|
|
1677
1716
|
* @param documentId - The document the assignment would be created on.
|
|
1678
|
-
* @param payload - `method` plus channel
|
|
1679
|
-
* `collect`-mode `entries`.
|
|
1680
|
-
*
|
|
1717
|
+
* @param payload - `method` plus signer channel descriptors and/or
|
|
1718
|
+
* `collect`-mode `entries`. Signer IDs are not part of this request. Send
|
|
1719
|
+
* each signer's creation `step` too: the API keeps every
|
|
1720
|
+
* `DigitalCertificate` signer alone in its step when it estimates.
|
|
1721
|
+
* @param payload.signers[].sign_as - Optional staging capacity, validated as on creation; it does not change the cost.
|
|
1681
1722
|
* @returns an {@link ICostEstimate} with `total_credits`, balances, a
|
|
1682
1723
|
* line-item `breakdown`, and a `has_sufficient_resources` gate.
|
|
1683
1724
|
* `blocking_reason` may be `PendingPayment`, `InsufficientDocuments`, or
|
|
@@ -1699,7 +1740,8 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1699
1740
|
* ```
|
|
1700
1741
|
* @throws {ValidationError} If `documentId` is missing, a `virtual` request
|
|
1701
1742
|
* has no signer entry, or a `collect` request has no signer entry or no
|
|
1702
|
-
* field-placement entry,
|
|
1743
|
+
* field-placement entry, the signing order is invalid, or the request
|
|
1744
|
+
* combines `DigitalCertificate` with `collect`.
|
|
1703
1745
|
* The last case has `errors.code ===
|
|
1704
1746
|
* 'digital_certificate_requires_virtual_method'`.
|
|
1705
1747
|
* @throws {ApiError} If the API rejects the request.
|
|
@@ -2066,6 +2108,57 @@ var AssignmentResource = class extends BaseResource {
|
|
|
2066
2108
|
() => this.http.post(`${path2}/review`, body)
|
|
2067
2109
|
);
|
|
2068
2110
|
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Read the capacity each signer signs in (`GET /documents/{documentId}/signer-capacities`).
|
|
2113
|
+
*
|
|
2114
|
+
* Staging extension. Order matches the assignment's signers; an unsent
|
|
2115
|
+
* document returns an empty list. OAuth applications need `documents:read`.
|
|
2116
|
+
* @param documentId - Workspace document ID.
|
|
2117
|
+
* @returns Sender-stated capacities, defaulting to `Sign`:
|
|
2118
|
+
* ```jsonc
|
|
2119
|
+
* [{ "signer_id": "signer-1", "sign_as": "Witness" }]
|
|
2120
|
+
* ```
|
|
2121
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
2122
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or an older deployment.
|
|
2123
|
+
* @example
|
|
2124
|
+
* ```ts
|
|
2125
|
+
* const capacities = await client.assignments.getSignerCapacities(document.id);
|
|
2126
|
+
* ```
|
|
2127
|
+
*/
|
|
2128
|
+
async getSignerCapacities(documentId) {
|
|
2129
|
+
return this.call(
|
|
2130
|
+
"Failed to fetch signer capacities",
|
|
2131
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/signer-capacities`)
|
|
2132
|
+
);
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Read delivery and open times (`GET /documents/{documentId}/notification-history`).
|
|
2136
|
+
*
|
|
2137
|
+
* Staging extension. An open can come from a mail scanner; it is not proof
|
|
2138
|
+
* of human reading. An unsent document returns `[]`. Needs `documents:read`.
|
|
2139
|
+
* @param documentId - Workspace document ID.
|
|
2140
|
+
* @returns History in assignment-signer order:
|
|
2141
|
+
* ```jsonc
|
|
2142
|
+
* [{ "signer_id": "signer-1", "notification_history": [{
|
|
2143
|
+
* "event": "signature_request", "status": "delivered",
|
|
2144
|
+
* "error_code": null, "error_message": null,
|
|
2145
|
+
* "sent_at": "2026-11-24T12:00:00Z", "failed_at": null,
|
|
2146
|
+
* "delivered_at": "2026-11-24T12:00:05Z", "opened_at": null
|
|
2147
|
+
* }] }]
|
|
2148
|
+
* ```
|
|
2149
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
2150
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or an older deployment.
|
|
2151
|
+
* @example
|
|
2152
|
+
* ```ts
|
|
2153
|
+
* const history = await client.assignments.getNotificationHistory(document.id);
|
|
2154
|
+
* ```
|
|
2155
|
+
*/
|
|
2156
|
+
async getNotificationHistory(documentId) {
|
|
2157
|
+
return this.call(
|
|
2158
|
+
"Failed to fetch notification history",
|
|
2159
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/notification-history`)
|
|
2160
|
+
);
|
|
2161
|
+
}
|
|
2069
2162
|
identityVerificationPath(documentId, assignmentId, signerId) {
|
|
2070
2163
|
const docId = this.pathSegment(documentId, "Document ID");
|
|
2071
2164
|
const asgId = this.pathSegment(assignmentId, "Assignment ID");
|
|
@@ -3087,9 +3180,10 @@ var DocumentResource = class extends BaseResource {
|
|
|
3087
3180
|
*
|
|
3088
3181
|
* @param templateId - The template that would be instantiated.
|
|
3089
3182
|
* @param signers - One channel descriptor per template role. Cost requests
|
|
3090
|
-
* use
|
|
3091
|
-
*
|
|
3092
|
-
*
|
|
3183
|
+
* use `role_id`, `verification_method`, `notification_methods`, and the
|
|
3184
|
+
* role's creation `step`, which the API reads to keep each
|
|
3185
|
+
* `DigitalCertificate` signer alone in its step; they send no signer ID,
|
|
3186
|
+
* and editor roles are ignored by the cost calculation.
|
|
3093
3187
|
* @param accountId - Override the client's default account ID.
|
|
3094
3188
|
* @returns An {@link ICostEstimate}: `total_credits`, balances, and a
|
|
3095
3189
|
* per-line `breakdown` of what the operation would consume:
|
|
@@ -3382,6 +3476,66 @@ var DocumentResource = class extends BaseResource {
|
|
|
3382
3476
|
const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
|
|
3383
3477
|
return { signed, total, pending, percentage };
|
|
3384
3478
|
}
|
|
3479
|
+
/**
|
|
3480
|
+
* List contacts watching a document (`GET /documents/{documentId}/watchers`).
|
|
3481
|
+
*
|
|
3482
|
+
* Staging extension. Returns contacts in the order set, omitting deleted
|
|
3483
|
+
* contacts. API key or user token only; OAuth application tokens are refused.
|
|
3484
|
+
* @param documentId - Workspace document ID.
|
|
3485
|
+
* @returns Watcher contacts:
|
|
3486
|
+
* ```jsonc
|
|
3487
|
+
* [{ "resource": "signer", "id": "signer-1", "full_name": "Example Watcher",
|
|
3488
|
+
* "email": "watcher@example.com", "whatsapp_phone_number": null,
|
|
3489
|
+
* "government_id": null, "has_accepted_terms": false }]
|
|
3490
|
+
* ```
|
|
3491
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
3492
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or older deployment.
|
|
3493
|
+
* @example
|
|
3494
|
+
* ```ts
|
|
3495
|
+
* const watchers = await client.documents.listWatchers(document.id);
|
|
3496
|
+
* ```
|
|
3497
|
+
*/
|
|
3498
|
+
async listWatchers(documentId) {
|
|
3499
|
+
return this.call(
|
|
3500
|
+
"Failed to list document watchers",
|
|
3501
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/watchers`)
|
|
3502
|
+
);
|
|
3503
|
+
}
|
|
3504
|
+
/**
|
|
3505
|
+
* Replace a document's watchers (`PUT /documents/{documentId}/watchers`).
|
|
3506
|
+
*
|
|
3507
|
+
* Staging extension. Each contact must belong to the workspace and have an
|
|
3508
|
+
* email. Watchers get one queued email when the document ends, without a
|
|
3509
|
+
* document link or file. Workspace notification preferences do not suppress
|
|
3510
|
+
* it. Set before sending or while open; `[]` removes every watcher.
|
|
3511
|
+
* API key or user token only; OAuth application tokens are refused.
|
|
3512
|
+
* @param documentId - Workspace document ID.
|
|
3513
|
+
* @param watcherIds - Up to ten contact IDs; duplicate IDs count once.
|
|
3514
|
+
* @returns The stored contacts:
|
|
3515
|
+
* ```jsonc
|
|
3516
|
+
* [{ "resource": "signer", "id": "signer-1", "full_name": "Example Watcher",
|
|
3517
|
+
* "email": "watcher@example.com", "whatsapp_phone_number": null,
|
|
3518
|
+
* "government_id": null, "has_accepted_terms": false }]
|
|
3519
|
+
* ```
|
|
3520
|
+
* @throws {ValidationError} If an ID is invalid or more than ten distinct watchers are supplied.
|
|
3521
|
+
* @throws {ApiError} `400` for a closed document or invalid contact; `401`, `403`, `404`.
|
|
3522
|
+
* @example
|
|
3523
|
+
* ```ts
|
|
3524
|
+
* await client.documents.setWatchers(document.id, [contact.id]);
|
|
3525
|
+
* // body: { watcher_ids: [contact.id] }
|
|
3526
|
+
* ```
|
|
3527
|
+
*/
|
|
3528
|
+
async setWatchers(documentId, watcherIds) {
|
|
3529
|
+
if (!Array.isArray(watcherIds) || watcherIds.some((id) => typeof id !== "string" || !id.trim()) || new Set(watcherIds).size > 10) {
|
|
3530
|
+
throw new ValidationError("watcherIds must contain at most ten distinct non-empty contact IDs");
|
|
3531
|
+
}
|
|
3532
|
+
return this.call(
|
|
3533
|
+
"Failed to set document watchers",
|
|
3534
|
+
() => this.http.put(`/documents/${this.pathSegment(documentId, "Document ID")}/watchers`, {
|
|
3535
|
+
watcher_ids: watcherIds
|
|
3536
|
+
})
|
|
3537
|
+
);
|
|
3538
|
+
}
|
|
3385
3539
|
};
|
|
3386
3540
|
function normaliseTemplateSigners(signers) {
|
|
3387
3541
|
if (!Array.isArray(signers) || signers.length === 0) {
|
|
@@ -3478,6 +3632,7 @@ function normaliseTemplateCostSigners(signers) {
|
|
|
3478
3632
|
if (signer.notification_methods !== void 0) {
|
|
3479
3633
|
descriptor.notification_methods = signer.notification_methods;
|
|
3480
3634
|
}
|
|
3635
|
+
if (signer.step !== void 0) descriptor.step = signer.step;
|
|
3481
3636
|
return descriptor;
|
|
3482
3637
|
});
|
|
3483
3638
|
return normalised;
|
|
@@ -9313,7 +9468,8 @@ var ContractResource = class extends BaseResource {
|
|
|
9313
9468
|
* @param payload.currency - Three-letter currency; null resets as documented.
|
|
9314
9469
|
* @param payload.start_date - Start date (`YYYY-MM-DD`), or null.
|
|
9315
9470
|
* @param payload.end_date - End date (`YYYY-MM-DD`), or null.
|
|
9316
|
-
* @param payload.auto_renew - Whether the hourly lifecycle starts a new term
|
|
9471
|
+
* @param payload.auto_renew - Whether the hourly lifecycle starts a new term;
|
|
9472
|
+
* null resets it to false, or drops it from a pending amendment's terms.
|
|
9317
9473
|
* @param payload.renewal_term_months - 1–600 months, or null for the default.
|
|
9318
9474
|
* @param payload.notice_period_days - 0–3650 days, or null to disable notice.
|
|
9319
9475
|
* @param payload.owner_id - Active workspace member ID, or null.
|
|
@@ -9618,8 +9774,8 @@ function buildContractInput(payload) {
|
|
|
9618
9774
|
if (typeof payload.start_date === "string" && typeof payload.end_date === "string" && payload.end_date < payload.start_date) {
|
|
9619
9775
|
throw new ValidationError("end_date must be on or after start_date");
|
|
9620
9776
|
}
|
|
9621
|
-
if (payload.auto_renew !== void 0 && typeof payload.auto_renew !== "boolean") {
|
|
9622
|
-
throw new ValidationError("auto_renew must be a boolean");
|
|
9777
|
+
if (payload.auto_renew !== void 0 && payload.auto_renew !== null && typeof payload.auto_renew !== "boolean") {
|
|
9778
|
+
throw new ValidationError("auto_renew must be a boolean or null");
|
|
9623
9779
|
}
|
|
9624
9780
|
validateNullableInteger(payload.renewal_term_months, "renewal_term_months", 1, 600);
|
|
9625
9781
|
validateNullableInteger(payload.notice_period_days, "notice_period_days", 0, 3650);
|
|
@@ -9978,6 +10134,7 @@ var EnvelopeResource = class extends BaseResource {
|
|
|
9978
10134
|
*
|
|
9979
10135
|
* @param envelopeId - Envelope ID.
|
|
9980
10136
|
* @param accountId - Override the client's default account ID.
|
|
10137
|
+
* @returns Nothing; the acknowledgement body is discarded.
|
|
9981
10138
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9982
10139
|
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
9983
10140
|
* unknown envelope, `409` (`EnvelopeOpen`) while a document is still open.
|
|
@@ -10195,6 +10352,35 @@ var EnvelopeResource = class extends BaseResource {
|
|
|
10195
10352
|
)
|
|
10196
10353
|
);
|
|
10197
10354
|
}
|
|
10355
|
+
/**
|
|
10356
|
+
* Price a whole-envelope reminder
|
|
10357
|
+
* (`POST /accounts/{accountId}/envelopes/{envelopeId}/signers/{signerId}/estimate-resend-cost`).
|
|
10358
|
+
*
|
|
10359
|
+
* Staging extension. Sends and charges nothing. Prices one reminder per
|
|
10360
|
+
* channel regardless of document count, without checking reminder cooldown
|
|
10361
|
+
* or whether the envelope is closed. OAuth requires `documents:write`.
|
|
10362
|
+
* @param envelopeId - Envelope ID.
|
|
10363
|
+
* @param signerId - Signer of the envelope.
|
|
10364
|
+
* @param accountId - Override the client's default workspace.
|
|
10365
|
+
* @returns The current reminder price:
|
|
10366
|
+
* ```jsonc
|
|
10367
|
+
* { "total": 0, "breakdown": [], "credit_balance": null, "has_sufficient_credits": true }
|
|
10368
|
+
* ```
|
|
10369
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10370
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown envelope/signer or older deployment.
|
|
10371
|
+
* @example
|
|
10372
|
+
* ```ts
|
|
10373
|
+
* const estimate = await client.envelopes.estimateResendCost(envelope.id, signer.id);
|
|
10374
|
+
* ```
|
|
10375
|
+
*/
|
|
10376
|
+
async estimateResendCost(envelopeId, signerId, accountId) {
|
|
10377
|
+
return this.call(
|
|
10378
|
+
"Failed to estimate envelope reminder cost",
|
|
10379
|
+
() => this.http.post(
|
|
10380
|
+
`${this.envelopePath(envelopeId, accountId)}/signers/${this.pathSegment(signerId, "Signer ID")}/estimate-resend-cost`
|
|
10381
|
+
)
|
|
10382
|
+
);
|
|
10383
|
+
}
|
|
10198
10384
|
envelopesPath(accountId) {
|
|
10199
10385
|
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/envelopes`;
|
|
10200
10386
|
}
|
|
@@ -10368,6 +10554,7 @@ var EmbedResource = class extends BaseResource {
|
|
|
10368
10554
|
*
|
|
10369
10555
|
* @param originId - Embed origin ID.
|
|
10370
10556
|
* @param accountId - Override the client's default account ID.
|
|
10557
|
+
* @returns Nothing; the acknowledgement body is discarded.
|
|
10371
10558
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10372
10559
|
* @throws {ApiError} `403`, or `404` for an unknown origin ID.
|
|
10373
10560
|
*
|
|
@@ -10432,6 +10619,202 @@ var EmbedResource = class extends BaseResource {
|
|
|
10432
10619
|
}
|
|
10433
10620
|
};
|
|
10434
10621
|
|
|
10622
|
+
// src/resources/scheduled-sends.ts
|
|
10623
|
+
var ScheduledSendResource = class extends BaseResource {
|
|
10624
|
+
/**
|
|
10625
|
+
* Schedule an assignment (`POST /documents/{documentId}/scheduled-sends`).
|
|
10626
|
+
*
|
|
10627
|
+
* Sends and charges nothing now. Each document takes one pending or
|
|
10628
|
+
* processing scheduled send. A failed due send records its reason and
|
|
10629
|
+
* emails the scheduling member (active owners if that member has left).
|
|
10630
|
+
* @param documentId - Unassigned document in the workspace.
|
|
10631
|
+
* @param payload - The same signing request as `assignments.create()` plus its send time.
|
|
10632
|
+
* @param payload.send_at - ISO date-time (no offset means UTC) or Unix seconds, one hour to 90 days ahead.
|
|
10633
|
+
* @param payload.method - `virtual` (default) or `collect`.
|
|
10634
|
+
* @param payload.signers - Contacts and their verification, notification, capacity and ordering options.
|
|
10635
|
+
* @param payload.signer_ids - Compatibility alias for signer IDs.
|
|
10636
|
+
* @param payload.signerIds - Compatibility alias for signer IDs.
|
|
10637
|
+
* @param payload.entries - Required field placements for `collect`.
|
|
10638
|
+
* @param payload.message - Invitation text.
|
|
10639
|
+
* @param payload.copy_receivers - Contacts receiving copies.
|
|
10640
|
+
* @param payload.expires_at - Absolute deadline at least two hours after send_at, or null for none.
|
|
10641
|
+
* @param payload.max_total_credits - Credit ceiling enforced when sending.
|
|
10642
|
+
* @returns The saved request's state:
|
|
10643
|
+
* ```jsonc
|
|
10644
|
+
* { "resource": "scheduled_send", "id": "send-1", "type": "assignment",
|
|
10645
|
+
* "document_ids": ["doc-1"], "status": "pending", "send_at": "2026-12-01T12:00:00Z",
|
|
10646
|
+
* "assignment_id": null, "envelope_id": null, "failure_reason": null,
|
|
10647
|
+
* "created_at": "2026-11-24T12:00:00Z", "processed_at": null }
|
|
10648
|
+
* ```
|
|
10649
|
+
* @throws {ValidationError} If the ID, time or signing request is malformed.
|
|
10650
|
+
* @throws {ApiError} `400` for timing, assignment or pending-send conflicts;
|
|
10651
|
+
* `401`, `403` for plan/scope restrictions, `404` for document/contact/deployment availability.
|
|
10652
|
+
* @example
|
|
10653
|
+
* ```ts
|
|
10654
|
+
* const scheduled = await client.scheduledSends.createAssignment(document.id, {
|
|
10655
|
+
* signers: [{ id: signer.id, verification_method: 'Email', notification_methods: ['Email'] }],
|
|
10656
|
+
* send_at: new Date(Date.now() + 86_400_000).toISOString(),
|
|
10657
|
+
* max_total_credits: 0,
|
|
10658
|
+
* });
|
|
10659
|
+
* ```
|
|
10660
|
+
*/
|
|
10661
|
+
async createAssignment(documentId, payload) {
|
|
10662
|
+
assertRecord(payload, "scheduled assignment");
|
|
10663
|
+
validateTimestamp(payload.send_at, "send_at");
|
|
10664
|
+
const { expires_at, ...assignment } = payload;
|
|
10665
|
+
const body = buildAssignmentPayload(assignment);
|
|
10666
|
+
body["send_at"] = payload.send_at;
|
|
10667
|
+
if (expires_at !== void 0) {
|
|
10668
|
+
if (expires_at !== null) validateTimestamp(expires_at, "expires_at");
|
|
10669
|
+
body["expires_at"] = expires_at;
|
|
10670
|
+
}
|
|
10671
|
+
return this.call(
|
|
10672
|
+
"Failed to schedule assignment",
|
|
10673
|
+
() => this.http.post(`/documents/${this.pathSegment(documentId, "Document ID")}/scheduled-sends`, body)
|
|
10674
|
+
);
|
|
10675
|
+
}
|
|
10676
|
+
/**
|
|
10677
|
+
* Schedule an envelope (`POST /accounts/{accountId}/scheduled-sends`).
|
|
10678
|
+
*
|
|
10679
|
+
* Creates no envelope and charges nothing now. Uses the same plan and
|
|
10680
|
+
* signing rules as envelope estimation; checks balances when sending.
|
|
10681
|
+
* @param payload - Envelope request and send time.
|
|
10682
|
+
* @param payload.send_at - ISO date-time or Unix seconds, one hour to 90 days ahead.
|
|
10683
|
+
* @param payload.name - Envelope name, 1–255 characters without `<`.
|
|
10684
|
+
* @param payload.message - Invitation text or null.
|
|
10685
|
+
* @param payload.signers - 1–20 contacts with shared channel options; no signing steps.
|
|
10686
|
+
* @param payload.documents - 1–20 unassigned documents, signer IDs and optional placements/copy receivers.
|
|
10687
|
+
* Each document's expires_at must be at least two hours after send_at.
|
|
10688
|
+
* @param payload.max_total_credits - Credit ceiling enforced when sending.
|
|
10689
|
+
* @param accountId - Override the client's default workspace.
|
|
10690
|
+
* @returns The saved request's state:
|
|
10691
|
+
* ```jsonc
|
|
10692
|
+
* { "resource": "scheduled_send", "id": "send-2", "type": "envelope",
|
|
10693
|
+
* "document_ids": ["doc-1", "doc-2"], "status": "pending", "send_at": "2026-12-01T12:00:00Z",
|
|
10694
|
+
* "assignment_id": null, "envelope_id": null, "failure_reason": null,
|
|
10695
|
+
* "created_at": "2026-11-24T12:00:00Z", "processed_at": null }
|
|
10696
|
+
* ```
|
|
10697
|
+
* @throws {ValidationError} If the time or envelope request is malformed.
|
|
10698
|
+
* @throws {ApiError} `400` for timing or envelope/pending-send conflicts;
|
|
10699
|
+
* `401`, `403` (`PlanRestricted`, `InsufficientScope`), `404`.
|
|
10700
|
+
* @example
|
|
10701
|
+
* ```ts
|
|
10702
|
+
* const scheduled = await client.scheduledSends.createEnvelope({
|
|
10703
|
+
* name: 'Agreement', signers: [{ id: signer.id }],
|
|
10704
|
+
* documents: [{ id: document.id, signer_ids: [signer.id] }],
|
|
10705
|
+
* send_at: new Date(Date.now() + 86_400_000).toISOString(),
|
|
10706
|
+
* });
|
|
10707
|
+
* ```
|
|
10708
|
+
*/
|
|
10709
|
+
async createEnvelope(payload, accountId) {
|
|
10710
|
+
assertRecord(payload, "scheduled envelope");
|
|
10711
|
+
validateTimestamp(payload.send_at, "send_at");
|
|
10712
|
+
const body = buildEnvelopePayload(payload);
|
|
10713
|
+
body["send_at"] = payload.send_at;
|
|
10714
|
+
return this.call("Failed to schedule envelope", () => this.http.post(this.path(accountId), body));
|
|
10715
|
+
}
|
|
10716
|
+
/**
|
|
10717
|
+
* List scheduled sends (`GET /accounts/{accountId}/scheduled-sends`).
|
|
10718
|
+
*
|
|
10719
|
+
* Newest first, in every state. Requires `documents:write`, because failure
|
|
10720
|
+
* reasons can expose balance and workspace membership information.
|
|
10721
|
+
* @param params - Optional document filter and pagination.
|
|
10722
|
+
* @param params.document_id - Return only sends containing this document.
|
|
10723
|
+
* @param params.page - One-based page number.
|
|
10724
|
+
* @param params.per-page - Page size, default 20 and maximum 50.
|
|
10725
|
+
* @param params.per_page - Compatibility alias for per-page.
|
|
10726
|
+
* @param accountId - Override the client's default workspace.
|
|
10727
|
+
* @returns Requests and header-derived pagination:
|
|
10728
|
+
* ```jsonc
|
|
10729
|
+
* { "data": [{ "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10730
|
+
* "status": "sent", "send_at": "2026-12-01T12:00:00Z", "assignment_id": "assignment-1",
|
|
10731
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10732
|
+
* "processed_at": "2026-12-01T12:00:03Z" }],
|
|
10733
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 } }
|
|
10734
|
+
* ```
|
|
10735
|
+
* @throws {ValidationError} If the workspace/filter is invalid.
|
|
10736
|
+
* @throws {ApiError} `400` for an invalid filter, `401`, `403`, `404`.
|
|
10737
|
+
* @example
|
|
10738
|
+
* ```ts
|
|
10739
|
+
* const sends = await client.scheduledSends.list({ document_id: document.id });
|
|
10740
|
+
* ```
|
|
10741
|
+
*/
|
|
10742
|
+
async list(params = {}, accountId) {
|
|
10743
|
+
assertRecord(params, "scheduled send list parameters");
|
|
10744
|
+
if (params.document_id !== void 0) assertNonEmptyString(params.document_id, "document_id");
|
|
10745
|
+
return this.callList(
|
|
10746
|
+
"Failed to list scheduled sends",
|
|
10747
|
+
() => this.http.get(this.path(accountId), { params: cleanListParams({ ...params }) })
|
|
10748
|
+
);
|
|
10749
|
+
}
|
|
10750
|
+
/**
|
|
10751
|
+
* Cancel a pending send (`PUT /accounts/{accountId}/scheduled-sends/{scheduledSendId}/cancel`).
|
|
10752
|
+
*
|
|
10753
|
+
* Sends and charges nothing. A second cancellation is a conflict.
|
|
10754
|
+
* @param scheduledSendId - Pending scheduled send ID.
|
|
10755
|
+
* @param accountId - Override the client's default workspace.
|
|
10756
|
+
* @returns The cancelled state:
|
|
10757
|
+
* ```jsonc
|
|
10758
|
+
* { "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10759
|
+
* "status": "cancelled", "send_at": "2026-12-01T12:00:00Z", "assignment_id": null,
|
|
10760
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10761
|
+
* "processed_at": "2026-11-24T12:05:00Z" }
|
|
10762
|
+
* ```
|
|
10763
|
+
* @throws {ValidationError} If an ID is invalid.
|
|
10764
|
+
* @throws {ApiError} `401`, `403`, `404`, `409` if no longer pending.
|
|
10765
|
+
* @example
|
|
10766
|
+
* ```ts
|
|
10767
|
+
* await client.scheduledSends.cancel(scheduled.id);
|
|
10768
|
+
* ```
|
|
10769
|
+
*/
|
|
10770
|
+
async cancel(scheduledSendId, accountId) {
|
|
10771
|
+
return this.call(
|
|
10772
|
+
"Failed to cancel scheduled send",
|
|
10773
|
+
() => this.http.put(`${this.path(accountId)}/${this.pathSegment(scheduledSendId, "Scheduled send ID")}/cancel`)
|
|
10774
|
+
);
|
|
10775
|
+
}
|
|
10776
|
+
/**
|
|
10777
|
+
* Send a pending request now (`PUT /accounts/{accountId}/scheduled-sends/{scheduledSendId}/send`).
|
|
10778
|
+
*
|
|
10779
|
+
* Checks and charges as the scheduling member. A refusal leaves it pending
|
|
10780
|
+
* for its original time; cancel it explicitly to stop that future attempt.
|
|
10781
|
+
* @param scheduledSendId - Pending scheduled send ID.
|
|
10782
|
+
* @param accountId - Override the client's default workspace.
|
|
10783
|
+
* @returns The sent state and created assignment or envelope ID:
|
|
10784
|
+
* ```jsonc
|
|
10785
|
+
* { "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10786
|
+
* "status": "sent", "send_at": "2026-12-01T12:00:00Z", "assignment_id": "assignment-1",
|
|
10787
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10788
|
+
* "processed_at": "2026-11-24T13:00:00Z" }
|
|
10789
|
+
* ```
|
|
10790
|
+
* @throws {ValidationError} If an ID is invalid.
|
|
10791
|
+
* @throws {ApiError} `400` for invalid requests/balances or departed members;
|
|
10792
|
+
* `401`, `403`, `404`, `409` if no longer pending or `CreditCeilingExceeded`.
|
|
10793
|
+
* @example
|
|
10794
|
+
* ```ts
|
|
10795
|
+
* const sent = await client.scheduledSends.sendNow(scheduled.id);
|
|
10796
|
+
* ```
|
|
10797
|
+
*/
|
|
10798
|
+
async sendNow(scheduledSendId, accountId) {
|
|
10799
|
+
return this.call(
|
|
10800
|
+
"Failed to send scheduled request",
|
|
10801
|
+
() => this.http.put(`${this.path(accountId)}/${this.pathSegment(scheduledSendId, "Scheduled send ID")}/send`)
|
|
10802
|
+
);
|
|
10803
|
+
}
|
|
10804
|
+
path(accountId) {
|
|
10805
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/scheduled-sends`;
|
|
10806
|
+
}
|
|
10807
|
+
};
|
|
10808
|
+
function validateTimestamp(value, label) {
|
|
10809
|
+
if (typeof value === "number") {
|
|
10810
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
10811
|
+
throw new ValidationError(`${label} must be a non-negative Unix time in seconds`);
|
|
10812
|
+
}
|
|
10813
|
+
} else {
|
|
10814
|
+
assertExpirationDate(value, label);
|
|
10815
|
+
}
|
|
10816
|
+
}
|
|
10817
|
+
|
|
10435
10818
|
// src/support/webhook-verifier.ts
|
|
10436
10819
|
var import_node_crypto2 = require("crypto");
|
|
10437
10820
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
@@ -10491,8 +10874,8 @@ var WebhookVerifier = class {
|
|
|
10491
10874
|
if (Math.abs(Date.now() / 1e3 - Number(timestamp)) > toleranceSeconds) return false;
|
|
10492
10875
|
const expected = (0, import_node_crypto2.createHmac)("sha256", key).update(`${id}.${timestamp}.`).update(payload).digest();
|
|
10493
10876
|
return signatures.split(" ").some((entry) => {
|
|
10494
|
-
const [version, signature] = entry.split(","
|
|
10495
|
-
if (version !== "v1" || !signature) return false;
|
|
10877
|
+
const [version, signature, extra] = entry.split(",");
|
|
10878
|
+
if (version !== "v1" || !signature || extra !== void 0) return false;
|
|
10496
10879
|
const actual = Buffer.from(signature, "base64");
|
|
10497
10880
|
if (actual.toString("base64") !== signature) return false;
|
|
10498
10881
|
return actual.length === expected.length && (0, import_node_crypto2.timingSafeEqual)(actual, expected);
|
|
@@ -10624,6 +11007,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
10624
11007
|
contracts;
|
|
10625
11008
|
envelopes;
|
|
10626
11009
|
embed;
|
|
11010
|
+
scheduledSends;
|
|
10627
11011
|
webhookVerifier;
|
|
10628
11012
|
/**
|
|
10629
11013
|
* Create a client. Supply `apiKey` (preferred, sent as `X-Api-Key`) or a
|
|
@@ -10753,6 +11137,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
10753
11137
|
);
|
|
10754
11138
|
this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10755
11139
|
this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
11140
|
+
this.scheduledSends = new ScheduledSendResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10756
11141
|
this.webhookVerifier = new WebhookVerifier(this.webhookSecret);
|
|
10757
11142
|
}
|
|
10758
11143
|
/**
|
|
@@ -11193,6 +11578,7 @@ function hasIdempotencyKey(headers) {
|
|
|
11193
11578
|
OAuthError,
|
|
11194
11579
|
OAuthResource,
|
|
11195
11580
|
SDK_USER_AGENT,
|
|
11581
|
+
ScheduledSendResource,
|
|
11196
11582
|
SignerDocumentsResource,
|
|
11197
11583
|
SignerResource,
|
|
11198
11584
|
TagResource,
|