@assinafy/sdk 3.0.2 → 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 +25 -1
- package/README.en.md +6 -0
- package/README.md +7 -0
- package/SECURITY.md +4 -2
- package/dist/index.d.mts +331 -11
- package/dist/index.d.ts +331 -11
- package/dist/index.js +393 -14
- package/dist/index.mjs +392 -14
- package/docs/API_COVERAGE.md +18 -1
- package/docs/COMPATIBILITY.md +22 -5
- package/docs/README.en.md +97 -7
- package/docs/README.md +97 -7
- package/docs/RELEASING.md +5 -3
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -699,7 +699,7 @@ import axios2 from "axios";
|
|
|
699
699
|
// package.json
|
|
700
700
|
var package_default = {
|
|
701
701
|
name: "@assinafy/sdk",
|
|
702
|
-
version: "3.0
|
|
702
|
+
version: "3.1.0",
|
|
703
703
|
packageManager: "bun@1.4.4",
|
|
704
704
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
705
705
|
type: "commonjs",
|
|
@@ -722,16 +722,16 @@ var package_default = {
|
|
|
722
722
|
sideEffects: false,
|
|
723
723
|
scripts: {
|
|
724
724
|
build: "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
725
|
-
test: "bun test",
|
|
726
|
-
"test:coverage": "bun test --coverage",
|
|
727
|
-
lint: "eslint src
|
|
728
|
-
"lint:fix": "eslint src
|
|
725
|
+
test: "bun test src tests/api-contract.test.ts",
|
|
726
|
+
"test:coverage": "bun test src tests/api-contract.test.ts --coverage",
|
|
727
|
+
lint: "eslint src tests/api-contract.test.ts --max-warnings=0",
|
|
728
|
+
"lint:fix": "eslint src tests/api-contract.test.ts --fix",
|
|
729
729
|
"lint:pkg": "publint --strict && attw --pack .",
|
|
730
730
|
audit: "bun audit",
|
|
731
|
-
"audit:api": "bun
|
|
731
|
+
"audit:api": "ASSINAFY_CONTRACT_CHECK=1 bun test tests/api-contract.test.ts",
|
|
732
732
|
prepack: "bun run build",
|
|
733
733
|
prepublishOnly: "bun run verify && bun run audit",
|
|
734
|
-
typecheck: "bun ./node_modules/@typescript/native/bin/tsc --noEmit && bun ./node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.
|
|
734
|
+
typecheck: "bun ./node_modules/@typescript/native/bin/tsc --noEmit && bun ./node_modules/@typescript/native/bin/tsc --noEmit -p tsconfig.tests.json",
|
|
735
735
|
verify: "bun run typecheck && bun run lint && bun run test:coverage && bun run build && bun run lint:pkg"
|
|
736
736
|
},
|
|
737
737
|
keywords: [
|
|
@@ -771,20 +771,20 @@ var package_default = {
|
|
|
771
771
|
"@types/bun": "^1.4.4",
|
|
772
772
|
"@types/node": "^22.20.5",
|
|
773
773
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
774
|
-
eslint: "^10.
|
|
774
|
+
eslint: "^10.15.0",
|
|
775
775
|
publint: "^0.3.25",
|
|
776
776
|
tsup: "^9.0.0",
|
|
777
777
|
typescript: "^6.0.3",
|
|
778
|
-
"typescript-eslint": "^8.72.
|
|
778
|
+
"typescript-eslint": "^8.72.2"
|
|
779
779
|
},
|
|
780
780
|
dependencies: {
|
|
781
|
-
axios: "^1.21.
|
|
781
|
+
axios: "^1.21.1"
|
|
782
782
|
},
|
|
783
783
|
overrides: {
|
|
784
784
|
esbuild: "0.28.2",
|
|
785
785
|
"follow-redirects": "1.16.2",
|
|
786
786
|
"brace-expansion": "5.0.12",
|
|
787
|
-
minimatch: "11.0.
|
|
787
|
+
minimatch: "11.0.9"
|
|
788
788
|
},
|
|
789
789
|
files: [
|
|
790
790
|
"dist",
|
|
@@ -1059,6 +1059,31 @@ var VERIFICATION_METHODS = /* @__PURE__ */ new Set([
|
|
|
1059
1059
|
"Bypass"
|
|
1060
1060
|
]);
|
|
1061
1061
|
var NOTIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1062
|
+
var SIGNER_CAPACITIES = /* @__PURE__ */ new Set([
|
|
1063
|
+
"Sign",
|
|
1064
|
+
"Approve",
|
|
1065
|
+
"Acknowledge",
|
|
1066
|
+
"Party",
|
|
1067
|
+
"Witness",
|
|
1068
|
+
"Intervening",
|
|
1069
|
+
"Receipt",
|
|
1070
|
+
"IssuerEndorserGuarantor",
|
|
1071
|
+
"IssuerEndorserGuarantorSurety",
|
|
1072
|
+
"Surety",
|
|
1073
|
+
"PartySurety",
|
|
1074
|
+
"JointDebtor",
|
|
1075
|
+
"PartyJointDebtor",
|
|
1076
|
+
"ContractingParty",
|
|
1077
|
+
"ContractedParty",
|
|
1078
|
+
"Landlord",
|
|
1079
|
+
"Tenant",
|
|
1080
|
+
"Buyer",
|
|
1081
|
+
"Seller",
|
|
1082
|
+
"AttorneyInFact",
|
|
1083
|
+
"LegalRepresentative",
|
|
1084
|
+
"Employer",
|
|
1085
|
+
"Employee"
|
|
1086
|
+
]);
|
|
1062
1087
|
var EMBEDDED_VERIFICATION_METHODS = /* @__PURE__ */ new Set(["Email", "Whatsapp", "Bypass"]);
|
|
1063
1088
|
var DIGITAL_CERTIFICATE_REQUIRES_VIRTUAL_METHOD = "digital_certificate_requires_virtual_method";
|
|
1064
1089
|
var ALLOWED_NOTIFICATION_METHODS = {
|
|
@@ -1212,6 +1237,7 @@ function normaliseSignerRef(ref) {
|
|
|
1212
1237
|
if (ref && typeof ref === "object") {
|
|
1213
1238
|
const input = ref;
|
|
1214
1239
|
validateAssignmentSignerOptions(input);
|
|
1240
|
+
validateSignerCapacity(input.sign_as);
|
|
1215
1241
|
const id = input.id ?? input.signer_id;
|
|
1216
1242
|
const normalised = cleanParams({
|
|
1217
1243
|
id,
|
|
@@ -1220,6 +1246,7 @@ function normaliseSignerRef(ref) {
|
|
|
1220
1246
|
embedded: input.embedded,
|
|
1221
1247
|
step: input.step
|
|
1222
1248
|
});
|
|
1249
|
+
if (input.sign_as !== void 0) normalised["sign_as"] = input.sign_as;
|
|
1223
1250
|
if (typeof id === "string" && id.trim().length > 0) {
|
|
1224
1251
|
return normalised;
|
|
1225
1252
|
}
|
|
@@ -1233,11 +1260,19 @@ function normaliseEstimateSigner(signer) {
|
|
|
1233
1260
|
}
|
|
1234
1261
|
const descriptor = signer;
|
|
1235
1262
|
validateAssignmentSignerOptions(descriptor);
|
|
1236
|
-
|
|
1263
|
+
validateSignerCapacity(descriptor.sign_as);
|
|
1264
|
+
const normalised = cleanParams({
|
|
1237
1265
|
verification_method: descriptor.verification_method,
|
|
1238
1266
|
notification_methods: descriptor.notification_methods,
|
|
1239
1267
|
step: descriptor.step
|
|
1240
1268
|
});
|
|
1269
|
+
if (descriptor.sign_as !== void 0) normalised["sign_as"] = descriptor.sign_as;
|
|
1270
|
+
return normalised;
|
|
1271
|
+
}
|
|
1272
|
+
function validateSignerCapacity(value) {
|
|
1273
|
+
if (value !== void 0 && value !== null && !SIGNER_CAPACITIES.has(value)) {
|
|
1274
|
+
throw new ValidationError("sign_as must be a supported signer capacity or null");
|
|
1275
|
+
}
|
|
1241
1276
|
}
|
|
1242
1277
|
function normaliseAssignmentEntries(entries) {
|
|
1243
1278
|
if (!Array.isArray(entries)) {
|
|
@@ -1475,6 +1510,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1475
1510
|
* This route takes no `Idempotency-Key`: a document takes one assignment,
|
|
1476
1511
|
* so a retry after a lost response answers `400` and charges nothing —
|
|
1477
1512
|
* read the document to see whether the first request went through.
|
|
1513
|
+
* @param payload.signers[].sign_as - Staging capacity printed on the certificate; omitted/null means `Sign`.
|
|
1478
1514
|
* @returns The created {@link IAssignment}: `signers` (rich, with `step` /
|
|
1479
1515
|
* `notified` / `verification_method`), `items` (one row per signer × field),
|
|
1480
1516
|
* a `summary` count block, and per-signer `signing_urls`. Response shape:
|
|
@@ -1617,6 +1653,7 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1617
1653
|
* `collect`-mode `entries`. Signer IDs are not part of this request. Send
|
|
1618
1654
|
* each signer's creation `step` too: the API keeps every
|
|
1619
1655
|
* `DigitalCertificate` signer alone in its step when it estimates.
|
|
1656
|
+
* @param payload.signers[].sign_as - Optional staging capacity, validated as on creation; it does not change the cost.
|
|
1620
1657
|
* @returns an {@link ICostEstimate} with `total_credits`, balances, a
|
|
1621
1658
|
* line-item `breakdown`, and a `has_sufficient_resources` gate.
|
|
1622
1659
|
* `blocking_reason` may be `PendingPayment`, `InsufficientDocuments`, or
|
|
@@ -2006,6 +2043,57 @@ var AssignmentResource = class extends BaseResource {
|
|
|
2006
2043
|
() => this.http.post(`${path2}/review`, body)
|
|
2007
2044
|
);
|
|
2008
2045
|
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Read the capacity each signer signs in (`GET /documents/{documentId}/signer-capacities`).
|
|
2048
|
+
*
|
|
2049
|
+
* Staging extension. Order matches the assignment's signers; an unsent
|
|
2050
|
+
* document returns an empty list. OAuth applications need `documents:read`.
|
|
2051
|
+
* @param documentId - Workspace document ID.
|
|
2052
|
+
* @returns Sender-stated capacities, defaulting to `Sign`:
|
|
2053
|
+
* ```jsonc
|
|
2054
|
+
* [{ "signer_id": "signer-1", "sign_as": "Witness" }]
|
|
2055
|
+
* ```
|
|
2056
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
2057
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or an older deployment.
|
|
2058
|
+
* @example
|
|
2059
|
+
* ```ts
|
|
2060
|
+
* const capacities = await client.assignments.getSignerCapacities(document.id);
|
|
2061
|
+
* ```
|
|
2062
|
+
*/
|
|
2063
|
+
async getSignerCapacities(documentId) {
|
|
2064
|
+
return this.call(
|
|
2065
|
+
"Failed to fetch signer capacities",
|
|
2066
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/signer-capacities`)
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
/**
|
|
2070
|
+
* Read delivery and open times (`GET /documents/{documentId}/notification-history`).
|
|
2071
|
+
*
|
|
2072
|
+
* Staging extension. An open can come from a mail scanner; it is not proof
|
|
2073
|
+
* of human reading. An unsent document returns `[]`. Needs `documents:read`.
|
|
2074
|
+
* @param documentId - Workspace document ID.
|
|
2075
|
+
* @returns History in assignment-signer order:
|
|
2076
|
+
* ```jsonc
|
|
2077
|
+
* [{ "signer_id": "signer-1", "notification_history": [{
|
|
2078
|
+
* "event": "signature_request", "status": "delivered",
|
|
2079
|
+
* "error_code": null, "error_message": null,
|
|
2080
|
+
* "sent_at": "2026-11-24T12:00:00Z", "failed_at": null,
|
|
2081
|
+
* "delivered_at": "2026-11-24T12:00:05Z", "opened_at": null
|
|
2082
|
+
* }] }]
|
|
2083
|
+
* ```
|
|
2084
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
2085
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or an older deployment.
|
|
2086
|
+
* @example
|
|
2087
|
+
* ```ts
|
|
2088
|
+
* const history = await client.assignments.getNotificationHistory(document.id);
|
|
2089
|
+
* ```
|
|
2090
|
+
*/
|
|
2091
|
+
async getNotificationHistory(documentId) {
|
|
2092
|
+
return this.call(
|
|
2093
|
+
"Failed to fetch notification history",
|
|
2094
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/notification-history`)
|
|
2095
|
+
);
|
|
2096
|
+
}
|
|
2009
2097
|
identityVerificationPath(documentId, assignmentId, signerId) {
|
|
2010
2098
|
const docId = this.pathSegment(documentId, "Document ID");
|
|
2011
2099
|
const asgId = this.pathSegment(assignmentId, "Assignment ID");
|
|
@@ -3323,6 +3411,66 @@ var DocumentResource = class extends BaseResource {
|
|
|
3323
3411
|
const percentage = total > 0 ? Math.round(signed / total * 1e4) / 100 : 0;
|
|
3324
3412
|
return { signed, total, pending, percentage };
|
|
3325
3413
|
}
|
|
3414
|
+
/**
|
|
3415
|
+
* List contacts watching a document (`GET /documents/{documentId}/watchers`).
|
|
3416
|
+
*
|
|
3417
|
+
* Staging extension. Returns contacts in the order set, omitting deleted
|
|
3418
|
+
* contacts. API key or user token only; OAuth application tokens are refused.
|
|
3419
|
+
* @param documentId - Workspace document ID.
|
|
3420
|
+
* @returns Watcher contacts:
|
|
3421
|
+
* ```jsonc
|
|
3422
|
+
* [{ "resource": "signer", "id": "signer-1", "full_name": "Example Watcher",
|
|
3423
|
+
* "email": "watcher@example.com", "whatsapp_phone_number": null,
|
|
3424
|
+
* "government_id": null, "has_accepted_terms": false }]
|
|
3425
|
+
* ```
|
|
3426
|
+
* @throws {ValidationError} If the document ID is invalid.
|
|
3427
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown document or older deployment.
|
|
3428
|
+
* @example
|
|
3429
|
+
* ```ts
|
|
3430
|
+
* const watchers = await client.documents.listWatchers(document.id);
|
|
3431
|
+
* ```
|
|
3432
|
+
*/
|
|
3433
|
+
async listWatchers(documentId) {
|
|
3434
|
+
return this.call(
|
|
3435
|
+
"Failed to list document watchers",
|
|
3436
|
+
() => this.http.get(`/documents/${this.pathSegment(documentId, "Document ID")}/watchers`)
|
|
3437
|
+
);
|
|
3438
|
+
}
|
|
3439
|
+
/**
|
|
3440
|
+
* Replace a document's watchers (`PUT /documents/{documentId}/watchers`).
|
|
3441
|
+
*
|
|
3442
|
+
* Staging extension. Each contact must belong to the workspace and have an
|
|
3443
|
+
* email. Watchers get one queued email when the document ends, without a
|
|
3444
|
+
* document link or file. Workspace notification preferences do not suppress
|
|
3445
|
+
* it. Set before sending or while open; `[]` removes every watcher.
|
|
3446
|
+
* API key or user token only; OAuth application tokens are refused.
|
|
3447
|
+
* @param documentId - Workspace document ID.
|
|
3448
|
+
* @param watcherIds - Up to ten contact IDs; duplicate IDs count once.
|
|
3449
|
+
* @returns The stored contacts:
|
|
3450
|
+
* ```jsonc
|
|
3451
|
+
* [{ "resource": "signer", "id": "signer-1", "full_name": "Example Watcher",
|
|
3452
|
+
* "email": "watcher@example.com", "whatsapp_phone_number": null,
|
|
3453
|
+
* "government_id": null, "has_accepted_terms": false }]
|
|
3454
|
+
* ```
|
|
3455
|
+
* @throws {ValidationError} If an ID is invalid or more than ten distinct watchers are supplied.
|
|
3456
|
+
* @throws {ApiError} `400` for a closed document or invalid contact; `401`, `403`, `404`.
|
|
3457
|
+
* @example
|
|
3458
|
+
* ```ts
|
|
3459
|
+
* await client.documents.setWatchers(document.id, [contact.id]);
|
|
3460
|
+
* // body: { watcher_ids: [contact.id] }
|
|
3461
|
+
* ```
|
|
3462
|
+
*/
|
|
3463
|
+
async setWatchers(documentId, watcherIds) {
|
|
3464
|
+
if (!Array.isArray(watcherIds) || watcherIds.some((id) => typeof id !== "string" || !id.trim()) || new Set(watcherIds).size > 10) {
|
|
3465
|
+
throw new ValidationError("watcherIds must contain at most ten distinct non-empty contact IDs");
|
|
3466
|
+
}
|
|
3467
|
+
return this.call(
|
|
3468
|
+
"Failed to set document watchers",
|
|
3469
|
+
() => this.http.put(`/documents/${this.pathSegment(documentId, "Document ID")}/watchers`, {
|
|
3470
|
+
watcher_ids: watcherIds
|
|
3471
|
+
})
|
|
3472
|
+
);
|
|
3473
|
+
}
|
|
3326
3474
|
};
|
|
3327
3475
|
function normaliseTemplateSigners(signers) {
|
|
3328
3476
|
if (!Array.isArray(signers) || signers.length === 0) {
|
|
@@ -9921,6 +10069,7 @@ var EnvelopeResource = class extends BaseResource {
|
|
|
9921
10069
|
*
|
|
9922
10070
|
* @param envelopeId - Envelope ID.
|
|
9923
10071
|
* @param accountId - Override the client's default account ID.
|
|
10072
|
+
* @returns Nothing; the acknowledgement body is discarded.
|
|
9924
10073
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
9925
10074
|
* @throws {ApiError} `403` for a token without `documents:write`, `404` for an
|
|
9926
10075
|
* unknown envelope, `409` (`EnvelopeOpen`) while a document is still open.
|
|
@@ -10138,6 +10287,35 @@ var EnvelopeResource = class extends BaseResource {
|
|
|
10138
10287
|
)
|
|
10139
10288
|
);
|
|
10140
10289
|
}
|
|
10290
|
+
/**
|
|
10291
|
+
* Price a whole-envelope reminder
|
|
10292
|
+
* (`POST /accounts/{accountId}/envelopes/{envelopeId}/signers/{signerId}/estimate-resend-cost`).
|
|
10293
|
+
*
|
|
10294
|
+
* Staging extension. Sends and charges nothing. Prices one reminder per
|
|
10295
|
+
* channel regardless of document count, without checking reminder cooldown
|
|
10296
|
+
* or whether the envelope is closed. OAuth requires `documents:write`.
|
|
10297
|
+
* @param envelopeId - Envelope ID.
|
|
10298
|
+
* @param signerId - Signer of the envelope.
|
|
10299
|
+
* @param accountId - Override the client's default workspace.
|
|
10300
|
+
* @returns The current reminder price:
|
|
10301
|
+
* ```jsonc
|
|
10302
|
+
* { "total": 0, "breakdown": [], "credit_balance": null, "has_sufficient_credits": true }
|
|
10303
|
+
* ```
|
|
10304
|
+
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10305
|
+
* @throws {ApiError} `401`, `403`, or `404` for an unknown envelope/signer or older deployment.
|
|
10306
|
+
* @example
|
|
10307
|
+
* ```ts
|
|
10308
|
+
* const estimate = await client.envelopes.estimateResendCost(envelope.id, signer.id);
|
|
10309
|
+
* ```
|
|
10310
|
+
*/
|
|
10311
|
+
async estimateResendCost(envelopeId, signerId, accountId) {
|
|
10312
|
+
return this.call(
|
|
10313
|
+
"Failed to estimate envelope reminder cost",
|
|
10314
|
+
() => this.http.post(
|
|
10315
|
+
`${this.envelopePath(envelopeId, accountId)}/signers/${this.pathSegment(signerId, "Signer ID")}/estimate-resend-cost`
|
|
10316
|
+
)
|
|
10317
|
+
);
|
|
10318
|
+
}
|
|
10141
10319
|
envelopesPath(accountId) {
|
|
10142
10320
|
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/envelopes`;
|
|
10143
10321
|
}
|
|
@@ -10311,6 +10489,7 @@ var EmbedResource = class extends BaseResource {
|
|
|
10311
10489
|
*
|
|
10312
10490
|
* @param originId - Embed origin ID.
|
|
10313
10491
|
* @param accountId - Override the client's default account ID.
|
|
10492
|
+
* @returns Nothing; the acknowledgement body is discarded.
|
|
10314
10493
|
* @throws {ValidationError} If an ID is missing or invalid.
|
|
10315
10494
|
* @throws {ApiError} `403`, or `404` for an unknown origin ID.
|
|
10316
10495
|
*
|
|
@@ -10375,6 +10554,202 @@ var EmbedResource = class extends BaseResource {
|
|
|
10375
10554
|
}
|
|
10376
10555
|
};
|
|
10377
10556
|
|
|
10557
|
+
// src/resources/scheduled-sends.ts
|
|
10558
|
+
var ScheduledSendResource = class extends BaseResource {
|
|
10559
|
+
/**
|
|
10560
|
+
* Schedule an assignment (`POST /documents/{documentId}/scheduled-sends`).
|
|
10561
|
+
*
|
|
10562
|
+
* Sends and charges nothing now. Each document takes one pending or
|
|
10563
|
+
* processing scheduled send. A failed due send records its reason and
|
|
10564
|
+
* emails the scheduling member (active owners if that member has left).
|
|
10565
|
+
* @param documentId - Unassigned document in the workspace.
|
|
10566
|
+
* @param payload - The same signing request as `assignments.create()` plus its send time.
|
|
10567
|
+
* @param payload.send_at - ISO date-time (no offset means UTC) or Unix seconds, one hour to 90 days ahead.
|
|
10568
|
+
* @param payload.method - `virtual` (default) or `collect`.
|
|
10569
|
+
* @param payload.signers - Contacts and their verification, notification, capacity and ordering options.
|
|
10570
|
+
* @param payload.signer_ids - Compatibility alias for signer IDs.
|
|
10571
|
+
* @param payload.signerIds - Compatibility alias for signer IDs.
|
|
10572
|
+
* @param payload.entries - Required field placements for `collect`.
|
|
10573
|
+
* @param payload.message - Invitation text.
|
|
10574
|
+
* @param payload.copy_receivers - Contacts receiving copies.
|
|
10575
|
+
* @param payload.expires_at - Absolute deadline at least two hours after send_at, or null for none.
|
|
10576
|
+
* @param payload.max_total_credits - Credit ceiling enforced when sending.
|
|
10577
|
+
* @returns The saved request's state:
|
|
10578
|
+
* ```jsonc
|
|
10579
|
+
* { "resource": "scheduled_send", "id": "send-1", "type": "assignment",
|
|
10580
|
+
* "document_ids": ["doc-1"], "status": "pending", "send_at": "2026-12-01T12:00:00Z",
|
|
10581
|
+
* "assignment_id": null, "envelope_id": null, "failure_reason": null,
|
|
10582
|
+
* "created_at": "2026-11-24T12:00:00Z", "processed_at": null }
|
|
10583
|
+
* ```
|
|
10584
|
+
* @throws {ValidationError} If the ID, time or signing request is malformed.
|
|
10585
|
+
* @throws {ApiError} `400` for timing, assignment or pending-send conflicts;
|
|
10586
|
+
* `401`, `403` for plan/scope restrictions, `404` for document/contact/deployment availability.
|
|
10587
|
+
* @example
|
|
10588
|
+
* ```ts
|
|
10589
|
+
* const scheduled = await client.scheduledSends.createAssignment(document.id, {
|
|
10590
|
+
* signers: [{ id: signer.id, verification_method: 'Email', notification_methods: ['Email'] }],
|
|
10591
|
+
* send_at: new Date(Date.now() + 86_400_000).toISOString(),
|
|
10592
|
+
* max_total_credits: 0,
|
|
10593
|
+
* });
|
|
10594
|
+
* ```
|
|
10595
|
+
*/
|
|
10596
|
+
async createAssignment(documentId, payload) {
|
|
10597
|
+
assertRecord(payload, "scheduled assignment");
|
|
10598
|
+
validateTimestamp(payload.send_at, "send_at");
|
|
10599
|
+
const { expires_at, ...assignment } = payload;
|
|
10600
|
+
const body = buildAssignmentPayload(assignment);
|
|
10601
|
+
body["send_at"] = payload.send_at;
|
|
10602
|
+
if (expires_at !== void 0) {
|
|
10603
|
+
if (expires_at !== null) validateTimestamp(expires_at, "expires_at");
|
|
10604
|
+
body["expires_at"] = expires_at;
|
|
10605
|
+
}
|
|
10606
|
+
return this.call(
|
|
10607
|
+
"Failed to schedule assignment",
|
|
10608
|
+
() => this.http.post(`/documents/${this.pathSegment(documentId, "Document ID")}/scheduled-sends`, body)
|
|
10609
|
+
);
|
|
10610
|
+
}
|
|
10611
|
+
/**
|
|
10612
|
+
* Schedule an envelope (`POST /accounts/{accountId}/scheduled-sends`).
|
|
10613
|
+
*
|
|
10614
|
+
* Creates no envelope and charges nothing now. Uses the same plan and
|
|
10615
|
+
* signing rules as envelope estimation; checks balances when sending.
|
|
10616
|
+
* @param payload - Envelope request and send time.
|
|
10617
|
+
* @param payload.send_at - ISO date-time or Unix seconds, one hour to 90 days ahead.
|
|
10618
|
+
* @param payload.name - Envelope name, 1–255 characters without `<`.
|
|
10619
|
+
* @param payload.message - Invitation text or null.
|
|
10620
|
+
* @param payload.signers - 1–20 contacts with shared channel options; no signing steps.
|
|
10621
|
+
* @param payload.documents - 1–20 unassigned documents, signer IDs and optional placements/copy receivers.
|
|
10622
|
+
* Each document's expires_at must be at least two hours after send_at.
|
|
10623
|
+
* @param payload.max_total_credits - Credit ceiling enforced when sending.
|
|
10624
|
+
* @param accountId - Override the client's default workspace.
|
|
10625
|
+
* @returns The saved request's state:
|
|
10626
|
+
* ```jsonc
|
|
10627
|
+
* { "resource": "scheduled_send", "id": "send-2", "type": "envelope",
|
|
10628
|
+
* "document_ids": ["doc-1", "doc-2"], "status": "pending", "send_at": "2026-12-01T12:00:00Z",
|
|
10629
|
+
* "assignment_id": null, "envelope_id": null, "failure_reason": null,
|
|
10630
|
+
* "created_at": "2026-11-24T12:00:00Z", "processed_at": null }
|
|
10631
|
+
* ```
|
|
10632
|
+
* @throws {ValidationError} If the time or envelope request is malformed.
|
|
10633
|
+
* @throws {ApiError} `400` for timing or envelope/pending-send conflicts;
|
|
10634
|
+
* `401`, `403` (`PlanRestricted`, `InsufficientScope`), `404`.
|
|
10635
|
+
* @example
|
|
10636
|
+
* ```ts
|
|
10637
|
+
* const scheduled = await client.scheduledSends.createEnvelope({
|
|
10638
|
+
* name: 'Agreement', signers: [{ id: signer.id }],
|
|
10639
|
+
* documents: [{ id: document.id, signer_ids: [signer.id] }],
|
|
10640
|
+
* send_at: new Date(Date.now() + 86_400_000).toISOString(),
|
|
10641
|
+
* });
|
|
10642
|
+
* ```
|
|
10643
|
+
*/
|
|
10644
|
+
async createEnvelope(payload, accountId) {
|
|
10645
|
+
assertRecord(payload, "scheduled envelope");
|
|
10646
|
+
validateTimestamp(payload.send_at, "send_at");
|
|
10647
|
+
const body = buildEnvelopePayload(payload);
|
|
10648
|
+
body["send_at"] = payload.send_at;
|
|
10649
|
+
return this.call("Failed to schedule envelope", () => this.http.post(this.path(accountId), body));
|
|
10650
|
+
}
|
|
10651
|
+
/**
|
|
10652
|
+
* List scheduled sends (`GET /accounts/{accountId}/scheduled-sends`).
|
|
10653
|
+
*
|
|
10654
|
+
* Newest first, in every state. Requires `documents:write`, because failure
|
|
10655
|
+
* reasons can expose balance and workspace membership information.
|
|
10656
|
+
* @param params - Optional document filter and pagination.
|
|
10657
|
+
* @param params.document_id - Return only sends containing this document.
|
|
10658
|
+
* @param params.page - One-based page number.
|
|
10659
|
+
* @param params.per-page - Page size, default 20 and maximum 50.
|
|
10660
|
+
* @param params.per_page - Compatibility alias for per-page.
|
|
10661
|
+
* @param accountId - Override the client's default workspace.
|
|
10662
|
+
* @returns Requests and header-derived pagination:
|
|
10663
|
+
* ```jsonc
|
|
10664
|
+
* { "data": [{ "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10665
|
+
* "status": "sent", "send_at": "2026-12-01T12:00:00Z", "assignment_id": "assignment-1",
|
|
10666
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10667
|
+
* "processed_at": "2026-12-01T12:00:03Z" }],
|
|
10668
|
+
* "meta": { "current_page": 1, "per_page": 20, "total": 1, "last_page": 1 } }
|
|
10669
|
+
* ```
|
|
10670
|
+
* @throws {ValidationError} If the workspace/filter is invalid.
|
|
10671
|
+
* @throws {ApiError} `400` for an invalid filter, `401`, `403`, `404`.
|
|
10672
|
+
* @example
|
|
10673
|
+
* ```ts
|
|
10674
|
+
* const sends = await client.scheduledSends.list({ document_id: document.id });
|
|
10675
|
+
* ```
|
|
10676
|
+
*/
|
|
10677
|
+
async list(params = {}, accountId) {
|
|
10678
|
+
assertRecord(params, "scheduled send list parameters");
|
|
10679
|
+
if (params.document_id !== void 0) assertNonEmptyString(params.document_id, "document_id");
|
|
10680
|
+
return this.callList(
|
|
10681
|
+
"Failed to list scheduled sends",
|
|
10682
|
+
() => this.http.get(this.path(accountId), { params: cleanListParams({ ...params }) })
|
|
10683
|
+
);
|
|
10684
|
+
}
|
|
10685
|
+
/**
|
|
10686
|
+
* Cancel a pending send (`PUT /accounts/{accountId}/scheduled-sends/{scheduledSendId}/cancel`).
|
|
10687
|
+
*
|
|
10688
|
+
* Sends and charges nothing. A second cancellation is a conflict.
|
|
10689
|
+
* @param scheduledSendId - Pending scheduled send ID.
|
|
10690
|
+
* @param accountId - Override the client's default workspace.
|
|
10691
|
+
* @returns The cancelled state:
|
|
10692
|
+
* ```jsonc
|
|
10693
|
+
* { "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10694
|
+
* "status": "cancelled", "send_at": "2026-12-01T12:00:00Z", "assignment_id": null,
|
|
10695
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10696
|
+
* "processed_at": "2026-11-24T12:05:00Z" }
|
|
10697
|
+
* ```
|
|
10698
|
+
* @throws {ValidationError} If an ID is invalid.
|
|
10699
|
+
* @throws {ApiError} `401`, `403`, `404`, `409` if no longer pending.
|
|
10700
|
+
* @example
|
|
10701
|
+
* ```ts
|
|
10702
|
+
* await client.scheduledSends.cancel(scheduled.id);
|
|
10703
|
+
* ```
|
|
10704
|
+
*/
|
|
10705
|
+
async cancel(scheduledSendId, accountId) {
|
|
10706
|
+
return this.call(
|
|
10707
|
+
"Failed to cancel scheduled send",
|
|
10708
|
+
() => this.http.put(`${this.path(accountId)}/${this.pathSegment(scheduledSendId, "Scheduled send ID")}/cancel`)
|
|
10709
|
+
);
|
|
10710
|
+
}
|
|
10711
|
+
/**
|
|
10712
|
+
* Send a pending request now (`PUT /accounts/{accountId}/scheduled-sends/{scheduledSendId}/send`).
|
|
10713
|
+
*
|
|
10714
|
+
* Checks and charges as the scheduling member. A refusal leaves it pending
|
|
10715
|
+
* for its original time; cancel it explicitly to stop that future attempt.
|
|
10716
|
+
* @param scheduledSendId - Pending scheduled send ID.
|
|
10717
|
+
* @param accountId - Override the client's default workspace.
|
|
10718
|
+
* @returns The sent state and created assignment or envelope ID:
|
|
10719
|
+
* ```jsonc
|
|
10720
|
+
* { "id": "send-1", "type": "assignment", "document_ids": ["doc-1"],
|
|
10721
|
+
* "status": "sent", "send_at": "2026-12-01T12:00:00Z", "assignment_id": "assignment-1",
|
|
10722
|
+
* "envelope_id": null, "failure_reason": null, "created_at": "2026-11-24T12:00:00Z",
|
|
10723
|
+
* "processed_at": "2026-11-24T13:00:00Z" }
|
|
10724
|
+
* ```
|
|
10725
|
+
* @throws {ValidationError} If an ID is invalid.
|
|
10726
|
+
* @throws {ApiError} `400` for invalid requests/balances or departed members;
|
|
10727
|
+
* `401`, `403`, `404`, `409` if no longer pending or `CreditCeilingExceeded`.
|
|
10728
|
+
* @example
|
|
10729
|
+
* ```ts
|
|
10730
|
+
* const sent = await client.scheduledSends.sendNow(scheduled.id);
|
|
10731
|
+
* ```
|
|
10732
|
+
*/
|
|
10733
|
+
async sendNow(scheduledSendId, accountId) {
|
|
10734
|
+
return this.call(
|
|
10735
|
+
"Failed to send scheduled request",
|
|
10736
|
+
() => this.http.put(`${this.path(accountId)}/${this.pathSegment(scheduledSendId, "Scheduled send ID")}/send`)
|
|
10737
|
+
);
|
|
10738
|
+
}
|
|
10739
|
+
path(accountId) {
|
|
10740
|
+
return `/accounts/${this.pathSegment(this.accountId(accountId), "Account ID")}/scheduled-sends`;
|
|
10741
|
+
}
|
|
10742
|
+
};
|
|
10743
|
+
function validateTimestamp(value, label) {
|
|
10744
|
+
if (typeof value === "number") {
|
|
10745
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
10746
|
+
throw new ValidationError(`${label} must be a non-negative Unix time in seconds`);
|
|
10747
|
+
}
|
|
10748
|
+
} else {
|
|
10749
|
+
assertExpirationDate(value, label);
|
|
10750
|
+
}
|
|
10751
|
+
}
|
|
10752
|
+
|
|
10378
10753
|
// src/support/webhook-verifier.ts
|
|
10379
10754
|
import { createHmac, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
10380
10755
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
@@ -10434,8 +10809,8 @@ var WebhookVerifier = class {
|
|
|
10434
10809
|
if (Math.abs(Date.now() / 1e3 - Number(timestamp)) > toleranceSeconds) return false;
|
|
10435
10810
|
const expected = createHmac("sha256", key).update(`${id}.${timestamp}.`).update(payload).digest();
|
|
10436
10811
|
return signatures.split(" ").some((entry) => {
|
|
10437
|
-
const [version, signature] = entry.split(","
|
|
10438
|
-
if (version !== "v1" || !signature) return false;
|
|
10812
|
+
const [version, signature, extra] = entry.split(",");
|
|
10813
|
+
if (version !== "v1" || !signature || extra !== void 0) return false;
|
|
10439
10814
|
const actual = Buffer.from(signature, "base64");
|
|
10440
10815
|
if (actual.toString("base64") !== signature) return false;
|
|
10441
10816
|
return actual.length === expected.length && timingSafeEqual2(actual, expected);
|
|
@@ -10567,6 +10942,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
10567
10942
|
contracts;
|
|
10568
10943
|
envelopes;
|
|
10569
10944
|
embed;
|
|
10945
|
+
scheduledSends;
|
|
10570
10946
|
webhookVerifier;
|
|
10571
10947
|
/**
|
|
10572
10948
|
* Create a client. Supply `apiKey` (preferred, sent as `X-Api-Key`) or a
|
|
@@ -10696,6 +11072,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
10696
11072
|
);
|
|
10697
11073
|
this.envelopes = new EnvelopeResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10698
11074
|
this.embed = new EmbedResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
11075
|
+
this.scheduledSends = new ScheduledSendResource(this.axiosInstance, this.defaultAccountId, this.logger);
|
|
10699
11076
|
this.webhookVerifier = new WebhookVerifier(this.webhookSecret);
|
|
10700
11077
|
}
|
|
10701
11078
|
/**
|
|
@@ -11135,6 +11512,7 @@ export {
|
|
|
11135
11512
|
OAuthError,
|
|
11136
11513
|
OAuthResource,
|
|
11137
11514
|
SDK_USER_AGENT,
|
|
11515
|
+
ScheduledSendResource,
|
|
11138
11516
|
SignerDocumentsResource,
|
|
11139
11517
|
SignerResource,
|
|
11140
11518
|
TagResource,
|
package/docs/API_COVERAGE.md
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
This ledger maps the official
|
|
4
4
|
[`GET /v1/docs/openapi.json`](https://api.assinafy.com.br/v1/docs/openapi.json)
|
|
5
5
|
contract to the public SDK API: 112 paths, 147 HTTP operations, and 62 component
|
|
6
|
-
schemas.
|
|
6
|
+
schemas. Staging additionally publishes 10 operations (120 paths, 157 operations,
|
|
7
|
+
63 schemas); those methods require a deployment that serves them.
|
|
7
8
|
|
|
8
9
|
All paths below include the `/v1` prefix shown by the OpenAPI document, except
|
|
9
10
|
the RFC 8615 `.well-known` document, which is served at the host root. The
|
|
@@ -13,6 +14,7 @@ the corresponding relative path without repeating that prefix.
|
|
|
13
14
|
Status meanings:
|
|
14
15
|
|
|
15
16
|
- **Covered** — a public, typed SDK method sends the operation.
|
|
17
|
+
- **Covered (staging)** — typed method for an operation currently published on staging.
|
|
16
18
|
- **Not exposed** — official route the API reserves for Assinafy's own pages;
|
|
17
19
|
integrations must not call it.
|
|
18
20
|
- **Compatibility extension** — route retained for existing integrations but
|
|
@@ -321,3 +323,18 @@ interfaces and each method's JSDoc examples together with the
|
|
|
321
323
|
[official API reference](https://api.assinafy.com.br/v1/docs). Deployment
|
|
322
324
|
variants that require compatibility handling are recorded in
|
|
323
325
|
[COMPATIBILITY.md](COMPATIBILITY.md).
|
|
326
|
+
|
|
327
|
+
## Additional staging operations — 10/10
|
|
328
|
+
|
|
329
|
+
| Method | Path | SDK method | Status |
|
|
330
|
+
| --- | --- | --- | --- |
|
|
331
|
+
| `GET` | `/v1/documents/{documentId}/signer-capacities` | `client.assignments.getSignerCapacities(documentId)` | Covered (staging) |
|
|
332
|
+
| `GET` | `/v1/documents/{documentId}/notification-history` | `client.assignments.getNotificationHistory(documentId)` | Covered (staging) |
|
|
333
|
+
| `GET` | `/v1/documents/{documentId}/watchers` | `client.documents.listWatchers(documentId)` | Covered (staging) |
|
|
334
|
+
| `PUT` | `/v1/documents/{documentId}/watchers` | `client.documents.setWatchers(documentId, watcherIds)` | Covered (staging) |
|
|
335
|
+
| `POST` | `/v1/accounts/{accountId}/envelopes/{envelopeId}/signers/{signerId}/estimate-resend-cost` | `client.envelopes.estimateResendCost(envelopeId, signerId, accountId?)` | Covered (staging) |
|
|
336
|
+
| `POST` | `/v1/documents/{documentId}/scheduled-sends` | `client.scheduledSends.createAssignment(documentId, payload)` | Covered (staging) |
|
|
337
|
+
| `POST` | `/v1/accounts/{accountId}/scheduled-sends` | `client.scheduledSends.createEnvelope(payload, accountId?)` | Covered (staging) |
|
|
338
|
+
| `GET` | `/v1/accounts/{accountId}/scheduled-sends` | `client.scheduledSends.list(params?, accountId?)` | Covered (staging) |
|
|
339
|
+
| `PUT` | `/v1/accounts/{accountId}/scheduled-sends/{scheduledSendId}/cancel` | `client.scheduledSends.cancel(scheduledSendId, accountId?)` | Covered (staging) |
|
|
340
|
+
| `PUT` | `/v1/accounts/{accountId}/scheduled-sends/{scheduledSendId}/send` | `client.scheduledSends.sendNow(scheduledSendId, accountId?)` | Covered (staging) |
|
package/docs/COMPATIBILITY.md
CHANGED
|
@@ -61,6 +61,24 @@ Older signer-self responses can omit `has_signature`, `has_initial`, and
|
|
|
61
61
|
`is_signature_reusable`; assignment signers can omit `notification_history`.
|
|
62
62
|
Those fields are optional in the SDK response types.
|
|
63
63
|
|
|
64
|
+
## Staging additions
|
|
65
|
+
|
|
66
|
+
Staging publishes 157 operations; production publishes 147. The additional
|
|
67
|
+
operations expose scheduled assignments/envelopes (`client.scheduledSends`),
|
|
68
|
+
document watchers, signer capacities, notification delivery/open history, and
|
|
69
|
+
envelope reminder estimates. They are marked **Covered (staging)** in the
|
|
70
|
+
coverage ledger. No method falls back to another environment.
|
|
71
|
+
|
|
72
|
+
Assignment creation and estimates also accept nullable `sign_as`; it is a
|
|
73
|
+
sender-stated certificate label, not an identity claim. Signature-image upload
|
|
74
|
+
accepts PNG and, on staging, JPEG. Plan prices are deployment-specific: use
|
|
75
|
+
cost estimates and pass `max_total_credits` when creating a signing request.
|
|
76
|
+
|
|
77
|
+
Run `ASSINAFY_CONTRACT_ENV=staging ASSINAFY_OPENAPI_URL=... bun run audit:api`
|
|
78
|
+
to validate the staging specification. OAuth discovery checks target the public
|
|
79
|
+
production and sandbox deployments.
|
|
80
|
+
Keep the selected deployment URL in local configuration.
|
|
81
|
+
|
|
64
82
|
## Contract lifecycle management (CLM)
|
|
65
83
|
|
|
66
84
|
Production exposes the six contract lifecycle operations under
|
|
@@ -96,9 +114,8 @@ not reinterpret either response or route a sandbox request to production.
|
|
|
96
114
|
Read operations remain available after a production plan lapses; writes are
|
|
97
115
|
plan-gated. Signed amendments wait and the lifecycle catches up after the plan
|
|
98
116
|
returns, as defined by the production integration guide.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
sandbox smoke tests does not verify either capability.
|
|
117
|
+
Staging publishes the six CLM operations and activity paging. Deployment
|
|
118
|
+
availability remains explicit: configure `baseUrl` for the environment being used.
|
|
102
119
|
|
|
103
120
|
`documents.details()` can expose `has_contract` only in a workspace context and
|
|
104
121
|
only when contract tracking is available. A missing key means unknown, not
|
|
@@ -383,8 +400,8 @@ embed frame then reports `session_expired`.
|
|
|
383
400
|
|
|
384
401
|
`DigitalCertificate` requires the account feature, a CPF or CNPJ stored in the
|
|
385
402
|
signer's `government_id`, and exactly one certificate signer in that signing
|
|
386
|
-
step.
|
|
387
|
-
|
|
403
|
+
step. Read the current cost estimate for verification and notification fees.
|
|
404
|
+
Notification methods are `Email`, `Whatsapp` or `Bypass`. It also requires
|
|
388
405
|
`method: virtual`: certificate completion completes a virtual item, while the
|
|
389
406
|
ordinary field-signing endpoint refuses certificate signers. The SDK rejects a
|
|
390
407
|
certificate/`collect` combination before assignment creation or cost
|