@assinafy/sdk 2.5.1 → 2.6.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 +62 -45
- package/README.en.md +120 -78
- package/README.md +107 -70
- package/dist/index.d.mts +1064 -60
- package/dist/index.d.ts +1064 -60
- package/dist/index.js +1040 -67
- package/dist/index.mjs +1036 -63
- package/docs/API_COVERAGE.md +23 -10
- package/docs/COMPATIBILITY.md +47 -41
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ __export(index_exports, {
|
|
|
59
59
|
module.exports = __toCommonJS(index_exports);
|
|
60
60
|
|
|
61
61
|
// src/client.ts
|
|
62
|
-
var
|
|
62
|
+
var import_axios4 = __toESM(require("axios"));
|
|
63
63
|
var import_promises = require("timers/promises");
|
|
64
64
|
|
|
65
65
|
// src/errors.ts
|
|
@@ -213,12 +213,14 @@ var OAuthError = class _OAuthError extends ApiError {
|
|
|
213
213
|
const code = body["error"];
|
|
214
214
|
if (typeof code !== "string" || code.length === 0) return error;
|
|
215
215
|
const description = body["error_description"];
|
|
216
|
-
|
|
216
|
+
const upgraded = new _OAuthError(
|
|
217
217
|
code,
|
|
218
218
|
typeof description === "string" && description.length > 0 ? description : null,
|
|
219
219
|
error.statusCode,
|
|
220
220
|
body
|
|
221
221
|
);
|
|
222
|
+
if (error.challenge !== void 0) upgraded.challenge = error.challenge;
|
|
223
|
+
return upgraded;
|
|
222
224
|
}
|
|
223
225
|
};
|
|
224
226
|
var ValidationError = class extends AssinafyError {
|
|
@@ -522,6 +524,9 @@ function nextRetryDelayMs(headers, attempt, maxDelayMs = 3e4) {
|
|
|
522
524
|
return Math.min(backoffMs(attempt), maxDelayMs);
|
|
523
525
|
}
|
|
524
526
|
|
|
527
|
+
// src/resources/base.ts
|
|
528
|
+
var import_axios3 = require("axios");
|
|
529
|
+
|
|
525
530
|
// src/support/path.ts
|
|
526
531
|
function encodePathSegment(value) {
|
|
527
532
|
return encodeURIComponent(value).replace(
|
|
@@ -646,7 +651,7 @@ var import_axios2 = __toESM(require("axios"));
|
|
|
646
651
|
// package.json
|
|
647
652
|
var package_default = {
|
|
648
653
|
name: "@assinafy/sdk",
|
|
649
|
-
version: "2.
|
|
654
|
+
version: "2.6.0",
|
|
650
655
|
packageManager: "bun@1.4.0",
|
|
651
656
|
description: "TypeScript SDK for Assinafy API - Digital signature platform",
|
|
652
657
|
type: "commonjs",
|
|
@@ -727,7 +732,7 @@ var package_default = {
|
|
|
727
732
|
},
|
|
728
733
|
overrides: {
|
|
729
734
|
esbuild: "0.28.2",
|
|
730
|
-
"brace-expansion": "5.0.
|
|
735
|
+
"brace-expansion": "5.0.12"
|
|
731
736
|
},
|
|
732
737
|
files: [
|
|
733
738
|
"dist",
|
|
@@ -952,7 +957,10 @@ var BaseResource = class {
|
|
|
952
957
|
};
|
|
953
958
|
function assertSuccessful(response) {
|
|
954
959
|
if (response.status < 200 || response.status >= 300) {
|
|
955
|
-
throw
|
|
960
|
+
throw toSdkError(
|
|
961
|
+
new import_axios3.AxiosError("Request failed", void 0, response.config, void 0, response),
|
|
962
|
+
"API request failed"
|
|
963
|
+
);
|
|
956
964
|
}
|
|
957
965
|
return response;
|
|
958
966
|
}
|
|
@@ -1331,6 +1339,28 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1331
1339
|
* `DigitalCertificate` costs two credits, requires the feature plus a
|
|
1332
1340
|
* signer `government_id`, and that signer must be alone in its step.
|
|
1333
1341
|
*
|
|
1342
|
+
* Request body (`application/json`):
|
|
1343
|
+
* ```jsonc
|
|
1344
|
+
* {
|
|
1345
|
+
* "method": "virtual",
|
|
1346
|
+
* "signers": [
|
|
1347
|
+
* {
|
|
1348
|
+
* "id": "signer_example",
|
|
1349
|
+
* "verification_method": "Email",
|
|
1350
|
+
* "notification_methods": [
|
|
1351
|
+
* "Email"
|
|
1352
|
+
* ],
|
|
1353
|
+
* "step": 1
|
|
1354
|
+
* }
|
|
1355
|
+
* ],
|
|
1356
|
+
* "message": "Please sign this document.",
|
|
1357
|
+
* "expires_at": "2027-12-31T23:59:59Z",
|
|
1358
|
+
* "copy_receivers": [
|
|
1359
|
+
* "copy_signer_example"
|
|
1360
|
+
* ]
|
|
1361
|
+
* }
|
|
1362
|
+
* ```
|
|
1363
|
+
*
|
|
1334
1364
|
* @param documentId - The document to request signatures on.
|
|
1335
1365
|
* @param payload - Signers plus optional `method` (defaults to `virtual`),
|
|
1336
1366
|
* `message`, `expires_at`, `copy_receivers` (existing signer IDs, not
|
|
@@ -1449,6 +1479,21 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1449
1479
|
* email notification, and 0.45 for WhatsApp notification; a digital
|
|
1450
1480
|
* certificate charge is added on top of its notification cost.
|
|
1451
1481
|
*
|
|
1482
|
+
* Request body (`application/json`):
|
|
1483
|
+
* ```jsonc
|
|
1484
|
+
* {
|
|
1485
|
+
* "method": "virtual",
|
|
1486
|
+
* "signers": [
|
|
1487
|
+
* {
|
|
1488
|
+
* "verification_method": "Email",
|
|
1489
|
+
* "notification_methods": [
|
|
1490
|
+
* "Email"
|
|
1491
|
+
* ]
|
|
1492
|
+
* }
|
|
1493
|
+
* ]
|
|
1494
|
+
* }
|
|
1495
|
+
* ```
|
|
1496
|
+
*
|
|
1452
1497
|
* @param documentId - The document the assignment would be created on.
|
|
1453
1498
|
* @param payload - `method` plus channel-only signer descriptors and/or
|
|
1454
1499
|
* `collect`-mode `entries`. Create-only fields and signer IDs are not part
|
|
@@ -1504,6 +1549,13 @@ var AssignmentResource = class extends BaseResource {
|
|
|
1504
1549
|
* is retained as a compatibility value and, unlike ordinary nullable
|
|
1505
1550
|
* inputs, is intentionally not stripped from the body.
|
|
1506
1551
|
*
|
|
1552
|
+
* Request body (`application/json`):
|
|
1553
|
+
* ```jsonc
|
|
1554
|
+
* {
|
|
1555
|
+
* "expires_at": "2027-12-31T23:59:59Z"
|
|
1556
|
+
* }
|
|
1557
|
+
* ```
|
|
1558
|
+
*
|
|
1507
1559
|
* @param documentId - The document the assignment belongs to.
|
|
1508
1560
|
* @param assignmentId - The assignment to update.
|
|
1509
1561
|
* @param expiresAt - New expiry as an ISO-8601 date/time string. `null` is
|
|
@@ -1919,6 +1971,13 @@ var DocumentResource = class extends BaseResource {
|
|
|
1919
1971
|
* {@link DocumentResource.upload} — that avoids the extra round-trip and
|
|
1920
1972
|
* the processing race entirely.
|
|
1921
1973
|
*
|
|
1974
|
+
* Request body (`application/json`):
|
|
1975
|
+
* ```jsonc
|
|
1976
|
+
* {
|
|
1977
|
+
* "name": "Service agreement.pdf"
|
|
1978
|
+
* }
|
|
1979
|
+
* ```
|
|
1980
|
+
*
|
|
1922
1981
|
* @param documentId - The document to rename.
|
|
1923
1982
|
* @param name - The new display name (max 255 chars), e.g.
|
|
1924
1983
|
* `'Service agreement.pdf'`. The API removes diacritics and replaces
|
|
@@ -2329,6 +2388,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2329
2388
|
* overwrites the existing set — use
|
|
2330
2389
|
* {@link DocumentResource.addTags} to append.
|
|
2331
2390
|
*
|
|
2391
|
+
* Request body (`application/json`):
|
|
2392
|
+
* ```jsonc
|
|
2393
|
+
* {
|
|
2394
|
+
* "tags": [
|
|
2395
|
+
* "tag_example"
|
|
2396
|
+
* ]
|
|
2397
|
+
* }
|
|
2398
|
+
* ```
|
|
2399
|
+
*
|
|
2332
2400
|
* @param documentId - The document to retag.
|
|
2333
2401
|
* @param tags - The complete desired set of tag IDs (`[]` clears all).
|
|
2334
2402
|
* @param accountId - Override the client's default account ID.
|
|
@@ -2371,6 +2439,15 @@ var DocumentResource = class extends BaseResource {
|
|
|
2371
2439
|
* present is a no-op. To replace the whole set instead, use
|
|
2372
2440
|
* {@link DocumentResource.replaceTags}.
|
|
2373
2441
|
*
|
|
2442
|
+
* Request body (`application/json`):
|
|
2443
|
+
* ```jsonc
|
|
2444
|
+
* {
|
|
2445
|
+
* "tags": [
|
|
2446
|
+
* "tag_example"
|
|
2447
|
+
* ]
|
|
2448
|
+
* }
|
|
2449
|
+
* ```
|
|
2450
|
+
*
|
|
2374
2451
|
* @param documentId - The document to tag.
|
|
2375
2452
|
* @param tags - Tag IDs to attach (must be non-empty).
|
|
2376
2453
|
* @param accountId - Override the client's default account ID.
|
|
@@ -2446,6 +2523,35 @@ var DocumentResource = class extends BaseResource {
|
|
|
2446
2523
|
* `options` may add `name`, `message`, `expires_at`, `editor_fields`, and
|
|
2447
2524
|
* tag names in `tags` (unknown names are created automatically).
|
|
2448
2525
|
*
|
|
2526
|
+
* Request body (`application/json`):
|
|
2527
|
+
* ```jsonc
|
|
2528
|
+
* {
|
|
2529
|
+
* "signers": [
|
|
2530
|
+
* {
|
|
2531
|
+
* "role_id": "signing_role_example",
|
|
2532
|
+
* "id": "signer_example",
|
|
2533
|
+
* "verification_method": "Email",
|
|
2534
|
+
* "notification_methods": [
|
|
2535
|
+
* "Email"
|
|
2536
|
+
* ],
|
|
2537
|
+
* "step": 1
|
|
2538
|
+
* }
|
|
2539
|
+
* ],
|
|
2540
|
+
* "name": "Service agreement.pdf",
|
|
2541
|
+
* "message": "Please sign this document.",
|
|
2542
|
+
* "expires_at": "2027-12-31T23:59:59Z",
|
|
2543
|
+
* "editor_fields": [
|
|
2544
|
+
* {
|
|
2545
|
+
* "field_id": "editor_field_example",
|
|
2546
|
+
* "value": "Example Company"
|
|
2547
|
+
* }
|
|
2548
|
+
* ],
|
|
2549
|
+
* "tags": [
|
|
2550
|
+
* "Contracts"
|
|
2551
|
+
* ]
|
|
2552
|
+
* }
|
|
2553
|
+
* ```
|
|
2554
|
+
*
|
|
2449
2555
|
* @param templateId - The template to instantiate.
|
|
2450
2556
|
* @param signers - Role-to-signer bindings (each with `role_id` and `id`,
|
|
2451
2557
|
* plus optional `verification_method`, `notification_methods`, `step`).
|
|
@@ -2529,6 +2635,21 @@ var DocumentResource = class extends BaseResource {
|
|
|
2529
2635
|
* `DigitalCertificate` adds two credits per signer and has the same feature,
|
|
2530
2636
|
* `government_id`, and signing-step prerequisites as document creation.
|
|
2531
2637
|
*
|
|
2638
|
+
* Request body (`application/json`):
|
|
2639
|
+
* ```jsonc
|
|
2640
|
+
* {
|
|
2641
|
+
* "signers": [
|
|
2642
|
+
* {
|
|
2643
|
+
* "role_id": "signing_role_example",
|
|
2644
|
+
* "verification_method": "Email",
|
|
2645
|
+
* "notification_methods": [
|
|
2646
|
+
* "Email"
|
|
2647
|
+
* ]
|
|
2648
|
+
* }
|
|
2649
|
+
* ]
|
|
2650
|
+
* }
|
|
2651
|
+
* ```
|
|
2652
|
+
*
|
|
2532
2653
|
* @param templateId - The template that would be instantiated.
|
|
2533
2654
|
* @param signers - One channel descriptor per template role. Cost requests
|
|
2534
2655
|
* use only `role_id`, `verification_method`, and `notification_methods`;
|
|
@@ -2904,13 +3025,27 @@ var SignerResource = class extends BaseResource {
|
|
|
2904
3025
|
* A reused signer is returned unchanged; this method does not overwrite its
|
|
2905
3026
|
* existing name, phone, CPF, or metadata with the create payload.
|
|
2906
3027
|
*
|
|
3028
|
+
* Request body (`application/json`):
|
|
3029
|
+
* ```jsonc
|
|
3030
|
+
* {
|
|
3031
|
+
* "full_name": "Example Signer",
|
|
3032
|
+
* "email": "signer@example.com",
|
|
3033
|
+
* "whatsapp_phone_number": "+5548999990000",
|
|
3034
|
+
* "government_id": "390.533.447-05",
|
|
3035
|
+
* "metadata": {
|
|
3036
|
+
* "reference": "customer_example"
|
|
3037
|
+
* }
|
|
3038
|
+
* }
|
|
3039
|
+
* ```
|
|
3040
|
+
*
|
|
2907
3041
|
* @param payload - The signer to create. The official fields are required
|
|
2908
|
-
* `full_name` plus optional `email
|
|
2909
|
-
* `
|
|
2910
|
-
*
|
|
3042
|
+
* `full_name` plus optional `email`, E.164 `whatsapp_phone_number` and
|
|
3043
|
+
* `government_id` (CPF, or a CNPJ that may contain letters; the API strips
|
|
3044
|
+
* formatting). `phone`, `cpf`, and `metadata` are compatibility extensions;
|
|
3045
|
+
* the SDK normalizes the phone alias and strips non-digits from CPF.
|
|
2911
3046
|
* @param accountId - Override the client's default account ID.
|
|
2912
|
-
* @returns The created (or reused) signer.
|
|
2913
|
-
* `cpf`
|
|
3047
|
+
* @returns The created (or reused) signer. `government_id` comes back
|
|
3048
|
+
* normalized; `cpf` is **never echoed back**:
|
|
2914
3049
|
* ```jsonc
|
|
2915
3050
|
* {
|
|
2916
3051
|
* "resource": "signer",
|
|
@@ -2918,6 +3053,7 @@ var SignerResource = class extends BaseResource {
|
|
|
2918
3053
|
* "full_name": "Ana Souza",
|
|
2919
3054
|
* "email": "ana@example.com",
|
|
2920
3055
|
* "whatsapp_phone_number": null,
|
|
3056
|
+
* "government_id": "39053344705",
|
|
2921
3057
|
* "has_accepted_terms": false
|
|
2922
3058
|
* }
|
|
2923
3059
|
* ```
|
|
@@ -2931,7 +3067,7 @@ var SignerResource = class extends BaseResource {
|
|
|
2931
3067
|
* const signer = await client.signers.create({
|
|
2932
3068
|
* full_name: 'Ana Souza',
|
|
2933
3069
|
* email: 'ana@example.com',
|
|
2934
|
-
*
|
|
3070
|
+
* government_id: '390.533.447-05', // returned as '39053344705'
|
|
2935
3071
|
* });
|
|
2936
3072
|
*
|
|
2937
3073
|
* // A whatsapp-only signer (no email):
|
|
@@ -2990,6 +3126,7 @@ var SignerResource = class extends BaseResource {
|
|
|
2990
3126
|
* "full_name": "Example Signer",
|
|
2991
3127
|
* "email": "signer@example.com",
|
|
2992
3128
|
* "whatsapp_phone_number": null,
|
|
3129
|
+
* "government_id": "12ABC34501DE35",
|
|
2993
3130
|
* "has_accepted_terms": false
|
|
2994
3131
|
* }
|
|
2995
3132
|
* ```
|
|
@@ -3055,9 +3192,20 @@ var SignerResource = class extends BaseResource {
|
|
|
3055
3192
|
* while it belongs to an in-flight document; changing an unverified channel
|
|
3056
3193
|
* rotates its access/verification codes, so resend the notification.
|
|
3057
3194
|
*
|
|
3195
|
+
* Request body (`application/json`):
|
|
3196
|
+
* ```jsonc
|
|
3197
|
+
* {
|
|
3198
|
+
* "full_name": "Example Signer",
|
|
3199
|
+
* "email": "signer@example.com",
|
|
3200
|
+
* "whatsapp_phone_number": "+5548999990000",
|
|
3201
|
+
* "government_id": "12.ABC.345/01DE-35"
|
|
3202
|
+
* }
|
|
3203
|
+
* ```
|
|
3204
|
+
*
|
|
3058
3205
|
* @param signerId - The signer to update.
|
|
3059
|
-
* @param payload - Fields to change.
|
|
3060
|
-
* legacy `cpf` extension
|
|
3206
|
+
* @param payload - Fields to change. `government_id` is sent as given (the
|
|
3207
|
+
* API normalizes it and keeps CNPJ letters); the legacy `cpf` extension is
|
|
3208
|
+
* stripped to digits.
|
|
3061
3209
|
* @param accountId - Override the client's default account ID.
|
|
3062
3210
|
* @returns The updated signer (as with create, `cpf` is never echoed back):
|
|
3063
3211
|
* ```jsonc
|
|
@@ -3067,6 +3215,7 @@ var SignerResource = class extends BaseResource {
|
|
|
3067
3215
|
* "full_name": "Ana Souza Lima",
|
|
3068
3216
|
* "email": "ana@example.com",
|
|
3069
3217
|
* "whatsapp_phone_number": null,
|
|
3218
|
+
* "government_id": "12ABC34501DE35",
|
|
3070
3219
|
* "has_accepted_terms": false
|
|
3071
3220
|
* }
|
|
3072
3221
|
* ```
|
|
@@ -3193,6 +3342,7 @@ function validateCreateSignerPayload(payload) {
|
|
|
3193
3342
|
validateOptionalPhone(phone);
|
|
3194
3343
|
if (payload.metadata !== void 0) serializeJsonRecord(payload.metadata, "metadata");
|
|
3195
3344
|
validateOptionalDigits(payload.cpf, "cpf");
|
|
3345
|
+
validateOptionalDigits(payload.government_id, "government_id");
|
|
3196
3346
|
}
|
|
3197
3347
|
function validateUpdateSignerPayload(payload) {
|
|
3198
3348
|
if (!payload || typeof payload !== "object") {
|
|
@@ -3241,8 +3391,8 @@ function normaliseSignerPayload(payload) {
|
|
|
3241
3391
|
if (payload.cpf) {
|
|
3242
3392
|
normalised["cpf"] = payload.cpf.replace(/\D/g, "");
|
|
3243
3393
|
}
|
|
3244
|
-
if (
|
|
3245
|
-
normalised["government_id"] = payload.government_id.
|
|
3394
|
+
if (payload.government_id) {
|
|
3395
|
+
normalised["government_id"] = payload.government_id.trim();
|
|
3246
3396
|
}
|
|
3247
3397
|
if ("metadata" in payload && payload.metadata !== void 0) {
|
|
3248
3398
|
normalised["metadata"] = payload.metadata;
|
|
@@ -3274,6 +3424,16 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3274
3424
|
/**
|
|
3275
3425
|
* Create a new workspace (`POST /accounts`).
|
|
3276
3426
|
*
|
|
3427
|
+
* Request body (`application/json`):
|
|
3428
|
+
* ```jsonc
|
|
3429
|
+
* {
|
|
3430
|
+
* "name": "Example Workspace",
|
|
3431
|
+
* "notification_sender_type": "Account",
|
|
3432
|
+
* "primary_color": "336699",
|
|
3433
|
+
* "secondary_color": "ffffff"
|
|
3434
|
+
* }
|
|
3435
|
+
* ```
|
|
3436
|
+
*
|
|
3277
3437
|
* @param payload - Official fields are workspace `name` (required) and
|
|
3278
3438
|
* optional `notification_sender_type` (`User` or `Account`). Optional brand
|
|
3279
3439
|
* colours use six hex characters without
|
|
@@ -3554,6 +3714,16 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3554
3714
|
/**
|
|
3555
3715
|
* Update a workspace (`PUT /accounts/{accountId}`).
|
|
3556
3716
|
*
|
|
3717
|
+
* Request body (`application/json`):
|
|
3718
|
+
* ```jsonc
|
|
3719
|
+
* {
|
|
3720
|
+
* "name": "Example Workspace",
|
|
3721
|
+
* "notification_sender_type": "Account",
|
|
3722
|
+
* "primary_color": "336699",
|
|
3723
|
+
* "secondary_color": null
|
|
3724
|
+
* }
|
|
3725
|
+
* ```
|
|
3726
|
+
*
|
|
3557
3727
|
* @param accountId - The workspace to update.
|
|
3558
3728
|
* @param payload - Official fields are `name` and
|
|
3559
3729
|
* `notification_sender_type` (`User` or `Account`). Brand colours use six
|
|
@@ -3614,6 +3784,13 @@ var WorkspaceResource = class extends BaseResource {
|
|
|
3614
3784
|
* proceeds with deletion; it is not documented as a blanket override for
|
|
3615
3785
|
* unrelated restrictions. The flag is sent in the request body.
|
|
3616
3786
|
*
|
|
3787
|
+
* Request body (`application/json`):
|
|
3788
|
+
* ```jsonc
|
|
3789
|
+
* {
|
|
3790
|
+
* "force": true
|
|
3791
|
+
* }
|
|
3792
|
+
* ```
|
|
3793
|
+
*
|
|
3617
3794
|
* @param accountId - The workspace to delete.
|
|
3618
3795
|
* @param options - Set `force: true` to cancel an active paid subscription
|
|
3619
3796
|
* and proceed with deletion.
|
|
@@ -3675,15 +3852,28 @@ var DEFAULT_WEBHOOK_EVENTS = Object.freeze([
|
|
|
3675
3852
|
]);
|
|
3676
3853
|
var WebhookResource = class extends BaseResource {
|
|
3677
3854
|
/**
|
|
3678
|
-
*
|
|
3679
|
-
* (`PUT /accounts/{accountId}/webhooks/subscriptions`).
|
|
3680
|
-
*
|
|
3855
|
+
* Update the account's oldest webhook endpoint, creating it if the account
|
|
3856
|
+
* has none (`PUT /accounts/{accountId}/webhooks/subscriptions`). Accounts
|
|
3857
|
+
* with several endpoints should use {@link WebhookResource.updateEndpoint}.
|
|
3681
3858
|
*
|
|
3682
3859
|
* When `events` is omitted or empty, {@link DEFAULT_WEBHOOK_EVENTS} is used
|
|
3683
3860
|
* (`document_ready`, `document_prepared`, `signer_signed_document`,
|
|
3684
3861
|
* `signer_rejected_document`, `document_processing_failed`).
|
|
3685
3862
|
* OAuth tokens need the `webhooks:write` scope.
|
|
3686
3863
|
*
|
|
3864
|
+
* Request body (`application/json`):
|
|
3865
|
+
* ```jsonc
|
|
3866
|
+
* {
|
|
3867
|
+
* "events": [
|
|
3868
|
+
* "document_ready",
|
|
3869
|
+
* "document_prepared"
|
|
3870
|
+
* ],
|
|
3871
|
+
* "is_active": true,
|
|
3872
|
+
* "url": "https://myapp.example.com/webhooks/assinafy",
|
|
3873
|
+
* "email": "operations@example.com"
|
|
3874
|
+
* }
|
|
3875
|
+
* ```
|
|
3876
|
+
*
|
|
3687
3877
|
* @param payload - Subscription details. `url` and `email` are required;
|
|
3688
3878
|
* `events` defaults to {@link DEFAULT_WEBHOOK_EVENTS} and `is_active`
|
|
3689
3879
|
* defaults to `true`.
|
|
@@ -3723,26 +3913,12 @@ var WebhookResource = class extends BaseResource {
|
|
|
3723
3913
|
* ```
|
|
3724
3914
|
*/
|
|
3725
3915
|
async register(payload, accountId) {
|
|
3726
|
-
|
|
3727
|
-
throw new ValidationError("Webhook subscription payload is required");
|
|
3728
|
-
}
|
|
3729
|
-
validateWebhookUrl(payload.url);
|
|
3730
|
-
if (!isEmail(payload.email)) {
|
|
3731
|
-
throw new ValidationError("Webhook email must be a valid email address", {
|
|
3732
|
-
email: payload.email
|
|
3733
|
-
});
|
|
3734
|
-
}
|
|
3735
|
-
if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event.trim()))) {
|
|
3736
|
-
throw new ValidationError("Webhook events must be an array of non-empty strings");
|
|
3737
|
-
}
|
|
3738
|
-
if (payload.is_active !== void 0 && typeof payload.is_active !== "boolean") {
|
|
3739
|
-
throw new ValidationError("Webhook is_active must be a boolean");
|
|
3740
|
-
}
|
|
3916
|
+
validateWebhookFields(payload, true);
|
|
3741
3917
|
const id = this.accountId(accountId);
|
|
3742
3918
|
const body = {
|
|
3743
3919
|
url: payload.url,
|
|
3744
3920
|
email: payload.email,
|
|
3745
|
-
events:
|
|
3921
|
+
events: withDefaultEvents(payload.events),
|
|
3746
3922
|
is_active: payload.is_active ?? true
|
|
3747
3923
|
};
|
|
3748
3924
|
this.logger.info("Registering webhook");
|
|
@@ -3755,8 +3931,9 @@ var WebhookResource = class extends BaseResource {
|
|
|
3755
3931
|
);
|
|
3756
3932
|
}
|
|
3757
3933
|
/**
|
|
3758
|
-
* Fetch the
|
|
3759
|
-
* (`GET /accounts/{accountId}/webhooks/subscriptions`).
|
|
3934
|
+
* Fetch the account's oldest webhook endpoint in the legacy subscription
|
|
3935
|
+
* shape (`GET /accounts/{accountId}/webhooks/subscriptions`). Accounts with
|
|
3936
|
+
* several endpoints should use {@link WebhookResource.listEndpoints}.
|
|
3760
3937
|
*
|
|
3761
3938
|
* @param accountId - Override the client's default account ID.
|
|
3762
3939
|
* @returns The subscription, or `null` when the workspace has none (the API
|
|
@@ -3798,13 +3975,14 @@ var WebhookResource = class extends BaseResource {
|
|
|
3798
3975
|
);
|
|
3799
3976
|
}
|
|
3800
3977
|
/**
|
|
3801
|
-
*
|
|
3802
|
-
* (`PUT /accounts/{accountId}/webhooks/inactivate`).
|
|
3978
|
+
* Deactivate the account's oldest webhook endpoint
|
|
3979
|
+
* (`PUT /accounts/{accountId}/webhooks/inactivate`). Other endpoints are
|
|
3980
|
+
* unaffected; use {@link WebhookResource.updateEndpoint} with
|
|
3981
|
+
* `is_active: false` to target a specific one.
|
|
3803
3982
|
*
|
|
3804
|
-
*
|
|
3805
|
-
*
|
|
3806
|
-
*
|
|
3807
|
-
* {@link WebhookResource.register} again with `is_active: true`.
|
|
3983
|
+
* The endpoint is retained (with its `url` and `events`) and simply stops
|
|
3984
|
+
* firing; re-enable it by calling {@link WebhookResource.register} again
|
|
3985
|
+
* with `is_active: true`.
|
|
3808
3986
|
* OAuth tokens need the `webhooks:write` scope.
|
|
3809
3987
|
*
|
|
3810
3988
|
* @param accountId - Override the client's default account ID.
|
|
@@ -3889,6 +4067,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
3889
4067
|
* truncated to 2,000 characters.
|
|
3890
4068
|
*
|
|
3891
4069
|
* @param params - Optional filters and pagination:
|
|
4070
|
+
* - `endpoint_id` — only deliveries to this webhook endpoint.
|
|
3892
4071
|
* - `event` — restrict to a single {@link WebhookEventType}
|
|
3893
4072
|
* (e.g. `'signer_signed_document'`).
|
|
3894
4073
|
* - `delivered` — `true`/`false` to filter by delivery success.
|
|
@@ -3903,6 +4082,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
3903
4082
|
* "id": "103a09cfce51319dd3b3f72ffcdf",
|
|
3904
4083
|
* "event": "signature_requested",
|
|
3905
4084
|
* "activity_id": 8629,
|
|
4085
|
+
* "endpoint_id": "65f1c2a9b3e4d5f60718293a4b5c6d7e", // null once the endpoint is deleted
|
|
3906
4086
|
* "endpoint": "https://example.com/hook",
|
|
3907
4087
|
* "payload": {
|
|
3908
4088
|
* // the full event body that was POSTed to `endpoint`:
|
|
@@ -3945,7 +4125,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
3945
4125
|
/**
|
|
3946
4126
|
* Retry delivery of a specific webhook dispatch
|
|
3947
4127
|
* (`POST /accounts/{accountId}/webhooks/{historyId}/retry`). Re-sends the
|
|
3948
|
-
* original payload to the
|
|
4128
|
+
* original payload to the endpoint that received it.
|
|
3949
4129
|
*
|
|
3950
4130
|
* @param dispatchId - The dispatch (delivery history) ID to re-send, as
|
|
3951
4131
|
* returned by {@link WebhookResource.listDispatches}.
|
|
@@ -3959,6 +4139,7 @@ var WebhookResource = class extends BaseResource {
|
|
|
3959
4139
|
* "id": "103a09cfce51319dd3b3f72ffcdf",
|
|
3960
4140
|
* "event": "signature_requested",
|
|
3961
4141
|
* "activity_id": 8629,
|
|
4142
|
+
* "endpoint_id": "65f1c2a9b3e4d5f60718293a4b5c6d7e", // null once the endpoint is deleted
|
|
3962
4143
|
* "endpoint": "https://example.com/hook",
|
|
3963
4144
|
* "payload": { }, // the original event body that was re-POSTed
|
|
3964
4145
|
* "delivered": true,
|
|
@@ -3989,11 +4170,320 @@ var WebhookResource = class extends BaseResource {
|
|
|
3989
4170
|
)
|
|
3990
4171
|
);
|
|
3991
4172
|
}
|
|
4173
|
+
/**
|
|
4174
|
+
* List the account's webhook endpoints, oldest first
|
|
4175
|
+
* (`GET /accounts/{accountId}/webhooks/endpoints`). OAuth tokens need the
|
|
4176
|
+
* `account:read` scope.
|
|
4177
|
+
*
|
|
4178
|
+
* @param accountId - Override the client's default account ID.
|
|
4179
|
+
* @returns Every endpoint (1 on free plans, up to 3 on paid plans):
|
|
4180
|
+
* ```jsonc
|
|
4181
|
+
* [
|
|
4182
|
+
* {
|
|
4183
|
+
* "id": "65f1c2a9b3e4d5f60718293a4b5c6d7e",
|
|
4184
|
+
* "name": "ERP",
|
|
4185
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4186
|
+
* "email": "ops@example.com",
|
|
4187
|
+
* "events": ["document_ready", "signer_signed_document"],
|
|
4188
|
+
* "is_active": true,
|
|
4189
|
+
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4190
|
+
* "created_at": "2026-10-01T12:00:00Z",
|
|
4191
|
+
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4192
|
+
* }
|
|
4193
|
+
* ]
|
|
4194
|
+
* ```
|
|
4195
|
+
* @throws {ValidationError} If no account ID is available.
|
|
4196
|
+
* @throws {ApiError} If the API rejects the request.
|
|
4197
|
+
*
|
|
4198
|
+
* @example
|
|
4199
|
+
* ```ts
|
|
4200
|
+
* const endpoints = await client.webhooks.listEndpoints();
|
|
4201
|
+
* const signed = endpoints.filter((endpoint) => endpoint.signing_enabled);
|
|
4202
|
+
* ```
|
|
4203
|
+
*/
|
|
4204
|
+
async listEndpoints(accountId) {
|
|
4205
|
+
const path2 = this.endpointsPath(accountId);
|
|
4206
|
+
return this.call("Failed to list webhook endpoints", () => this.http.get(path2));
|
|
4207
|
+
}
|
|
4208
|
+
/**
|
|
4209
|
+
* Register a URL to receive the account's webhook events
|
|
4210
|
+
* (`POST /accounts/{accountId}/webhooks/endpoints`).
|
|
4211
|
+
*
|
|
4212
|
+
* An account can have 1 endpoint, or up to 3 on paid plans. Each endpoint
|
|
4213
|
+
* of a workspace needs a different `url`. With `signing_enabled: true` the
|
|
4214
|
+
* API generates a signing secret; read it with
|
|
4215
|
+
* {@link WebhookResource.getEndpointSecret}. When `events` is omitted or
|
|
4216
|
+
* empty, {@link DEFAULT_WEBHOOK_EVENTS} is sent. OAuth tokens need the
|
|
4217
|
+
* `webhooks:write` scope.
|
|
4218
|
+
*
|
|
4219
|
+
* Request body (`application/json`):
|
|
4220
|
+
* ```jsonc
|
|
4221
|
+
* {
|
|
4222
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4223
|
+
* "email": "ops@example.com",
|
|
4224
|
+
* "events": ["document_ready", "signer_signed_document"],
|
|
4225
|
+
* "name": "ERP", // optional label
|
|
4226
|
+
* "is_active": true, // defaults to true
|
|
4227
|
+
* "signing_enabled": true // defaults to false
|
|
4228
|
+
* }
|
|
4229
|
+
* ```
|
|
4230
|
+
*
|
|
4231
|
+
* @param payload - Endpoint details. `url` (absolute HTTP(S)) and `email`
|
|
4232
|
+
* are required; `events`, `name`, `is_active` and `signing_enabled` are
|
|
4233
|
+
* optional.
|
|
4234
|
+
* @param accountId - Override the client's default account ID.
|
|
4235
|
+
* @returns The created endpoint:
|
|
4236
|
+
* ```jsonc
|
|
4237
|
+
* {
|
|
4238
|
+
* "id": "65f1c2a9b3e4d5f60718293a4b5c6d7e",
|
|
4239
|
+
* "name": "ERP",
|
|
4240
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4241
|
+
* "email": "ops@example.com",
|
|
4242
|
+
* "events": ["document_ready", "signer_signed_document"],
|
|
4243
|
+
* "is_active": true,
|
|
4244
|
+
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4245
|
+
* "created_at": "2026-10-01T12:00:00Z",
|
|
4246
|
+
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4247
|
+
* }
|
|
4248
|
+
* ```
|
|
4249
|
+
* @throws {ValidationError} If a field is malformed or no account ID is
|
|
4250
|
+
* available.
|
|
4251
|
+
* @throws {ApiError} `400` if another endpoint already uses `url`; `403`
|
|
4252
|
+
* when the plan's endpoint limit is reached or an OAuth token lacks
|
|
4253
|
+
* `webhooks:write`.
|
|
4254
|
+
*
|
|
4255
|
+
* @example
|
|
4256
|
+
* ```ts
|
|
4257
|
+
* const endpoint = await client.webhooks.createEndpoint({
|
|
4258
|
+
* name: 'ERP',
|
|
4259
|
+
* url: 'https://example.com/webhooks/assinafy',
|
|
4260
|
+
* email: 'ops@example.com',
|
|
4261
|
+
* events: ['document_ready', 'signer_signed_document'],
|
|
4262
|
+
* signing_enabled: true,
|
|
4263
|
+
* });
|
|
4264
|
+
* const { secret } = await client.webhooks.getEndpointSecret(endpoint.id);
|
|
4265
|
+
* ```
|
|
4266
|
+
*/
|
|
4267
|
+
async createEndpoint(payload, accountId) {
|
|
4268
|
+
validateWebhookFields(payload, true);
|
|
4269
|
+
const path2 = this.endpointsPath(accountId);
|
|
4270
|
+
this.logger.info("Creating webhook endpoint");
|
|
4271
|
+
return this.call(
|
|
4272
|
+
"Failed to create webhook endpoint",
|
|
4273
|
+
() => this.http.post(path2, { ...payload, events: withDefaultEvents(payload.events) })
|
|
4274
|
+
);
|
|
4275
|
+
}
|
|
4276
|
+
/**
|
|
4277
|
+
* Retrieve one webhook endpoint
|
|
4278
|
+
* (`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}`). OAuth
|
|
4279
|
+
* tokens need the `account:read` scope.
|
|
4280
|
+
*
|
|
4281
|
+
* @param endpointId - The endpoint ID.
|
|
4282
|
+
* @param accountId - Override the client's default account ID.
|
|
4283
|
+
* @returns The endpoint:
|
|
4284
|
+
* ```jsonc
|
|
4285
|
+
* {
|
|
4286
|
+
* "id": "65f1c2a9b3e4d5f60718293a4b5c6d7e",
|
|
4287
|
+
* "name": "ERP",
|
|
4288
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4289
|
+
* "email": "ops@example.com",
|
|
4290
|
+
* "events": ["document_ready", "signer_signed_document"],
|
|
4291
|
+
* "is_active": true,
|
|
4292
|
+
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4293
|
+
* "created_at": "2026-10-01T12:00:00Z",
|
|
4294
|
+
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4295
|
+
* }
|
|
4296
|
+
* ```
|
|
4297
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is
|
|
4298
|
+
* available.
|
|
4299
|
+
* @throws {ApiError} `404` if the endpoint does not exist.
|
|
4300
|
+
*
|
|
4301
|
+
* @example
|
|
4302
|
+
* ```ts
|
|
4303
|
+
* const endpoint = await client.webhooks.getEndpoint('65f1c2a9b3e4d5f60718293a4b5c6d7e');
|
|
4304
|
+
* ```
|
|
4305
|
+
*/
|
|
4306
|
+
async getEndpoint(endpointId, accountId) {
|
|
4307
|
+
const path2 = this.endpointPath(endpointId, accountId);
|
|
4308
|
+
return this.call("Failed to fetch webhook endpoint", () => this.http.get(path2));
|
|
4309
|
+
}
|
|
4310
|
+
/**
|
|
4311
|
+
* Change a webhook endpoint
|
|
4312
|
+
* (`PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}`). Only the
|
|
4313
|
+
* fields sent are updated; `url` cannot be one another endpoint of the
|
|
4314
|
+
* workspace already uses.
|
|
4315
|
+
*
|
|
4316
|
+
* `signing_enabled: true` generates a secret if the endpoint has none and
|
|
4317
|
+
* keeps the current one otherwise; `false` discards the secret. OAuth
|
|
4318
|
+
* tokens need the `webhooks:write` scope.
|
|
4319
|
+
*
|
|
4320
|
+
* Request body (`application/json`, every field optional):
|
|
4321
|
+
* ```jsonc
|
|
4322
|
+
* {
|
|
4323
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4324
|
+
* "email": "ops@example.com",
|
|
4325
|
+
* "events": ["document_ready"],
|
|
4326
|
+
* "name": "ERP",
|
|
4327
|
+
* "is_active": false,
|
|
4328
|
+
* "signing_enabled": true
|
|
4329
|
+
* }
|
|
4330
|
+
* ```
|
|
4331
|
+
*
|
|
4332
|
+
* @param endpointId - The endpoint ID.
|
|
4333
|
+
* @param payload - Fields to change; at least one is required.
|
|
4334
|
+
* @param accountId - Override the client's default account ID.
|
|
4335
|
+
* @returns The updated endpoint:
|
|
4336
|
+
* ```jsonc
|
|
4337
|
+
* {
|
|
4338
|
+
* "id": "65f1c2a9b3e4d5f60718293a4b5c6d7e",
|
|
4339
|
+
* "name": "ERP",
|
|
4340
|
+
* "url": "https://example.com/webhooks/assinafy",
|
|
4341
|
+
* "email": "ops@example.com",
|
|
4342
|
+
* "events": ["document_ready", "signer_signed_document"],
|
|
4343
|
+
* "is_active": true,
|
|
4344
|
+
* "signing_enabled": true, // deliveries carry a `webhook-signature` header
|
|
4345
|
+
* "created_at": "2026-10-01T12:00:00Z",
|
|
4346
|
+
* "updated_at": "2026-10-01T12:00:00Z"
|
|
4347
|
+
* }
|
|
4348
|
+
* ```
|
|
4349
|
+
* @throws {ValidationError} If `endpointId` is empty, the payload is empty
|
|
4350
|
+
* or malformed, or no account ID is available.
|
|
4351
|
+
* @throws {ApiError} `400` if another endpoint already uses `url`; `404` if
|
|
4352
|
+
* the endpoint does not exist.
|
|
4353
|
+
*
|
|
4354
|
+
* @example
|
|
4355
|
+
* ```ts
|
|
4356
|
+
* // Pause one endpoint without touching the others:
|
|
4357
|
+
* await client.webhooks.updateEndpoint(endpoint.id, { is_active: false });
|
|
4358
|
+
* ```
|
|
4359
|
+
*/
|
|
4360
|
+
async updateEndpoint(endpointId, payload, accountId) {
|
|
4361
|
+
validateWebhookFields(payload, false);
|
|
4362
|
+
const path2 = this.endpointPath(endpointId, accountId);
|
|
4363
|
+
this.logger.info("Updating webhook endpoint");
|
|
4364
|
+
return this.call("Failed to update webhook endpoint", () => this.http.put(path2, payload));
|
|
4365
|
+
}
|
|
4366
|
+
/**
|
|
4367
|
+
* Stop delivering events to an endpoint and free its plan slot
|
|
4368
|
+
* (`DELETE /accounts/{accountId}/webhooks/endpoints/{endpointId}`). Its
|
|
4369
|
+
* delivery history is kept with `endpoint_id: null`. OAuth tokens need the
|
|
4370
|
+
* `webhooks:write` scope.
|
|
4371
|
+
*
|
|
4372
|
+
* @param endpointId - The endpoint ID.
|
|
4373
|
+
* @param accountId - Override the client's default account ID.
|
|
4374
|
+
* @returns Resolves once deleted (the API answers `{ "data": [] }`).
|
|
4375
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is
|
|
4376
|
+
* available.
|
|
4377
|
+
* @throws {ApiError} `404` if the endpoint does not exist.
|
|
4378
|
+
*
|
|
4379
|
+
* @example
|
|
4380
|
+
* ```ts
|
|
4381
|
+
* await client.webhooks.deleteEndpoint('65f1c2a9b3e4d5f60718293a4b5c6d7e');
|
|
4382
|
+
* ```
|
|
4383
|
+
*/
|
|
4384
|
+
async deleteEndpoint(endpointId, accountId) {
|
|
4385
|
+
const path2 = this.endpointPath(endpointId, accountId);
|
|
4386
|
+
this.logger.info("Deleting webhook endpoint");
|
|
4387
|
+
await this.callVoid("Failed to delete webhook endpoint", () => this.http.delete(path2));
|
|
4388
|
+
}
|
|
4389
|
+
/**
|
|
4390
|
+
* Return the secret that signs deliveries to an endpoint
|
|
4391
|
+
* (`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret`).
|
|
4392
|
+
* Pass it to {@link AssinafyClient} as `webhookSecret` to verify deliveries
|
|
4393
|
+
* with `webhookVerifier.verifySignature()`. Not available to OAuth
|
|
4394
|
+
* applications; use an API key.
|
|
4395
|
+
*
|
|
4396
|
+
* @param endpointId - The endpoint ID.
|
|
4397
|
+
* @param accountId - Override the client's default account ID.
|
|
4398
|
+
* @returns The Standard Webhooks secret:
|
|
4399
|
+
* ```jsonc
|
|
4400
|
+
* { "secret": "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw" }
|
|
4401
|
+
* ```
|
|
4402
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is
|
|
4403
|
+
* available.
|
|
4404
|
+
* @throws {ApiError} `400` when signing is disabled on the endpoint; `404`
|
|
4405
|
+
* if it does not exist.
|
|
4406
|
+
*
|
|
4407
|
+
* @example
|
|
4408
|
+
* ```ts
|
|
4409
|
+
* const { secret } = await client.webhooks.getEndpointSecret(endpoint.id);
|
|
4410
|
+
* // store `secret` with your other credentials, never in source control
|
|
4411
|
+
* ```
|
|
4412
|
+
*/
|
|
4413
|
+
async getEndpointSecret(endpointId, accountId) {
|
|
4414
|
+
const path2 = `${this.endpointPath(endpointId, accountId)}/secret`;
|
|
4415
|
+
return this.call("Failed to fetch webhook endpoint secret", () => this.http.get(path2));
|
|
4416
|
+
}
|
|
4417
|
+
/**
|
|
4418
|
+
* Replace an endpoint's signing secret and return the new one
|
|
4419
|
+
* (`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret/rotate`).
|
|
4420
|
+
* The old secret stops working immediately: deliveries sent after the
|
|
4421
|
+
* rotation are signed only with the new secret, so update the receiver at
|
|
4422
|
+
* once. Not available to OAuth applications; use an API key.
|
|
4423
|
+
*
|
|
4424
|
+
* @param endpointId - The endpoint ID.
|
|
4425
|
+
* @param accountId - Override the client's default account ID.
|
|
4426
|
+
* @returns The new secret:
|
|
4427
|
+
* ```jsonc
|
|
4428
|
+
* { "secret": "whsec_bmV3LWtleS1iYXNlNjQtZW5jb2RlZA==" }
|
|
4429
|
+
* ```
|
|
4430
|
+
* @throws {ValidationError} If `endpointId` is empty or no account ID is
|
|
4431
|
+
* available.
|
|
4432
|
+
* @throws {ApiError} `400` when signing is disabled on the endpoint; `404`
|
|
4433
|
+
* if it does not exist.
|
|
4434
|
+
*
|
|
4435
|
+
* @example
|
|
4436
|
+
* ```ts
|
|
4437
|
+
* const { secret } = await client.webhooks.rotateEndpointSecret(endpoint.id);
|
|
4438
|
+
* await secretStore.put('assinafy-webhook-secret', secret);
|
|
4439
|
+
* ```
|
|
4440
|
+
*/
|
|
4441
|
+
async rotateEndpointSecret(endpointId, accountId) {
|
|
4442
|
+
const path2 = `${this.endpointPath(endpointId, accountId)}/secret/rotate`;
|
|
4443
|
+
this.logger.info("Rotating webhook endpoint secret");
|
|
4444
|
+
return this.call("Failed to rotate webhook endpoint secret", () => this.http.post(path2));
|
|
4445
|
+
}
|
|
4446
|
+
endpointsPath(accountId) {
|
|
4447
|
+
const id = this.pathSegment(this.accountId(accountId), "Account ID");
|
|
4448
|
+
return `/accounts/${id}/webhooks/endpoints`;
|
|
4449
|
+
}
|
|
4450
|
+
endpointPath(endpointId, accountId) {
|
|
4451
|
+
const eid = this.pathSegment(endpointId, "Endpoint ID");
|
|
4452
|
+
return `${this.endpointsPath(accountId)}/${eid}`;
|
|
4453
|
+
}
|
|
3992
4454
|
};
|
|
4455
|
+
function withDefaultEvents(events) {
|
|
4456
|
+
return [...events && events.length > 0 ? events : DEFAULT_WEBHOOK_EVENTS];
|
|
4457
|
+
}
|
|
4458
|
+
function validateWebhookFields(payload, required) {
|
|
4459
|
+
if (!payload || typeof payload !== "object") {
|
|
4460
|
+
throw new ValidationError("Webhook payload is required");
|
|
4461
|
+
}
|
|
4462
|
+
if (!required && Object.values(payload).every((value) => value === void 0)) {
|
|
4463
|
+
throw new ValidationError("Webhook endpoint update must include at least one field");
|
|
4464
|
+
}
|
|
4465
|
+
if (required || payload.url !== void 0) validateWebhookUrl(payload.url);
|
|
4466
|
+
if ((required || payload.email !== void 0) && !isEmail(payload.email)) {
|
|
4467
|
+
throw new ValidationError("Webhook email must be a valid email address", {
|
|
4468
|
+
email: payload.email
|
|
4469
|
+
});
|
|
4470
|
+
}
|
|
4471
|
+
if (payload.events !== void 0 && (!Array.isArray(payload.events) || payload.events.some((event) => typeof event !== "string" || !event.trim()))) {
|
|
4472
|
+
throw new ValidationError("Webhook events must be an array of non-empty strings");
|
|
4473
|
+
}
|
|
4474
|
+
for (const key of ["is_active", "signing_enabled"]) {
|
|
4475
|
+
if (payload[key] !== void 0 && typeof payload[key] !== "boolean") {
|
|
4476
|
+
throw new ValidationError(`Webhook ${key} must be a boolean`);
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4479
|
+
if (payload.name !== void 0 && typeof payload.name !== "string") {
|
|
4480
|
+
throw new ValidationError("Webhook name must be a string");
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
3993
4483
|
function validateWebhookUrl(value) {
|
|
3994
4484
|
let url;
|
|
3995
4485
|
try {
|
|
3996
|
-
url = new URL(value);
|
|
4486
|
+
url = new URL(value ?? "");
|
|
3997
4487
|
} catch {
|
|
3998
4488
|
throw new ValidationError("Webhook URL must be an absolute HTTP(S) URL", { url: value });
|
|
3999
4489
|
}
|
|
@@ -4207,6 +4697,14 @@ var TemplateResource = class extends BaseResource {
|
|
|
4207
4697
|
* `undefined` keys before sending. Unlike uploads, `name` here is a plain
|
|
4208
4698
|
* display name and is **not** forced to end in `.pdf`.
|
|
4209
4699
|
*
|
|
4700
|
+
* Request body (`application/json`):
|
|
4701
|
+
* ```jsonc
|
|
4702
|
+
* {
|
|
4703
|
+
* "name": "Service agreement.pdf",
|
|
4704
|
+
* "message": "Please sign this document."
|
|
4705
|
+
* }
|
|
4706
|
+
* ```
|
|
4707
|
+
*
|
|
4210
4708
|
* @param templateId - The template to update.
|
|
4211
4709
|
* @param payload - `name` and/or `message`; both optional.
|
|
4212
4710
|
* @param accountId - Override the client's default account ID.
|
|
@@ -4387,6 +4885,14 @@ var TagResource = class extends BaseResource {
|
|
|
4387
4885
|
* and `'ff8800'` both persist as `'ff8800'`. Omit `color`
|
|
4388
4886
|
* (or pass `null`) for no color.
|
|
4389
4887
|
*
|
|
4888
|
+
* Request body (`application/json`):
|
|
4889
|
+
* ```jsonc
|
|
4890
|
+
* {
|
|
4891
|
+
* "name": "Contracts",
|
|
4892
|
+
* "color": "ff8800"
|
|
4893
|
+
* }
|
|
4894
|
+
* ```
|
|
4895
|
+
*
|
|
4390
4896
|
* @param payload - `name` (required, max 64 characters; trimmed with
|
|
4391
4897
|
* internal whitespace collapsed) and optional `color`.
|
|
4392
4898
|
* @param accountId - Override the client's default account ID.
|
|
@@ -4436,6 +4942,14 @@ var TagResource = class extends BaseResource {
|
|
|
4436
4942
|
* leading `#` on `color` is accepted and stripped by the API
|
|
4437
4943
|
* (`'#112233'` → `'112233'`).
|
|
4438
4944
|
*
|
|
4945
|
+
* Request body (`application/json`):
|
|
4946
|
+
* ```jsonc
|
|
4947
|
+
* {
|
|
4948
|
+
* "name": "Signed contracts",
|
|
4949
|
+
* "color": null
|
|
4950
|
+
* }
|
|
4951
|
+
* ```
|
|
4952
|
+
*
|
|
4439
4953
|
* @param tagId - The tag to update.
|
|
4440
4954
|
* @param payload - `name` and/or `color`. `color: null` clears the color;
|
|
4441
4955
|
* omit a field to leave it unchanged.
|
|
@@ -4594,6 +5108,14 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4594
5108
|
* `X-Api-Key` (see {@link AuthenticationResource.createApiKey}) instead of
|
|
4595
5109
|
* storing a password.
|
|
4596
5110
|
*
|
|
5111
|
+
* Request body (`application/json`):
|
|
5112
|
+
* ```jsonc
|
|
5113
|
+
* {
|
|
5114
|
+
* "email": "user@example.com",
|
|
5115
|
+
* "password": "example-password"
|
|
5116
|
+
* }
|
|
5117
|
+
* ```
|
|
5118
|
+
*
|
|
4597
5119
|
* @param email - The user's email address, e.g. `'user@example.com'`.
|
|
4598
5120
|
* @param password - The user's password.
|
|
4599
5121
|
* @returns An {@link ILoginResponse} with the access token, user, and
|
|
@@ -4624,6 +5146,9 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4624
5146
|
* }
|
|
4625
5147
|
* ```
|
|
4626
5148
|
* @throws {ValidationError} If `email` or `password` is missing.
|
|
5149
|
+
* When the user has two-factor authentication enabled the response carries
|
|
5150
|
+
* an `mfa_token` instead of a usable session; finish with
|
|
5151
|
+
* {@link AuthenticationResource.verifyMfa}.
|
|
4627
5152
|
* @throws {ApiError} `400` if the credentials are rejected.
|
|
4628
5153
|
*
|
|
4629
5154
|
* @example
|
|
@@ -4642,6 +5167,52 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4642
5167
|
() => this.publicHttp.post("/login", { email, password })
|
|
4643
5168
|
);
|
|
4644
5169
|
}
|
|
5170
|
+
/**
|
|
5171
|
+
* Complete a two-factor login (`POST /authentication/mfa/verify`). Sent
|
|
5172
|
+
* without credentials.
|
|
5173
|
+
*
|
|
5174
|
+
* When the user has two-factor authentication enabled, `login()` returns
|
|
5175
|
+
* an `mfa_token`; exchange it here, within 5 minutes, for the session. The
|
|
5176
|
+
* challenge is single-use.
|
|
5177
|
+
*
|
|
5178
|
+
* Request body (`application/json`):
|
|
5179
|
+
* ```jsonc
|
|
5180
|
+
* {
|
|
5181
|
+
* "mfa_token": "<token from login>",
|
|
5182
|
+
* "code": "123456" // authenticator code, or a recovery code such as "ABCD-EFGH-JKMN"
|
|
5183
|
+
* }
|
|
5184
|
+
* ```
|
|
5185
|
+
*
|
|
5186
|
+
* @param mfaToken - The `mfa_token` returned by {@link AuthenticationResource.login}.
|
|
5187
|
+
* @param code - A 6-digit authenticator code or an unused recovery code.
|
|
5188
|
+
* @returns The same session as a password-only login:
|
|
5189
|
+
* ```jsonc
|
|
5190
|
+
* {
|
|
5191
|
+
* "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…",
|
|
5192
|
+
* "user": { "id": "md3j6p9w8b7y6qvqaoy5er42", "email": "user@example.com" },
|
|
5193
|
+
* "accounts": [{ "id": "acc_example", "name": "Empresa Exemplo", "roles": ["Owner"] }]
|
|
5194
|
+
* }
|
|
5195
|
+
* ```
|
|
5196
|
+
* @throws {ValidationError} If either argument is empty.
|
|
5197
|
+
* @throws {ApiError} `400` for an invalid or used code; `401` when the
|
|
5198
|
+
* challenge expired, was used, or too many codes were tried.
|
|
5199
|
+
*
|
|
5200
|
+
* @example
|
|
5201
|
+
* ```ts
|
|
5202
|
+
* let session = await client.auth.login('user@example.com', password);
|
|
5203
|
+
* if (session.mfa_token) {
|
|
5204
|
+
* session = await client.auth.verifyMfa(session.mfa_token, await promptForCode());
|
|
5205
|
+
* }
|
|
5206
|
+
* ```
|
|
5207
|
+
*/
|
|
5208
|
+
async verifyMfa(mfaToken, code) {
|
|
5209
|
+
assertNonEmptyString(mfaToken, "mfa_token");
|
|
5210
|
+
assertNonEmptyString(code, "code");
|
|
5211
|
+
return this.call(
|
|
5212
|
+
"Two-factor verification failed",
|
|
5213
|
+
() => this.publicHttp.post("/authentication/mfa/verify", { mfa_token: mfaToken, code })
|
|
5214
|
+
);
|
|
5215
|
+
}
|
|
4645
5216
|
/**
|
|
4646
5217
|
* Log in with a social provider (`POST /authentication/social-login`).
|
|
4647
5218
|
*
|
|
@@ -4649,6 +5220,15 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4649
5220
|
* Assinafy JWT. Returns the same {@link ILoginResponse} shape as
|
|
4650
5221
|
* {@link AuthenticationResource.login}.
|
|
4651
5222
|
*
|
|
5223
|
+
* Request body (`application/json`):
|
|
5224
|
+
* ```jsonc
|
|
5225
|
+
* {
|
|
5226
|
+
* "provider": "google",
|
|
5227
|
+
* "token": "provider_token_example",
|
|
5228
|
+
* "has_accepted_terms": true
|
|
5229
|
+
* }
|
|
5230
|
+
* ```
|
|
5231
|
+
*
|
|
4652
5232
|
* @param payload - The social-login body.
|
|
4653
5233
|
* @param payload.provider - OAuth provider; currently exactly `'google'`.
|
|
4654
5234
|
* @param payload.token - The provider-issued OAuth/ID token.
|
|
@@ -4723,6 +5303,14 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4723
5303
|
* The response is the standard status/message acknowledgement with no data,
|
|
4724
5304
|
* so this method resolves to `void`.
|
|
4725
5305
|
*
|
|
5306
|
+
* Request body (`application/json`):
|
|
5307
|
+
* ```jsonc
|
|
5308
|
+
* {
|
|
5309
|
+
* "provider": "google",
|
|
5310
|
+
* "token": "provider_token_example"
|
|
5311
|
+
* }
|
|
5312
|
+
* ```
|
|
5313
|
+
*
|
|
4726
5314
|
* @param payload - Social provider and provider-issued access/ID token.
|
|
4727
5315
|
* @returns Resolves when the API acknowledges that the identity was linked.
|
|
4728
5316
|
* @throws {ValidationError} If `provider` is not `google` or `token` is empty.
|
|
@@ -4759,6 +5347,13 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4759
5347
|
* a masked value. Calling this again rotates the key, invalidating the
|
|
4760
5348
|
* previous one.
|
|
4761
5349
|
*
|
|
5350
|
+
* Request body (`application/json`):
|
|
5351
|
+
* ```jsonc
|
|
5352
|
+
* {
|
|
5353
|
+
* "password": "example-password"
|
|
5354
|
+
* }
|
|
5355
|
+
* ```
|
|
5356
|
+
*
|
|
4762
5357
|
* @param password - The current user's password, required to authorize
|
|
4763
5358
|
* key generation.
|
|
4764
5359
|
* @returns An {@link IApiKeyResponse} containing the new key. Response
|
|
@@ -4846,6 +5441,15 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4846
5441
|
* Requires the current password as a confirmation. On success the API
|
|
4847
5442
|
* echoes back the affected `email`.
|
|
4848
5443
|
*
|
|
5444
|
+
* Request body (`application/json`):
|
|
5445
|
+
* ```jsonc
|
|
5446
|
+
* {
|
|
5447
|
+
* "email": "user@example.com",
|
|
5448
|
+
* "password": "example-password",
|
|
5449
|
+
* "new_password": "new-example-password"
|
|
5450
|
+
* }
|
|
5451
|
+
* ```
|
|
5452
|
+
*
|
|
4849
5453
|
* @param payload - The change-password body.
|
|
4850
5454
|
* @param payload.email - The user's email address.
|
|
4851
5455
|
* @param payload.password - The current password.
|
|
@@ -4892,6 +5496,13 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4892
5496
|
* Triggers Assinafy to email a reset link/token to the given address.
|
|
4893
5497
|
* Complete the flow with {@link AuthenticationResource.resetPassword}.
|
|
4894
5498
|
*
|
|
5499
|
+
* Request body (`application/json`):
|
|
5500
|
+
* ```jsonc
|
|
5501
|
+
* {
|
|
5502
|
+
* "email": "user@example.com"
|
|
5503
|
+
* }
|
|
5504
|
+
* ```
|
|
5505
|
+
*
|
|
4895
5506
|
* @param email - The email address to send the reset link to.
|
|
4896
5507
|
* @returns `{ email }` — the address the reset link was sent to. Response
|
|
4897
5508
|
* shape:
|
|
@@ -4923,6 +5534,15 @@ var AuthenticationResource = class extends BaseResource {
|
|
|
4923
5534
|
* {@link AuthenticationResource.requestPasswordReset} and sets the new
|
|
4924
5535
|
* password. On success the API echoes back the affected `email`.
|
|
4925
5536
|
*
|
|
5537
|
+
* Request body (`application/json`):
|
|
5538
|
+
* ```jsonc
|
|
5539
|
+
* {
|
|
5540
|
+
* "email": "user@example.com",
|
|
5541
|
+
* "token": "reset_token_example",
|
|
5542
|
+
* "new_password": "new-example-password"
|
|
5543
|
+
* }
|
|
5544
|
+
* ```
|
|
5545
|
+
*
|
|
4926
5546
|
* @param payload - The reset-password body.
|
|
4927
5547
|
* @param payload.email - The user's email address.
|
|
4928
5548
|
* @param payload.token - The reset token from the emailed link. The current
|
|
@@ -5145,8 +5765,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
5145
5765
|
* ```ts
|
|
5146
5766
|
* const request = await client.oauth.createAuthorizationUrl({
|
|
5147
5767
|
* clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
5148
|
-
* redirectUri: 'https://myapp.com/oauth/callback',
|
|
5149
|
-
* scopes: ['documents:read', 'documents:write', 'offline_access'],
|
|
5768
|
+
* redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
5769
|
+
* scopes: ['documents:read', 'documents:write', 'account:read', 'offline_access'],
|
|
5150
5770
|
* });
|
|
5151
5771
|
* session.oauth = request;
|
|
5152
5772
|
* response.redirect(request.url);
|
|
@@ -5233,8 +5853,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
5233
5853
|
* ```
|
|
5234
5854
|
* @throws {ValidationError} If `state` is missing or does not match, `iss`
|
|
5235
5855
|
* is absent or disagrees with the expected issuer, or a successful response
|
|
5236
|
-
* carries no `code
|
|
5237
|
-
*
|
|
5856
|
+
* carries no `code`, or a protocol parameter appears more than once.
|
|
5857
|
+
* Reject such responses without exchanging the code.
|
|
5238
5858
|
* @throws {OAuthError} If the server returned `error` (e.g.
|
|
5239
5859
|
* `access_denied`, `invalid_scope`, `invalid_request`,
|
|
5240
5860
|
* `unsupported_response_type`, `invalid_target`).
|
|
@@ -5247,9 +5867,9 @@ var OAuthResource = class extends BaseResource {
|
|
|
5247
5867
|
* const tokens = await client.oauth.exchangeCode({
|
|
5248
5868
|
* code,
|
|
5249
5869
|
* codeVerifier: stored.codeVerifier,
|
|
5250
|
-
* redirectUri: 'https://myapp.com/oauth/callback',
|
|
5870
|
+
* redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
5251
5871
|
* clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
5252
|
-
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET
|
|
5872
|
+
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET!,
|
|
5253
5873
|
* });
|
|
5254
5874
|
* });
|
|
5255
5875
|
* ```
|
|
@@ -5258,6 +5878,11 @@ var OAuthResource = class extends BaseResource {
|
|
|
5258
5878
|
assertRecord(expected, "expected authorization request");
|
|
5259
5879
|
assertNonEmptyString(expected.state, "expected.state");
|
|
5260
5880
|
const query = toSearchParams(params);
|
|
5881
|
+
for (const key of ["state", "iss", "code", "error", "error_description"]) {
|
|
5882
|
+
if (query.getAll(key).length > 1) {
|
|
5883
|
+
throw new ValidationError(`OAuth callback must not repeat ${key}`);
|
|
5884
|
+
}
|
|
5885
|
+
}
|
|
5261
5886
|
const state = query.get("state");
|
|
5262
5887
|
if (state === null || !constantTimeEquals(state, expected.state)) {
|
|
5263
5888
|
throw new ValidationError(
|
|
@@ -5294,6 +5919,12 @@ var OAuthResource = class extends BaseResource {
|
|
|
5294
5919
|
* a browser. Every value must match the authorization request exactly, or
|
|
5295
5920
|
* the API answers `invalid_grant`.
|
|
5296
5921
|
*
|
|
5922
|
+
* Request body (`application/x-www-form-urlencoded`; omit `client_secret`
|
|
5923
|
+
* for public applications):
|
|
5924
|
+
* ```text
|
|
5925
|
+
* grant_type=authorization_code&code=code_example&redirect_uri=https%3A%2F%2Fmyapp.example.com%2Foauth%2Fcallback&client_id=client_example&client_secret=secret_example&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk&resource=https%3A%2F%2Fapi.assinafy.com.br
|
|
5926
|
+
* ```
|
|
5927
|
+
*
|
|
5297
5928
|
* @param options - Exchange options.
|
|
5298
5929
|
* @param options.code - The code from
|
|
5299
5930
|
* {@link OAuthResource.readAuthorizationCallback}.
|
|
@@ -5329,9 +5960,9 @@ var OAuthResource = class extends BaseResource {
|
|
|
5329
5960
|
* const tokens = await client.oauth.exchangeCode({
|
|
5330
5961
|
* code,
|
|
5331
5962
|
* codeVerifier: session.oauth.codeVerifier,
|
|
5332
|
-
* redirectUri: 'https://myapp.com/oauth/callback',
|
|
5963
|
+
* redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
5333
5964
|
* clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
5334
|
-
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET
|
|
5965
|
+
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET!,
|
|
5335
5966
|
* });
|
|
5336
5967
|
* ```
|
|
5337
5968
|
*/
|
|
@@ -5367,6 +5998,12 @@ var OAuthResource = class extends BaseResource {
|
|
|
5367
5998
|
* only expires if it goes 30 days without a refresh; after that the user
|
|
5368
5999
|
* has to reconnect.
|
|
5369
6000
|
*
|
|
6001
|
+
* Request body (`application/x-www-form-urlencoded`; omit `client_secret`
|
|
6002
|
+
* for public applications):
|
|
6003
|
+
* ```text
|
|
6004
|
+
* grant_type=refresh_token&refresh_token=refresh_token_example&client_id=client_example&client_secret=secret_example&resource=https%3A%2F%2Fapi.assinafy.com.br
|
|
6005
|
+
* ```
|
|
6006
|
+
*
|
|
5370
6007
|
* @param options - Refresh options.
|
|
5371
6008
|
* @param options.refreshToken - The current refresh token.
|
|
5372
6009
|
* @param options.clientId - The application's `client_id`.
|
|
@@ -5397,7 +6034,7 @@ var OAuthResource = class extends BaseResource {
|
|
|
5397
6034
|
* const tokens = await client.oauth.refreshToken({
|
|
5398
6035
|
* refreshToken: connection.refreshToken,
|
|
5399
6036
|
* clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
5400
|
-
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET
|
|
6037
|
+
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET!,
|
|
5401
6038
|
* });
|
|
5402
6039
|
* await connection.save({ refreshToken: tokens.refresh_token });
|
|
5403
6040
|
* ```
|
|
@@ -5451,7 +6088,7 @@ var OAuthResource = class extends BaseResource {
|
|
|
5451
6088
|
* token: connection.refreshToken,
|
|
5452
6089
|
* tokenTypeHint: 'refresh_token',
|
|
5453
6090
|
* clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
5454
|
-
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET
|
|
6091
|
+
* clientSecret: process.env.ASSINAFY_CLIENT_SECRET!,
|
|
5455
6092
|
* });
|
|
5456
6093
|
* ```
|
|
5457
6094
|
*/
|
|
@@ -5494,8 +6131,8 @@ var OAuthResource = class extends BaseResource {
|
|
|
5494
6131
|
* "email_verified": true
|
|
5495
6132
|
* }
|
|
5496
6133
|
* ```
|
|
5497
|
-
* `sub` is the stable user identifier;
|
|
5498
|
-
* was not granted.
|
|
6134
|
+
* `sub` is the stable user identifier; other claims may be omitted or
|
|
6135
|
+
* `null` when their scope was not granted.
|
|
5499
6136
|
* @throws {ValidationError} If `accessToken` is supplied but empty.
|
|
5500
6137
|
* @throws {ApiError} `401` when the token is missing, expired or revoked;
|
|
5501
6138
|
* `403` when the `openid` scope was not granted — its `WWW-Authenticate`
|
|
@@ -5665,8 +6302,9 @@ function toSearchParams(params) {
|
|
|
5665
6302
|
assertRecord(params, "callback parameters");
|
|
5666
6303
|
const search = new URLSearchParams();
|
|
5667
6304
|
for (const [key, value] of Object.entries(params)) {
|
|
5668
|
-
const
|
|
5669
|
-
|
|
6305
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
6306
|
+
if (typeof item === "string") search.append(key, item);
|
|
6307
|
+
}
|
|
5670
6308
|
}
|
|
5671
6309
|
return search;
|
|
5672
6310
|
}
|
|
@@ -5676,6 +6314,17 @@ var FieldsResource = class extends BaseResource {
|
|
|
5676
6314
|
/**
|
|
5677
6315
|
* Create a field definition (`POST /accounts/{accountId}/fields`).
|
|
5678
6316
|
*
|
|
6317
|
+
* Request body (`application/json`):
|
|
6318
|
+
* ```jsonc
|
|
6319
|
+
* {
|
|
6320
|
+
* "type": "text",
|
|
6321
|
+
* "name": "Reference",
|
|
6322
|
+
* "regex": null,
|
|
6323
|
+
* "is_required": true,
|
|
6324
|
+
* "is_active": true
|
|
6325
|
+
* }
|
|
6326
|
+
* ```
|
|
6327
|
+
*
|
|
5679
6328
|
* @param payload - The field to create. `type` and `name` are required;
|
|
5680
6329
|
* `type` must be one of the platform field types (see
|
|
5681
6330
|
* {@link FieldsResource.listTypes}); `regex` may be a string or `null`,
|
|
@@ -5820,6 +6469,15 @@ var FieldsResource = class extends BaseResource {
|
|
|
5820
6469
|
* Update a field definition
|
|
5821
6470
|
* (`PUT /accounts/{accountId}/fields/{fieldId}`).
|
|
5822
6471
|
*
|
|
6472
|
+
* Request body (`application/json`):
|
|
6473
|
+
* ```jsonc
|
|
6474
|
+
* {
|
|
6475
|
+
* "name": "Customer reference",
|
|
6476
|
+
* "regex": null,
|
|
6477
|
+
* "is_active": true
|
|
6478
|
+
* }
|
|
6479
|
+
* ```
|
|
6480
|
+
*
|
|
5823
6481
|
* @param fieldId - The field definition to update.
|
|
5824
6482
|
* @param payload - Fields are `name`, nullable `regex`, and `is_active`;
|
|
5825
6483
|
* `type` and `is_required` are compatibility extensions.
|
|
@@ -5908,6 +6566,13 @@ var FieldsResource = class extends BaseResource {
|
|
|
5908
6566
|
* `signerAccessCode` is a compatibility query and is sent as
|
|
5909
6567
|
* `signer-access-code` when supplied.
|
|
5910
6568
|
*
|
|
6569
|
+
* Request body (`application/json`):
|
|
6570
|
+
* ```jsonc
|
|
6571
|
+
* {
|
|
6572
|
+
* "value": "Example value"
|
|
6573
|
+
* }
|
|
6574
|
+
* ```
|
|
6575
|
+
*
|
|
5911
6576
|
* @param fieldId - The field definition to validate against.
|
|
5912
6577
|
* @param value - The value to check (validated against the field's
|
|
5913
6578
|
* type/regex). Sent as `{ value }` in the request body.
|
|
@@ -5960,6 +6625,16 @@ var FieldsResource = class extends BaseResource {
|
|
|
5960
6625
|
* same compatibility extension described on
|
|
5961
6626
|
* {@link FieldsResource.validate}.
|
|
5962
6627
|
*
|
|
6628
|
+
* Request body (`application/json`):
|
|
6629
|
+
* ```jsonc
|
|
6630
|
+
* [
|
|
6631
|
+
* {
|
|
6632
|
+
* "field_id": "field_example",
|
|
6633
|
+
* "value": "Example value"
|
|
6634
|
+
* }
|
|
6635
|
+
* ]
|
|
6636
|
+
* ```
|
|
6637
|
+
*
|
|
5963
6638
|
* @param entries - Non-empty array of `{ field_id, value }` pairs.
|
|
5964
6639
|
* @param options - Account override and optional legacy `signerAccessCode`.
|
|
5965
6640
|
* @returns One validation result per entry. Response shape:
|
|
@@ -6287,6 +6962,15 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6287
6962
|
* The `document_ids` array goes in the request body; the access code
|
|
6288
6963
|
* authenticates via the `signer-access-code` query param.
|
|
6289
6964
|
*
|
|
6965
|
+
* Request body (`application/json`):
|
|
6966
|
+
* ```jsonc
|
|
6967
|
+
* {
|
|
6968
|
+
* "document_ids": [
|
|
6969
|
+
* "document_example"
|
|
6970
|
+
* ]
|
|
6971
|
+
* }
|
|
6972
|
+
* ```
|
|
6973
|
+
*
|
|
6290
6974
|
* @param documentIds - Non-empty array of document IDs to sign.
|
|
6291
6975
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
6292
6976
|
* @returns Resolves when the API acknowledges the operation. The documented
|
|
@@ -6326,6 +7010,16 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6326
7010
|
* Both `document_ids` and `decline_reason` go in the request body; the access
|
|
6327
7011
|
* code authenticates via the `signer-access-code` query param.
|
|
6328
7012
|
*
|
|
7013
|
+
* Request body (`application/json`):
|
|
7014
|
+
* ```jsonc
|
|
7015
|
+
* {
|
|
7016
|
+
* "document_ids": [
|
|
7017
|
+
* "document_example"
|
|
7018
|
+
* ],
|
|
7019
|
+
* "decline_reason": "The document needs a correction."
|
|
7020
|
+
* }
|
|
7021
|
+
* ```
|
|
7022
|
+
*
|
|
6329
7023
|
* @param documentIds - Non-empty array of document IDs to decline.
|
|
6330
7024
|
* @param declineReason - Free-text reason shown to the sender (required).
|
|
6331
7025
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
@@ -6441,6 +7135,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6441
7135
|
* **body carries only `verification-code`** (putting the access code in the
|
|
6442
7136
|
* body leaves the request unauthenticated → `401`).
|
|
6443
7137
|
*
|
|
7138
|
+
* Request body (`application/json`):
|
|
7139
|
+
* ```jsonc
|
|
7140
|
+
* {
|
|
7141
|
+
* "verification-code": "123456"
|
|
7142
|
+
* }
|
|
7143
|
+
* ```
|
|
7144
|
+
*
|
|
6444
7145
|
* @param payload - `signerAccessCode` (the signing-link code) and
|
|
6445
7146
|
* `verificationCode` (the OTP the signer received).
|
|
6446
7147
|
* @returns Resolves when the API acknowledges the operation. The response
|
|
@@ -6659,6 +7360,18 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6659
7360
|
* first. Digital Certificate signers cannot use this endpoint; use the
|
|
6660
7361
|
* certificate start/complete API flow instead.
|
|
6661
7362
|
*
|
|
7363
|
+
* Request body (`application/json`):
|
|
7364
|
+
* ```jsonc
|
|
7365
|
+
* [
|
|
7366
|
+
* {
|
|
7367
|
+
* "itemId": "item_example",
|
|
7368
|
+
* "fieldId": "field_example",
|
|
7369
|
+
* "pageId": "page_example",
|
|
7370
|
+
* "value": "Example Signer"
|
|
7371
|
+
* }
|
|
7372
|
+
* ]
|
|
7373
|
+
* ```
|
|
7374
|
+
*
|
|
6662
7375
|
* @param documentId - The document being signed.
|
|
6663
7376
|
* @param assignmentId - The assignment within that document.
|
|
6664
7377
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
@@ -6716,6 +7429,13 @@ var SignerDocumentsResource = class extends BaseResource {
|
|
|
6716
7429
|
* delete the document via `documents.delete`; there is no workspace "cancel"
|
|
6717
7430
|
* endpoint.)
|
|
6718
7431
|
*
|
|
7432
|
+
* Request body (`application/json`):
|
|
7433
|
+
* ```jsonc
|
|
7434
|
+
* {
|
|
7435
|
+
* "decline_reason": "The document needs a correction."
|
|
7436
|
+
* }
|
|
7437
|
+
* ```
|
|
7438
|
+
*
|
|
6719
7439
|
* @param documentId - The document being declined.
|
|
6720
7440
|
* @param assignmentId - The assignment within that document.
|
|
6721
7441
|
* @param signerAccessCode - The signer's access code, from their signing link.
|
|
@@ -6902,6 +7622,21 @@ var UserResource = class extends BaseResource {
|
|
|
6902
7622
|
* (`PUT /users/self/notification-preferences`). Omitted keys retain their
|
|
6903
7623
|
* current values; account/security e-mails are not configurable here.
|
|
6904
7624
|
*
|
|
7625
|
+
* Request body (`application/json`):
|
|
7626
|
+
* ```jsonc
|
|
7627
|
+
* {
|
|
7628
|
+
* "DocumentCompleted": true,
|
|
7629
|
+
* "SignerDeclined": true,
|
|
7630
|
+
* "DocumentCancelled": true,
|
|
7631
|
+
* "DocumentAboutToExpire": true,
|
|
7632
|
+
* "DocumentExpired": true,
|
|
7633
|
+
* "DocumentExpirationReset": true,
|
|
7634
|
+
* "DocumentProcessingFailed": true,
|
|
7635
|
+
* "TemplateProcessingFailed": true,
|
|
7636
|
+
* "SignerWhatsappFailed": true
|
|
7637
|
+
* }
|
|
7638
|
+
* ```
|
|
7639
|
+
*
|
|
6905
7640
|
* @param preferences - One or more of the nine documented keys, each with
|
|
6906
7641
|
* a boolean value. Request example:
|
|
6907
7642
|
* ```json
|
|
@@ -6941,7 +7676,186 @@ var UserResource = class extends BaseResource {
|
|
|
6941
7676
|
() => this.http.put("/users/self/notification-preferences", preferences)
|
|
6942
7677
|
);
|
|
6943
7678
|
}
|
|
7679
|
+
/**
|
|
7680
|
+
* List the user's enrolled two-factor methods (`GET /users/self/mfa`).
|
|
7681
|
+
*
|
|
7682
|
+
* @returns Methods and unused recovery-code count:
|
|
7683
|
+
* ```jsonc
|
|
7684
|
+
* {
|
|
7685
|
+
* "methods": [
|
|
7686
|
+
* {
|
|
7687
|
+
* "id": "a1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
7688
|
+
* "type": "Totp",
|
|
7689
|
+
* "label": "My phone",
|
|
7690
|
+
* "confirmed_at": "2026-09-09T14:21:03Z",
|
|
7691
|
+
* "last_used_at": "2026-09-09T18:02:44Z"
|
|
7692
|
+
* }
|
|
7693
|
+
* ],
|
|
7694
|
+
* "recovery_codes_remaining": 8
|
|
7695
|
+
* }
|
|
7696
|
+
* ```
|
|
7697
|
+
* @throws {ApiError} `401` when credentials are missing or invalid.
|
|
7698
|
+
*
|
|
7699
|
+
* @example
|
|
7700
|
+
* ```ts
|
|
7701
|
+
* const { methods } = await client.users.getMfa();
|
|
7702
|
+
* const enabled = methods.some((method) => method.confirmed_at !== null);
|
|
7703
|
+
* ```
|
|
7704
|
+
*/
|
|
7705
|
+
async getMfa() {
|
|
7706
|
+
return this.call(
|
|
7707
|
+
"Failed to fetch two-factor methods",
|
|
7708
|
+
() => this.http.get("/users/self/mfa")
|
|
7709
|
+
);
|
|
7710
|
+
}
|
|
7711
|
+
/**
|
|
7712
|
+
* Start authenticator-app enrollment (`POST /users/self/mfa/totp`).
|
|
7713
|
+
* Two-factor authentication is not active until
|
|
7714
|
+
* {@link UserResource.confirmTotpEnrollment} succeeds.
|
|
7715
|
+
*
|
|
7716
|
+
* Request body (`application/json`): `{ "label": "My phone" }` (optional).
|
|
7717
|
+
*
|
|
7718
|
+
* @param label - Optional name for the device.
|
|
7719
|
+
* @returns The pending enrollment. `secret` is returned only here:
|
|
7720
|
+
* ```jsonc
|
|
7721
|
+
* {
|
|
7722
|
+
* "id": "a1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
7723
|
+
* "secret": "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ",
|
|
7724
|
+
* "provisioning_uri": "otpauth://totp/user%40example.com?issuer=Assinafy&secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"
|
|
7725
|
+
* }
|
|
7726
|
+
* ```
|
|
7727
|
+
* @throws {ValidationError} If `label` is not a string.
|
|
7728
|
+
* @throws {ApiError} `401` when credentials are missing or invalid.
|
|
7729
|
+
*
|
|
7730
|
+
* @example
|
|
7731
|
+
* ```ts
|
|
7732
|
+
* const enrollment = await client.users.startTotpEnrollment('My phone');
|
|
7733
|
+
* showQrCode(enrollment.provisioning_uri);
|
|
7734
|
+
* ```
|
|
7735
|
+
*/
|
|
7736
|
+
async startTotpEnrollment(label) {
|
|
7737
|
+
if (label !== void 0 && typeof label !== "string") {
|
|
7738
|
+
throw new ValidationError("label must be a string");
|
|
7739
|
+
}
|
|
7740
|
+
return this.call(
|
|
7741
|
+
"Failed to start authenticator enrollment",
|
|
7742
|
+
() => this.http.post("/users/self/mfa/totp", label === void 0 ? {} : { label })
|
|
7743
|
+
);
|
|
7744
|
+
}
|
|
7745
|
+
/**
|
|
7746
|
+
* Activate an authenticator with a live code from the new device
|
|
7747
|
+
* (`PUT /users/self/mfa/totp/confirm`). From then on every login needs a
|
|
7748
|
+
* second factor.
|
|
7749
|
+
*
|
|
7750
|
+
* Replacing an already confirmed authenticator soft-deletes the old one,
|
|
7751
|
+
* reissues recovery codes, and additionally requires `password` or
|
|
7752
|
+
* `reauth_code`. First-time enrollment needs neither.
|
|
7753
|
+
*
|
|
7754
|
+
* Request body (`application/json`):
|
|
7755
|
+
* ```jsonc
|
|
7756
|
+
* {
|
|
7757
|
+
* "id": "a1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
7758
|
+
* "code": "123456", // from the NEW device
|
|
7759
|
+
* "password": "example-pass", // only when replacing; or:
|
|
7760
|
+
* "reauth_code": "654321" // code from the CURRENT device, or a recovery code
|
|
7761
|
+
* }
|
|
7762
|
+
* ```
|
|
7763
|
+
*
|
|
7764
|
+
* @param payload - Enrollment `id`, new-device `code`, and re-authentication
|
|
7765
|
+
* when replacing a method.
|
|
7766
|
+
* @returns The recovery codes, shown only once:
|
|
7767
|
+
* ```jsonc
|
|
7768
|
+
* {
|
|
7769
|
+
* "recovery_codes": ["ABCD-EFGH-JKMN", "PQRS-TUVW-XYZ2"] // ten in total
|
|
7770
|
+
* }
|
|
7771
|
+
* ```
|
|
7772
|
+
* @throws {ValidationError} If `id` or `code` is empty.
|
|
7773
|
+
* @throws {ApiError} `400` for a wrong code or missing re-authentication;
|
|
7774
|
+
* `404` for an unknown enrollment.
|
|
7775
|
+
*
|
|
7776
|
+
* @example
|
|
7777
|
+
* ```ts
|
|
7778
|
+
* const { recovery_codes } = await client.users.confirmTotpEnrollment({
|
|
7779
|
+
* id: enrollment.id,
|
|
7780
|
+
* code: '123456',
|
|
7781
|
+
* });
|
|
7782
|
+
* ```
|
|
7783
|
+
*/
|
|
7784
|
+
async confirmTotpEnrollment(payload) {
|
|
7785
|
+
assertRecord(payload, "payload");
|
|
7786
|
+
assertNonEmptyString(payload.id, "id");
|
|
7787
|
+
assertNonEmptyString(payload.code, "code");
|
|
7788
|
+
return this.call(
|
|
7789
|
+
"Failed to confirm authenticator enrollment",
|
|
7790
|
+
() => this.http.put("/users/self/mfa/totp/confirm", payload)
|
|
7791
|
+
);
|
|
7792
|
+
}
|
|
7793
|
+
/**
|
|
7794
|
+
* Issue ten fresh recovery codes and invalidate the previous set
|
|
7795
|
+
* (`POST /users/self/mfa/recovery-codes`).
|
|
7796
|
+
*
|
|
7797
|
+
* Request body (`application/json`): `{ "password": "…" }` or
|
|
7798
|
+
* `{ "code": "123456" }`.
|
|
7799
|
+
*
|
|
7800
|
+
* @param proof - Current password, or a live authenticator / recovery code.
|
|
7801
|
+
* @returns The new codes, shown only once:
|
|
7802
|
+
* ```jsonc
|
|
7803
|
+
* {
|
|
7804
|
+
* "recovery_codes": ["ABCD-EFGH-JKMN", "PQRS-TUVW-XYZ2"] // ten in total
|
|
7805
|
+
* }
|
|
7806
|
+
* ```
|
|
7807
|
+
* @throws {ValidationError} If neither `password` nor `code` is given.
|
|
7808
|
+
* @throws {ApiError} `400` when the proof is rejected.
|
|
7809
|
+
*
|
|
7810
|
+
* @example
|
|
7811
|
+
* ```ts
|
|
7812
|
+
* const { recovery_codes } = await client.users.regenerateRecoveryCodes({ code: '123456' });
|
|
7813
|
+
* ```
|
|
7814
|
+
*/
|
|
7815
|
+
async regenerateRecoveryCodes(proof) {
|
|
7816
|
+
validateReauth(proof);
|
|
7817
|
+
return this.call(
|
|
7818
|
+
"Failed to regenerate recovery codes",
|
|
7819
|
+
() => this.http.post("/users/self/mfa/recovery-codes", proof)
|
|
7820
|
+
);
|
|
7821
|
+
}
|
|
7822
|
+
/**
|
|
7823
|
+
* Remove an enrolled two-factor method (`DELETE /users/self/mfa/{id}`).
|
|
7824
|
+
* Removing the last method also discards the recovery codes.
|
|
7825
|
+
*
|
|
7826
|
+
* Request body (`application/json`): `{ "password": "…" }` or
|
|
7827
|
+
* `{ "code": "123456" }`.
|
|
7828
|
+
*
|
|
7829
|
+
* @param methodId - The method ID from {@link UserResource.getMfa}.
|
|
7830
|
+
* @param proof - Current password, or a live authenticator / recovery code.
|
|
7831
|
+
* @returns Whether two-factor authentication is still on:
|
|
7832
|
+
* ```jsonc
|
|
7833
|
+
* { "is_mfa_enabled": false }
|
|
7834
|
+
* ```
|
|
7835
|
+
* @throws {ValidationError} If `methodId` is empty or no proof is given.
|
|
7836
|
+
* @throws {ApiError} `400` when the proof is rejected; `404` for an unknown
|
|
7837
|
+
* method.
|
|
7838
|
+
*
|
|
7839
|
+
* @example
|
|
7840
|
+
* ```ts
|
|
7841
|
+
* await client.users.deleteMfaMethod(method.id, { password });
|
|
7842
|
+
* ```
|
|
7843
|
+
*/
|
|
7844
|
+
async deleteMfaMethod(methodId, proof) {
|
|
7845
|
+
const id = this.pathSegment(methodId, "Method ID");
|
|
7846
|
+
validateReauth(proof);
|
|
7847
|
+
return this.call(
|
|
7848
|
+
"Failed to remove two-factor method",
|
|
7849
|
+
() => this.http.delete(`/users/self/mfa/${id}`, { data: proof })
|
|
7850
|
+
);
|
|
7851
|
+
}
|
|
6944
7852
|
};
|
|
7853
|
+
function validateReauth(proof) {
|
|
7854
|
+
assertRecord(proof, "proof");
|
|
7855
|
+
if (![proof.password, proof.code].some((value) => typeof value === "string" && value.trim())) {
|
|
7856
|
+
throw new ValidationError("password or code is required");
|
|
7857
|
+
}
|
|
7858
|
+
}
|
|
6945
7859
|
var NOTIFICATION_PREFERENCE_KEYS = /* @__PURE__ */ new Set([
|
|
6946
7860
|
"DocumentCompleted",
|
|
6947
7861
|
"SignerDeclined",
|
|
@@ -6971,24 +7885,73 @@ function validateNotificationPreferences(preferences) {
|
|
|
6971
7885
|
|
|
6972
7886
|
// src/support/webhook-verifier.ts
|
|
6973
7887
|
var import_node_crypto2 = require("crypto");
|
|
7888
|
+
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
6974
7889
|
var WebhookVerifier = class {
|
|
6975
7890
|
webhookSecret;
|
|
6976
7891
|
/**
|
|
6977
|
-
*
|
|
6978
|
-
*
|
|
6979
|
-
*
|
|
6980
|
-
* gateway and this process. Omit it to keep verification disabled.
|
|
7892
|
+
* @param webhookSecret - The endpoint's `whsec_…` secret from
|
|
7893
|
+
* `webhooks.getEndpointSecret()`. Omit it to keep verification disabled
|
|
7894
|
+
* (every check returns `false`).
|
|
6981
7895
|
*
|
|
6982
7896
|
* @example
|
|
6983
7897
|
* ```ts
|
|
6984
|
-
* const verifier = new WebhookVerifier(process.env.
|
|
7898
|
+
* const verifier = new WebhookVerifier(process.env.ASSINAFY_WEBHOOK_SECRET);
|
|
6985
7899
|
* ```
|
|
6986
7900
|
*/
|
|
6987
7901
|
constructor(webhookSecret) {
|
|
6988
7902
|
this.webhookSecret = webhookSecret;
|
|
6989
7903
|
}
|
|
6990
7904
|
/**
|
|
6991
|
-
*
|
|
7905
|
+
* Verify a signed delivery: the Standard Webhooks signature over the raw
|
|
7906
|
+
* body, and a `webhook-timestamp` within `toleranceSeconds` of this
|
|
7907
|
+
* machine's clock (replay protection).
|
|
7908
|
+
*
|
|
7909
|
+
* @param payload - Exact, unparsed request bytes (or their UTF-8 string).
|
|
7910
|
+
* Re-serialized JSON will not match.
|
|
7911
|
+
* @param headers - Request headers: a Node/Express header object
|
|
7912
|
+
* (lowercase keys) or a Fetch `Headers`. Reads `webhook-id`,
|
|
7913
|
+
* `webhook-timestamp` and `webhook-signature`.
|
|
7914
|
+
* @param toleranceSeconds - Accepted clock distance. Defaults to `300`.
|
|
7915
|
+
* @returns `true` only when a signature entry matches (constant-time) and
|
|
7916
|
+
* the timestamp is fresh; `false` when verification is disabled, a header
|
|
7917
|
+
* is missing, or anything does not match.
|
|
7918
|
+
*
|
|
7919
|
+
* @example
|
|
7920
|
+
* ```ts
|
|
7921
|
+
* app.post('/webhooks/assinafy', express.raw({ type: 'application/json' }), (req, res) => {
|
|
7922
|
+
* if (!client.webhookVerifier.verifySignature(req.body, req.headers)) {
|
|
7923
|
+
* return res.status(401).end();
|
|
7924
|
+
* }
|
|
7925
|
+
* const event = client.webhookVerifier.extractEvent(req.body);
|
|
7926
|
+
* // deduplicate on req.headers['webhook-id'], then process
|
|
7927
|
+
* res.status(204).end();
|
|
7928
|
+
* });
|
|
7929
|
+
* ```
|
|
7930
|
+
*/
|
|
7931
|
+
verifySignature(payload, headers, toleranceSeconds = DEFAULT_TOLERANCE_SECONDS) {
|
|
7932
|
+
const key = decodeSecret(this.webhookSecret);
|
|
7933
|
+
if (!key || typeof payload !== "string" && !Buffer.isBuffer(payload) || !headers) {
|
|
7934
|
+
return false;
|
|
7935
|
+
}
|
|
7936
|
+
const id = header(headers, "webhook-id");
|
|
7937
|
+
const timestamp = header(headers, "webhook-timestamp");
|
|
7938
|
+
const signatures = header(headers, "webhook-signature");
|
|
7939
|
+
if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false;
|
|
7940
|
+
if (Math.abs(Date.now() / 1e3 - Number(timestamp)) > toleranceSeconds) return false;
|
|
7941
|
+
const expected = (0, import_node_crypto2.createHmac)("sha256", key).update(`${id}.${timestamp}.`).update(payload).digest();
|
|
7942
|
+
return signatures.split(" ").some((entry) => {
|
|
7943
|
+
const [version, signature] = entry.split(",", 2);
|
|
7944
|
+
if (version !== "v1" || !signature) return false;
|
|
7945
|
+
const actual = Buffer.from(signature, "base64");
|
|
7946
|
+
return actual.length === expected.length && (0, import_node_crypto2.timingSafeEqual)(actual, expected);
|
|
7947
|
+
});
|
|
7948
|
+
}
|
|
7949
|
+
/**
|
|
7950
|
+
* Compare a hexadecimal HMAC-SHA256 digest of the raw body, keyed with the
|
|
7951
|
+
* secret string as-is.
|
|
7952
|
+
*
|
|
7953
|
+
* @deprecated For gateways that apply their own HMAC convention. Assinafy's
|
|
7954
|
+
* own signatures are verified with {@link WebhookVerifier.verifySignature}.
|
|
6992
7955
|
*
|
|
6993
7956
|
* @param payload - Exact, unparsed request bytes (or their UTF-8 string).
|
|
6994
7957
|
* @param signature - 64-character hexadecimal SHA-256 digest supplied by
|
|
@@ -7077,6 +8040,16 @@ var WebhookVerifier = class {
|
|
|
7077
8040
|
return {};
|
|
7078
8041
|
}
|
|
7079
8042
|
};
|
|
8043
|
+
function decodeSecret(secret) {
|
|
8044
|
+
if (typeof secret !== "string" || !secret) return null;
|
|
8045
|
+
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
|
|
8046
|
+
return key.length > 0 ? key : null;
|
|
8047
|
+
}
|
|
8048
|
+
function header(headers, name) {
|
|
8049
|
+
const value = typeof headers.get === "function" ? headers.get(name) : headers[name];
|
|
8050
|
+
const first = Array.isArray(value) ? value[0] : value;
|
|
8051
|
+
return typeof first === "string" ? first.trim() : void 0;
|
|
8052
|
+
}
|
|
7080
8053
|
function isRecord(value) {
|
|
7081
8054
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7082
8055
|
}
|
|
@@ -7164,7 +8137,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
7164
8137
|
baseURL,
|
|
7165
8138
|
timeout
|
|
7166
8139
|
};
|
|
7167
|
-
this.axiosInstance =
|
|
8140
|
+
this.axiosInstance = import_axios4.default.create({
|
|
7168
8141
|
...transportOptions,
|
|
7169
8142
|
headers,
|
|
7170
8143
|
// Authorization is stripped by the redirect stack already;
|
|
@@ -7173,7 +8146,7 @@ var AssinafyClient = class _AssinafyClient {
|
|
|
7173
8146
|
});
|
|
7174
8147
|
installCredentialOriginGuard(this.axiosInstance, baseURL);
|
|
7175
8148
|
this.publicAxiosInstance = withoutCredentials(
|
|
7176
|
-
|
|
8149
|
+
import_axios4.default.create({
|
|
7177
8150
|
...transportOptions,
|
|
7178
8151
|
headers: { "User-Agent": SDK_USER_AGENT }
|
|
7179
8152
|
})
|
|
@@ -7593,7 +8566,7 @@ function installRateLimitRetry(http, maxRetries, logger) {
|
|
|
7593
8566
|
http.interceptors.response.use(
|
|
7594
8567
|
(response) => response,
|
|
7595
8568
|
async (error) => {
|
|
7596
|
-
if (!
|
|
8569
|
+
if (!import_axios4.default.isAxiosError(error) || error.response?.status !== 429 || !error.config) {
|
|
7597
8570
|
throw error;
|
|
7598
8571
|
}
|
|
7599
8572
|
const config = error.config;
|