@assinafy/cli 2.4.1 → 2.5.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/.env.example +4 -2
- package/README.en.md +52 -27
- package/README.md +40 -14
- package/dist/api.cjs +238 -18
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +238 -18
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +559 -52
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/resources/authentication.d.ts +33 -3
- package/dist/types/api/resources/authentication.d.ts.map +1 -1
- package/dist/types/api/resources/oauth.d.ts.map +1 -1
- package/dist/types/api/resources/webhooks.d.ts +39 -6
- package/dist/types/api/resources/webhooks.d.ts.map +1 -1
- package/dist/types/api/support/webhook-verifier.d.ts +31 -14
- package/dist/types/api/support/webhook-verifier.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +87 -2
- package/dist/types/api/types.d.ts.map +1 -1
- package/docs/README.md +1 -1
- package/docs/api-operations.json +105 -1
- package/docs/api-reference.md +2309 -2025
- package/docs/auth.md +125 -4
- package/docs/migration-v2.md +4 -3
- package/docs/oauth-guide.md +4 -4
- package/docs/oauth.md +4 -4
- package/docs/sdk-reference.md +74 -12
- package/docs/signers.md +1 -1
- package/docs/webhooks.md +157 -15
- package/install.ps1 +10 -0
- package/install.sh +3 -0
- package/package.json +1 -1
package/docs/auth.md
CHANGED
|
@@ -11,8 +11,9 @@ Options:
|
|
|
11
11
|
-h, --help display help for command
|
|
12
12
|
|
|
13
13
|
Commands:
|
|
14
|
-
login [options] <email> Exchange email + password
|
|
15
|
-
token (no
|
|
14
|
+
login [options] <email> Exchange email + password (and a two-factor
|
|
15
|
+
code when enabled) for a JWT access token (no
|
|
16
|
+
existing credentials required)
|
|
16
17
|
social-login [options] Exchange a provider token for an Assinafy JWT
|
|
17
18
|
(no existing credentials required)
|
|
18
19
|
link-social-login [options] Link a Google identity to the authenticated
|
|
@@ -23,6 +24,8 @@ Commands:
|
|
|
23
24
|
reset-password [options] Complete a password reset with the emailed
|
|
24
25
|
token (no existing credentials required)
|
|
25
26
|
api-keys Manage the current user personal API key
|
|
27
|
+
mfa Two-factor authentication: login verification,
|
|
28
|
+
enrollment, and recovery codes
|
|
26
29
|
help [command] display help for command
|
|
27
30
|
```
|
|
28
31
|
|
|
@@ -31,14 +34,16 @@ Commands:
|
|
|
31
34
|
```text
|
|
32
35
|
Usage: assinafy auth login [options] <email>
|
|
33
36
|
|
|
34
|
-
Exchange email + password
|
|
35
|
-
required)
|
|
37
|
+
Exchange email + password (and a two-factor code when enabled) for a JWT access
|
|
38
|
+
token (no existing credentials required)
|
|
36
39
|
|
|
37
40
|
Arguments:
|
|
38
41
|
email Account email
|
|
39
42
|
|
|
40
43
|
Options:
|
|
41
44
|
--password <password> Password (prompted if omitted) (env: ASSINAFY_PASSWORD)
|
|
45
|
+
--mfa-code <code> Authenticator or recovery code (prompted if required
|
|
46
|
+
and omitted) (env: ASSINAFY_MFA_CODE)
|
|
42
47
|
-h, --help display help for command
|
|
43
48
|
```
|
|
44
49
|
|
|
@@ -167,3 +172,119 @@ Options:
|
|
|
167
172
|
-y, --yes Skip the confirmation prompt
|
|
168
173
|
-h, --help display help for command
|
|
169
174
|
```
|
|
175
|
+
|
|
176
|
+
### `assinafy auth mfa`
|
|
177
|
+
|
|
178
|
+
```text
|
|
179
|
+
Usage: assinafy auth mfa [options] [command]
|
|
180
|
+
|
|
181
|
+
Two-factor authentication: login verification, enrollment, and recovery codes
|
|
182
|
+
|
|
183
|
+
Options:
|
|
184
|
+
-h, --help display help for command
|
|
185
|
+
|
|
186
|
+
Commands:
|
|
187
|
+
verify [options] Complete a two-factor login with the mfa_token
|
|
188
|
+
from login (no existing credentials required)
|
|
189
|
+
list|ls List enrolled two-factor methods and remaining
|
|
190
|
+
recovery codes
|
|
191
|
+
enroll [options] Start authenticator enrollment; prints the
|
|
192
|
+
one-time secret and provisioning URI
|
|
193
|
+
confirm [options] <methodId> Activate an enrolled authenticator and print
|
|
194
|
+
the one-time recovery codes
|
|
195
|
+
recovery-codes [options] Issue ten new recovery codes and invalidate
|
|
196
|
+
the previous set
|
|
197
|
+
remove|rm [options] <methodId> Remove a two-factor method (the last one also
|
|
198
|
+
discards recovery codes)
|
|
199
|
+
help [command] display help for command
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### `assinafy auth mfa verify`
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
Usage: assinafy auth mfa verify [options]
|
|
206
|
+
|
|
207
|
+
Complete a two-factor login with the mfa_token from login (no existing
|
|
208
|
+
credentials required)
|
|
209
|
+
|
|
210
|
+
Options:
|
|
211
|
+
--mfa-token <token> Challenge token returned by login (env:
|
|
212
|
+
ASSINAFY_MFA_TOKEN)
|
|
213
|
+
--mfa-code <code> Authenticator or recovery code (prompted if required and
|
|
214
|
+
omitted) (env: ASSINAFY_MFA_CODE)
|
|
215
|
+
-h, --help display help for command
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### `assinafy auth mfa list`
|
|
219
|
+
|
|
220
|
+
```text
|
|
221
|
+
Usage: assinafy auth mfa list|ls [options]
|
|
222
|
+
|
|
223
|
+
List enrolled two-factor methods and remaining recovery codes
|
|
224
|
+
|
|
225
|
+
Options:
|
|
226
|
+
-h, --help display help for command
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### `assinafy auth mfa enroll`
|
|
230
|
+
|
|
231
|
+
```text
|
|
232
|
+
Usage: assinafy auth mfa enroll [options]
|
|
233
|
+
|
|
234
|
+
Start authenticator enrollment; prints the one-time secret and provisioning URI
|
|
235
|
+
|
|
236
|
+
Options:
|
|
237
|
+
--label <label> Name for the authenticator
|
|
238
|
+
-h, --help display help for command
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### `assinafy auth mfa confirm`
|
|
242
|
+
|
|
243
|
+
```text
|
|
244
|
+
Usage: assinafy auth mfa confirm [options] <methodId>
|
|
245
|
+
|
|
246
|
+
Activate an enrolled authenticator and print the one-time recovery codes
|
|
247
|
+
|
|
248
|
+
Arguments:
|
|
249
|
+
methodId Method ID returned by enroll
|
|
250
|
+
|
|
251
|
+
Options:
|
|
252
|
+
--code <code> Live code from the new authenticator
|
|
253
|
+
--password <password> Current password (only when replacing a confirmed
|
|
254
|
+
method) (env: ASSINAFY_PASSWORD)
|
|
255
|
+
--reauth-code <code> Code from the current authenticator or a recovery code
|
|
256
|
+
(only when replacing)
|
|
257
|
+
-h, --help display help for command
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### `assinafy auth mfa recovery-codes`
|
|
261
|
+
|
|
262
|
+
```text
|
|
263
|
+
Usage: assinafy auth mfa recovery-codes [options]
|
|
264
|
+
|
|
265
|
+
Issue ten new recovery codes and invalidate the previous set
|
|
266
|
+
|
|
267
|
+
Options:
|
|
268
|
+
--password <password> Current password (env: ASSINAFY_PASSWORD)
|
|
269
|
+
--mfa-code <code> Authenticator or recovery code (prompted if required
|
|
270
|
+
and omitted) (env: ASSINAFY_MFA_CODE)
|
|
271
|
+
-h, --help display help for command
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### `assinafy auth mfa remove`
|
|
275
|
+
|
|
276
|
+
```text
|
|
277
|
+
Usage: assinafy auth mfa remove|rm [options] <methodId>
|
|
278
|
+
|
|
279
|
+
Remove a two-factor method (the last one also discards recovery codes)
|
|
280
|
+
|
|
281
|
+
Arguments:
|
|
282
|
+
methodId Method ID
|
|
283
|
+
|
|
284
|
+
Options:
|
|
285
|
+
--password <password> Current password (env: ASSINAFY_PASSWORD)
|
|
286
|
+
--mfa-code <code> Authenticator or recovery code (prompted if required
|
|
287
|
+
and omitted) (env: ASSINAFY_MFA_CODE)
|
|
288
|
+
-y, --yes Skip the confirmation prompt
|
|
289
|
+
-h, --help display help for command
|
|
290
|
+
```
|
package/docs/migration-v2.md
CHANGED
|
@@ -15,9 +15,10 @@ Version 2 publishes the Node.js SDK at `@assinafy/cli/api` and requires Node.js
|
|
|
15
15
|
verification and notification. Explicit signer controls still take precedence.
|
|
16
16
|
- `uploadAndRequestSignatures` rejects with `PartialWorkflowError` when it fails
|
|
17
17
|
after the upload, exposing the `documentId` and `signerIds` it already created
|
|
18
|
-
so callers can
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
so callers can inspect remote state and resume. Signer IDs may have been reused;
|
|
19
|
+
never delete those signers automatically after a failed workflow.
|
|
20
|
+
- Signer artifact downloads use the published public route. Supplying an optional
|
|
21
|
+
access code adds an identity preflight before downloading.
|
|
21
22
|
|
|
22
23
|
Legacy signer aliases (`phone`, `cpf`, and assignment `signer_ids`/`signerIds`),
|
|
23
24
|
both public `sendToken` request forms, and existing CLI functionality remain
|
package/docs/oauth-guide.md
CHANGED
|
@@ -40,7 +40,7 @@ The resource indicator is an origin, distinct from the SDK `baseUrl`, which incl
|
|
|
40
40
|
| `email` | Include permitted email claims. |
|
|
41
41
|
| `offline_access` | Request rotating refresh tokens for background work. |
|
|
42
42
|
|
|
43
|
-
`oauth connect` requests
|
|
43
|
+
`oauth connect` requests the seven scopes registered for the official CLI application by default: `account:read documents:read documents:write templates:read templates:write webhooks:write offline_access`. This supports documents, templates, the selected workspace, webhook settings, and rotating refresh tokens. The default does not request `openid`, `profile`, or `email`, so it does not issue an ID token or enable UserInfo. Those scopes remain available through `--scope` and the SDK for applications registered to use them. Existing connections need a new authorization with the larger scope set; refreshing an old token does not add permissions. Use `--scope` to explicitly select a different registered set when needed. For other applications, request only scopes they use. Resource metadata lists API scopes; authorization-server metadata also describes authentication features such as `offline_access`. The returned `scope` string is authoritative for the access token; do not infer granted scopes from what the browser requested. It never lists `offline_access`, even when granted: a `refresh_token` in the response is the only signal that refresh is available. A scope never bypasses a user's role or the token's workspace boundary. Billing, subscriptions, workspace membership, credential management, and administration remain unavailable to OAuth tokens; those CLI operations require the non-OAuth credential documented for each endpoint.
|
|
44
44
|
|
|
45
45
|
## Discover and start authorization
|
|
46
46
|
|
|
@@ -125,7 +125,7 @@ const tokens = await oauthClient.oauth.exchangeCode(
|
|
|
125
125
|
);
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
`exchangeCode(callbackUrl, request, clientSecret?)` checks the callback origin/path and registered query parameters, rejects duplicate protocol parameters, compares `state` in constant time, and requires the exact stored issuer. It rejects denied authorization before calling the token endpoint. Authorization codes expire after 60 seconds and can be used once. Exchange immediately and never retry a code blindly after a timeout.
|
|
128
|
+
`exchangeCode(callbackUrl, request, clientSecret?)` checks the callback origin/path and registered query parameters, rejects duplicate protocol parameters, requires exactly one of `code` or `error`, compares `state` in constant time, and requires the exact stored issuer. It rejects denied authorization before calling the token endpoint. Authorization codes expire after 60 seconds and can be used once. Exchange immediately and never retry a code blindly after a timeout.
|
|
129
129
|
|
|
130
130
|
An authorization error raises `ValidationError` with a bounded OAuth error code in `errors.oauthError` and the message, without retaining the callback URL. Unrecognized formats become `unknown_error`. For `invalid_scope`, check that the application registration permits every requested scope, including `offline_access`; do not treat the browser return as successful authorization.
|
|
131
131
|
|
|
@@ -261,7 +261,7 @@ await oauthClient.oauth.revoke({
|
|
|
261
261
|
|
|
262
262
|
### Automatic browser return
|
|
263
263
|
|
|
264
|
-
The distributed CLI includes the official **Public** application's client ID, `96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88`. This public identifier is not a secret. The CLI uses PKCE S256 and the scopes `account:read documents:read documents:write templates:read templates:write webhooks:write
|
|
264
|
+
The distributed CLI includes the official **Public** application's client ID, `96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88`. This public identifier is not a secret. The CLI uses PKCE S256 and the scopes `account:read documents:read documents:write templates:read templates:write webhooks:write offline_access`; keep the registered permissions consistent with the requested scopes. No client secret is used by `oauth connect`, including when `ASSINAFY_OAUTH_CLIENT_SECRET` is set for another application.
|
|
265
265
|
|
|
266
266
|
Application maintainers must deploy the callback from `integrations-generic-callback` and register this exact HTTPS URI, without an extension or trailing slash:
|
|
267
267
|
|
|
@@ -287,7 +287,7 @@ assinafy documents list --json
|
|
|
287
287
|
| --- | --- |
|
|
288
288
|
| `--client-id <id>` | Override the bundled public application ID; takes precedence over `ASSINAFY_OAUTH_CLIENT_ID`. |
|
|
289
289
|
| `--redirect-uri <uri>` | Registered HTTPS relay URI; defaults to the extensionless URL above. Query parameters and fragments are unsupported for this browser relay. |
|
|
290
|
-
| `--scope '<scopes>'` | Space-separated scopes; defaults to `account:read documents:read documents:write templates:read templates:write webhooks:write
|
|
290
|
+
| `--scope '<scopes>'` | Space-separated scopes; defaults to `account:read documents:read documents:write templates:read templates:write webhooks:write offline_access`. |
|
|
291
291
|
| `--timeout <seconds>` | Browser response deadline, 1–600 seconds; default 180. API calls use the SDK's network timeout. |
|
|
292
292
|
| `--no-browser` | Print the authorization URL for manual opening; the local listener still receives the return automatically. |
|
|
293
293
|
|
package/docs/oauth.md
CHANGED
|
@@ -41,10 +41,10 @@ Options:
|
|
|
41
41
|
ASSINAFY_OAUTH_CLIENT_ID)
|
|
42
42
|
--redirect-uri <uri> Exactly registered HTTPS relay URI (default:
|
|
43
43
|
"https://integrations.assinafy.com.br/assinafy-cli/oauth-callback")
|
|
44
|
-
--scope <scopes> Space-separated scopes; the default requests
|
|
45
|
-
|
|
46
|
-
documents:write templates:read
|
|
47
|
-
webhooks:write
|
|
44
|
+
--scope <scopes> Space-separated scopes; the default requests the seven
|
|
45
|
+
registered CLI scopes (default: "account:read
|
|
46
|
+
documents:read documents:write templates:read
|
|
47
|
+
templates:write webhooks:write offline_access")
|
|
48
48
|
--timeout <seconds> Wait for browser consent (1–600 seconds) (default:
|
|
49
49
|
"180")
|
|
50
50
|
--no-browser Print the authorization URL without opening the system
|
package/docs/sdk-reference.md
CHANGED
|
@@ -52,7 +52,7 @@ const publicClient = new AssinafyClient({ allowUnauthenticated: true });
|
|
|
52
52
|
| `timeout` | `number` | Request timeout in milliseconds; default `30_000`. |
|
|
53
53
|
| `logger` | `Logger` | Optional `debug`/`info`/`warn`/`error` functions; otherwise no-op. |
|
|
54
54
|
| `allowUnauthenticated` | `boolean` | Permit construction without `apiKey`/`token`; use only for public, OAuth bootstrap, and signer-code flows. |
|
|
55
|
-
| `webhookSecret` | `string` |
|
|
55
|
+
| `webhookSecret` | `string` | Endpoint `whsec_` signing secret used by `client.webhookVerifier`; see [Webhook verification](#webhook-verification). |
|
|
56
56
|
|
|
57
57
|
| API | Result |
|
|
58
58
|
| --- | --- |
|
|
@@ -224,7 +224,7 @@ Create payload: `{ full_name: string; email?; whatsapp_phone_number?; phone?; cp
|
|
|
224
224
|
|
|
225
225
|
## Signer-side flows (`client.signerDocuments`)
|
|
226
226
|
|
|
227
|
-
These methods use the private `signer-access-code`, not the workspace API key, except for the artifact download that the API publishes as a public route. For email verification, obtain the access code from the verification link and the OTP from the same
|
|
227
|
+
These methods use the private `signer-access-code`, not the workspace API key, except for the artifact download that the API publishes as a public route. For email or WhatsApp verification, obtain the access code from the verification link and the OTP from the same message. An invitation containing only a document ID and recipient is not an access code. Call `self` and `getAssignment` to confirm the signer and document before submitting a decision; keep each document's verification credentials together.
|
|
228
228
|
|
|
229
229
|
| SDK method | HTTP operation | Resolves to |
|
|
230
230
|
| --- | --- | --- |
|
|
@@ -412,8 +412,27 @@ Notification counters can overlap when a request uses multiple delivery channels
|
|
|
412
412
|
| `createApiKey(password)` | [`POST /users/api-keys`](./api-reference.md#create-api-key) | `IApiKeyResponse` |
|
|
413
413
|
| `getApiKey()` | [`GET /users/api-keys`](./api-reference.md#get-api-key) | `IMaskedApiKeyResponse`; 404 means no key |
|
|
414
414
|
| `deleteApiKey()` | [`DELETE /users/api-keys`](./api-reference.md#delete-api-key) | `IEmptyResult` (`unknown[]`) |
|
|
415
|
+
| `verifyMfa({ mfa_token, code })` | [`POST /authentication/mfa/verify`](./api-reference.md#complete-a-two-factor-login) | `IMfaVerifyPayload` → `ILoginResponse` |
|
|
416
|
+
| `listMfaMethods()` | [`GET /users/self/mfa`](./api-reference.md#list-two-factor-methods) | `IMfaStatus` (`{ methods, recovery_codes_remaining }`) |
|
|
417
|
+
| `startTotpEnrollment(label?)` | [`POST /users/self/mfa/totp`](./api-reference.md#start-authenticator-enrollment) | `{ label? }` → `ITotpEnrollment` (`{ id, secret, provisioning_uri }`) |
|
|
418
|
+
| `confirmTotpEnrollment({ id, code, password?, reauth_code? })` | [`PUT /users/self/mfa/totp/confirm`](./api-reference.md#confirm-authenticator-enrollment) | `ITotpConfirmPayload` → `IMfaRecoveryCodes` |
|
|
419
|
+
| `regenerateRecoveryCodes({ password?, code? })` | [`POST /users/self/mfa/recovery-codes`](./api-reference.md#regenerate-recovery-codes) | `IMfaReauthPayload` → `IMfaRecoveryCodes` |
|
|
420
|
+
| `removeMfaMethod(methodId, { password?, code? })` | [`DELETE /users/self/mfa/{methodId}`](./api-reference.md#remove-a-two-factor-method) | JSON body `IMfaReauthPayload` → `{ is_mfa_enabled }` |
|
|
415
421
|
|
|
416
|
-
|
|
422
|
+
### Two-factor authentication
|
|
423
|
+
|
|
424
|
+
When the user has a confirmed authenticator, `login` returns an `mfa_token` challenge instead of a session. Exchange it within 5 minutes, once, with a 6-digit authenticator code or a recovery code:
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
let session = await client.auth.login('user@example.com', password);
|
|
428
|
+
if (!session.access_token && session.mfa_token) {
|
|
429
|
+
session = await client.auth.verifyMfa({ mfa_token: session.mfa_token, code: '123456' });
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Enrollment is `startTotpEnrollment` (show `provisioning_uri` as a QR code; the secret is returned only once) followed by `confirmTotpEnrollment({ id, code })`, which returns ten one-time recovery codes. Replacing a confirmed method also needs `password` or `reauth_code`. `regenerateRecoveryCodes` and `removeMfaMethod` require the current password or a live/recovery `code`; the SDK rejects a payload with neither before sending. `verifyMfa` strips owner credentials.
|
|
434
|
+
|
|
435
|
+
Login/social/reset/two-factor-verify bootstrap calls can use an unauthenticated client. The published authenticated user endpoints permit either a bearer JWT or `X-Api-Key`; use the credential type appropriate to the account and endpoint policy.
|
|
417
436
|
|
|
418
437
|
## OAuth (`client.oauth`)
|
|
419
438
|
|
|
@@ -444,7 +463,7 @@ Metadata, discovery, token, and revoke calls remove owner headers. UserInfo uses
|
|
|
444
463
|
| `validateMultiple(entries, options?)` | [`POST …/fields/validate-multiple`](./api-reference.md#validate-multiple-field-values) | `IFieldValidationResult[]` |
|
|
445
464
|
| `listTypes()` | [`GET /field-types`](./api-reference.md#list-field-types) | `IFieldType[]` |
|
|
446
465
|
|
|
447
|
-
Published create payload: `{ type: string; name: string; regex?; is_required? }`. Published update payload: `{ name?; regex?: string | null; is_active? }`. The SDK retains create-time `is_active` and update-time `type`/`is_required` as compatibility extensions. List params are `{ include_inactive?, include_standard? }`. Validation options are `{ signerAccessCode?, accountId? }`; multiple entries are `{ field_id, value }[]`. When a signer code is supplied, the SDK removes any configured owner API-key/bearer headers from that request.
|
|
466
|
+
Published create payload: `{ type: string; name: string; regex?; is_required? }`. Published update payload: `{ name?; regex?: string | null; is_active? }`. The SDK retains create-time `is_active` and update-time `type`/`is_required` as compatibility extensions. List params are `{ include_inactive?, include_standard? }`. Validation options are `{ signerAccessCode?, accountId? }`; multiple entries are `{ field_id, value }[]`. When a signer code is supplied, the SDK removes any configured owner API-key/bearer headers from that request. An explicitly empty or blank code raises `ValidationError` before any request; omit the option for owner-authenticated validation.
|
|
448
467
|
|
|
449
468
|
## Tags (`client.tags`)
|
|
450
469
|
|
|
@@ -504,16 +523,39 @@ Template list params support pagination, published `search`, and compatible `sor
|
|
|
504
523
|
|
|
505
524
|
## Webhooks (`client.webhooks`)
|
|
506
525
|
|
|
526
|
+
An account can register 1 webhook endpoint, or up to 3 on paid plans. Each endpoint has its own URL, events, active flag, and signing setting; every active endpoint subscribed to an event receives it independently. The `subscriptions` operations remain and act on the account's oldest endpoint.
|
|
527
|
+
|
|
507
528
|
| SDK method | HTTP operation | Resolves to |
|
|
508
529
|
| --- | --- | --- |
|
|
509
|
-
| `
|
|
530
|
+
| `listEndpoints(accountId?)` | [`GET /accounts/{accountId}/webhooks/endpoints`](./api-reference.md#list-webhook-endpoints) | `IWebhookEndpoint[]`, oldest first |
|
|
531
|
+
| `createEndpoint(payload, accountId?)` | [`POST /accounts/{accountId}/webhooks/endpoints`](./api-reference.md#create-webhook-endpoint) | `IWebhookEndpointCreatePayload` → `IWebhookEndpoint` |
|
|
532
|
+
| `getEndpoint(endpointId, accountId?)` | [`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}`](./api-reference.md#get-webhook-endpoint) | `IWebhookEndpoint` |
|
|
533
|
+
| `updateEndpoint(endpointId, payload, accountId?)` | [`PUT /accounts/{accountId}/webhooks/endpoints/{endpointId}`](./api-reference.md#update-webhook-endpoint) | `IWebhookEndpointUpdatePayload` → `IWebhookEndpoint` |
|
|
534
|
+
| `deleteEndpoint(endpointId, accountId?)` | [`DELETE /accounts/{accountId}/webhooks/endpoints/{endpointId}`](./api-reference.md#delete-webhook-endpoint) | `IEmptyResult` (`[]`) |
|
|
535
|
+
| `getEndpointSecret(endpointId, accountId?)` | [`GET /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret`](./api-reference.md#get-webhook-endpoint-signing-secret) | `IWebhookEndpointSecret` (`{ secret }`) |
|
|
536
|
+
| `rotateEndpointSecret(endpointId, accountId?)` | [`POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/secret/rotate`](./api-reference.md#rotate-webhook-endpoint-signing-secret) | `IWebhookEndpointSecret` |
|
|
537
|
+
| `register(payload, accountId?)` | [`PUT /accounts/{accountId}/webhooks/subscriptions`](./api-reference.md#update-webhook-subscription) | `IWebhookSubscription` (oldest endpoint) |
|
|
510
538
|
| `get(accountId?)` | [`GET /accounts/{accountId}/webhooks/subscriptions`](./api-reference.md#get-webhook-subscription) | `IWebhookSubscription | null` |
|
|
511
539
|
| `inactivate(accountId?)` | [`PUT /accounts/{accountId}/webhooks/inactivate`](./api-reference.md#inactivate-webhook-subscription) | `IWebhookSubscription` |
|
|
512
540
|
| `listEventTypes()` | [`GET /webhooks/event-types`](./api-reference.md#list-webhook-event-types) | `IWebhookEventTypeInfo[]` |
|
|
513
541
|
| `listDispatches(params?, accountId?)` | [`GET /accounts/{accountId}/webhooks`](./api-reference.md#list-webhook-deliveries) | `PaginatedResult<IWebhookDispatch>` |
|
|
514
542
|
| `retryDispatch(dispatchId, accountId?)` | [`POST /accounts/{accountId}/webhooks/{dispatchId}/retry`](./api-reference.md#retry-webhook-delivery) | `IWebhookDispatch` |
|
|
515
543
|
|
|
516
|
-
|
|
544
|
+
Endpoint payload: `{ url: string; email: string; events?: string[]; name?: string; is_active?: boolean; signing_enabled?: boolean }`. Update sends only the given fields and requires at least one. URLs must be HTTP(S) and unique within the workspace (`400`); creating past the plan limit returns `403`. Enabling signing creates a `whsec_` secret if none exists; disabling it discards the secret. Secret read and rotation return `400` when signing is disabled and are not available to OAuth applications; rotation invalidates the previous secret immediately.
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
const endpoint = await client.webhooks.createEndpoint({
|
|
548
|
+
url: 'https://example.com/assinafy/webhooks',
|
|
549
|
+
email: 'ops@example.com',
|
|
550
|
+
name: 'ERP',
|
|
551
|
+
events: ['document_ready', 'signer_signed_document'],
|
|
552
|
+
signing_enabled: true,
|
|
553
|
+
});
|
|
554
|
+
const { secret } = await client.webhooks.getEndpointSecret(endpoint.id);
|
|
555
|
+
// Store `secret` in your receiver's secret manager.
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
Registration payload: `{ url: string; email: string; events?: string[]; is_active?: boolean }`. When `events` is omitted on `register` or `createEndpoint`, the SDK uses `document_ready`, `document_prepared`, `signer_signed_document`, `signer_rejected_document`, and `document_processing_failed`; pass `[]` deliberately for none. Dispatch filters extend pagination with `{ endpoint_id?, event?, delivered?, from?, to?, sort?: 'created_at' | '-created_at' }`; sort is a compatibility extension. Dispatch records include `endpoint_id`. Dispatch `search` is unsupported and rejected locally. Retrying re-sends only to that entry's endpoint and requires the endpoint to be active. There is no delete-subscription operation; delete a specific endpoint with `deleteEndpoint` or deactivate the oldest with `inactivate`.
|
|
517
559
|
|
|
518
560
|
Decline operations require a non-empty reason of at most 2,000 Unicode characters. `signers.findByEmail` follows pagination metadata until an exact case-insensitive email match is found or the search is exhausted; when a response carries no pagination metadata a partial page ends the search, and the scan is bounded at 100 pages.
|
|
519
561
|
|
|
@@ -536,21 +578,41 @@ try {
|
|
|
536
578
|
}
|
|
537
579
|
```
|
|
538
580
|
|
|
539
|
-
## Webhook verification
|
|
581
|
+
## Webhook verification
|
|
582
|
+
|
|
583
|
+
Deliveries are `POST` requests with `Content-Type: application/json`, a `webhook-id` (stable across retries of the same event to the same endpoint; use it to deduplicate), a `webhook-timestamp` (Unix seconds), and, when the endpoint has `signing_enabled`, a `webhook-signature` following [Standard Webhooks](https://www.standardwebhooks.com). Any `2xx` is success; a failed delivery is retried once after 3 seconds. After 10 consecutive failed events the endpoint's delivery is paused and probed until one succeeds; use `retryDispatch` to force redelivery.
|
|
540
584
|
|
|
541
585
|
| API | Result |
|
|
542
586
|
| --- | --- |
|
|
543
|
-
| `new WebhookVerifier(secret?, { algorithm?, encoding? }?)` |
|
|
544
|
-
| `
|
|
587
|
+
| `new WebhookVerifier(secret?, { algorithm?, encoding? }?)` | Verifier keyed with an endpoint's `whsec_` secret. The options apply only to the deprecated `verify`. |
|
|
588
|
+
| `verifyDelivery(rawBody, headers, { toleranceSeconds?, now? }?)` | `boolean`. Checks `v1` HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{rawBody}` with the base64-decoded secret, constant-time, against every space-separated signature entry, and rejects timestamps more than `toleranceSeconds` (default 300) from `now` (ms, default `Date.now()`). `headers` may be Node `IncomingHttpHeaders`, a plain record (case-insensitive), or Fetch `Headers`; repeated headers are rejected. |
|
|
589
|
+
| `verify(rawBody, signature)` | Deprecated body-only HMAC kept for existing callers; Assinafy deliveries do not use it. |
|
|
545
590
|
| `extractEvent(rawBody)` | Parsed `IWebhookPayload`, or `null` for invalid JSON/non-object data. |
|
|
546
591
|
| `getEventType(event)` | `event`/`type` string, or `null`. |
|
|
547
592
|
| `getEventData(event)` | First object found at `payload`, `data`, or `object`; otherwise `{}`. |
|
|
548
593
|
|
|
549
|
-
|
|
594
|
+
`client.webhookVerifier` uses the `webhookSecret` client option. Each endpoint has its own secret, so construct one verifier per signed endpoint.
|
|
595
|
+
|
|
596
|
+
```ts
|
|
597
|
+
import express from 'express';
|
|
598
|
+
import { WebhookVerifier } from '@assinafy/cli/api';
|
|
599
|
+
|
|
600
|
+
const verifier = new WebhookVerifier(process.env.ASSINAFY_WEBHOOK_SECRET);
|
|
601
|
+
const app = express();
|
|
602
|
+
|
|
603
|
+
app.post('/assinafy/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
|
|
604
|
+
if (!verifier.verifyDelivery(req.body, req.headers)) return res.sendStatus(401);
|
|
605
|
+
const event = verifier.extractEvent(req.body);
|
|
606
|
+
// Deduplicate by req.headers['webhook-id'], enqueue the work, and answer quickly.
|
|
607
|
+
res.sendStatus(204);
|
|
608
|
+
});
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
Verify the raw bytes before parsing; re-serialized JSON does not match. The envelope is `{ id, event, message, payload, origin, created_at, subject, object, account_id }`; `subject` and `object` carry a `type` of `User`, `Signer`, `Account`, `Document`, or `Template`. Unknown fields are forward-compatible additions. Confirm business state (for example a document's status) through the API before irreversible actions.
|
|
550
612
|
|
|
551
613
|
## Contract boundaries
|
|
552
614
|
|
|
553
|
-
- Production OpenAPI currently publishes
|
|
554
|
-
- Certificate start/complete are deployed production extensions, exposed by `startCertificate` and `completeCertificate` with the signing application's payloads. They supplement the
|
|
615
|
+
- Production OpenAPI currently publishes 106 operations. Some sandbox deployments lag it; account/user statistics and user notification-preference routes may return route-level 404s even though production documentation includes them.
|
|
616
|
+
- Certificate start/complete are deployed production extensions, exposed by `startCertificate` and `completeCertificate` with the signing application's payloads. They supplement the 106 OpenAPI operations; the API manifest contains only published paths.
|
|
555
617
|
- The SDK retains the two template compatibility routes above and both published/legacy public `sendToken` payloads for compatible deployments.
|
|
556
618
|
- Signer artifact downloads are public in the published contract. Supplying a signer access code opts into an SDK identity preflight; it does not change the server route into a private endpoint.
|
package/docs/signers.md
CHANGED
|
@@ -80,7 +80,7 @@ Options:
|
|
|
80
80
|
--name <name> Signer full name
|
|
81
81
|
--email <email> Email address
|
|
82
82
|
--phone <number> WhatsApp phone number (E.164)
|
|
83
|
-
--cpf <cpf> Brazilian tax ID (CPF)
|
|
83
|
+
--cpf <cpf> Brazilian tax ID (CPF/CNPJ), sent as government_id
|
|
84
84
|
-h, --help display help for command
|
|
85
85
|
```
|
|
86
86
|
|
package/docs/webhooks.md
CHANGED
|
@@ -5,27 +5,168 @@
|
|
|
5
5
|
```text
|
|
6
6
|
Usage: assinafy webhooks [options] [command]
|
|
7
7
|
|
|
8
|
-
Manage webhook
|
|
8
|
+
Manage webhook endpoints, the primary subscription, and delivery history
|
|
9
9
|
|
|
10
10
|
Options:
|
|
11
11
|
-h, --help display help for command
|
|
12
12
|
|
|
13
13
|
Commands:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
endpoints Manage webhook endpoints and their signing secrets
|
|
15
|
+
register [options] Register (or replace) the account's oldest webhook
|
|
16
|
+
endpoint
|
|
17
|
+
get Show the account's oldest webhook endpoint
|
|
18
|
+
inactivate Inactivate the account's oldest webhook endpoint without
|
|
19
|
+
deleting it
|
|
17
20
|
event-types List supported webhook event types
|
|
18
21
|
dispatches [options] List webhook delivery history
|
|
19
22
|
retry <dispatchId> Retry delivery of a specific dispatch
|
|
20
23
|
help [command] display help for command
|
|
21
24
|
```
|
|
22
25
|
|
|
26
|
+
### `assinafy webhooks endpoints`
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
Usage: assinafy webhooks endpoints [options] [command]
|
|
30
|
+
|
|
31
|
+
Manage webhook endpoints and their signing secrets
|
|
32
|
+
|
|
33
|
+
Options:
|
|
34
|
+
-h, --help display help for command
|
|
35
|
+
|
|
36
|
+
Commands:
|
|
37
|
+
list|ls List webhook endpoints, oldest first
|
|
38
|
+
create [options] Register a webhook endpoint (1 per
|
|
39
|
+
account, up to 3 on paid plans)
|
|
40
|
+
get <endpointId> Show one webhook endpoint
|
|
41
|
+
update [options] <endpointId> Update the given fields of a webhook
|
|
42
|
+
endpoint
|
|
43
|
+
delete|rm [options] <endpointId> Delete a webhook endpoint and free its
|
|
44
|
+
slot
|
|
45
|
+
secret <endpointId> Print the endpoint signing secret
|
|
46
|
+
(signing must be enabled; not available
|
|
47
|
+
via OAuth)
|
|
48
|
+
rotate-secret [options] <endpointId> Replace the endpoint signing secret; the
|
|
49
|
+
old one stops working immediately
|
|
50
|
+
help [command] display help for command
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### `assinafy webhooks endpoints list`
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
Usage: assinafy webhooks endpoints list|ls [options]
|
|
57
|
+
|
|
58
|
+
List webhook endpoints, oldest first
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
-h, --help display help for command
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### `assinafy webhooks endpoints create`
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
Usage: assinafy webhooks endpoints create [options]
|
|
68
|
+
|
|
69
|
+
Register a webhook endpoint (1 per account, up to 3 on paid plans)
|
|
70
|
+
|
|
71
|
+
Options:
|
|
72
|
+
--url <url> Endpoint URL to receive events
|
|
73
|
+
--email <email> Contact email for delivery problems
|
|
74
|
+
--name <name> Label to tell endpoints apart
|
|
75
|
+
--events <csv> Comma-separated event names
|
|
76
|
+
--active Deliver events to this endpoint
|
|
77
|
+
--inactive Stop delivering events
|
|
78
|
+
--signing Sign deliveries (Standard Webhooks)
|
|
79
|
+
--no-signing Disable signing and discard the secret
|
|
80
|
+
-h, --help display help for command
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### `assinafy webhooks endpoints get`
|
|
84
|
+
|
|
85
|
+
```text
|
|
86
|
+
Usage: assinafy webhooks endpoints get [options] <endpointId>
|
|
87
|
+
|
|
88
|
+
Show one webhook endpoint
|
|
89
|
+
|
|
90
|
+
Arguments:
|
|
91
|
+
endpointId Endpoint ID
|
|
92
|
+
|
|
93
|
+
Options:
|
|
94
|
+
-h, --help display help for command
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### `assinafy webhooks endpoints update`
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
Usage: assinafy webhooks endpoints update [options] <endpointId>
|
|
101
|
+
|
|
102
|
+
Update the given fields of a webhook endpoint
|
|
103
|
+
|
|
104
|
+
Arguments:
|
|
105
|
+
endpointId Endpoint ID
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
--url <url> Endpoint URL to receive events
|
|
109
|
+
--email <email> Contact email for delivery problems
|
|
110
|
+
--name <name> Label to tell endpoints apart
|
|
111
|
+
--events <csv> Comma-separated event names
|
|
112
|
+
--active Deliver events to this endpoint
|
|
113
|
+
--inactive Stop delivering events
|
|
114
|
+
--signing Sign deliveries (Standard Webhooks)
|
|
115
|
+
--no-signing Disable signing and discard the secret
|
|
116
|
+
-h, --help display help for command
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### `assinafy webhooks endpoints delete`
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
Usage: assinafy webhooks endpoints delete|rm [options] <endpointId>
|
|
123
|
+
|
|
124
|
+
Delete a webhook endpoint and free its slot
|
|
125
|
+
|
|
126
|
+
Arguments:
|
|
127
|
+
endpointId Endpoint ID
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
-y, --yes Skip the confirmation prompt
|
|
131
|
+
-h, --help display help for command
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### `assinafy webhooks endpoints secret`
|
|
135
|
+
|
|
136
|
+
```text
|
|
137
|
+
Usage: assinafy webhooks endpoints secret [options] <endpointId>
|
|
138
|
+
|
|
139
|
+
Print the endpoint signing secret (signing must be enabled; not available via
|
|
140
|
+
OAuth)
|
|
141
|
+
|
|
142
|
+
Arguments:
|
|
143
|
+
endpointId Endpoint ID
|
|
144
|
+
|
|
145
|
+
Options:
|
|
146
|
+
-h, --help display help for command
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### `assinafy webhooks endpoints rotate-secret`
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
Usage: assinafy webhooks endpoints rotate-secret [options] <endpointId>
|
|
153
|
+
|
|
154
|
+
Replace the endpoint signing secret; the old one stops working immediately
|
|
155
|
+
|
|
156
|
+
Arguments:
|
|
157
|
+
endpointId Endpoint ID
|
|
158
|
+
|
|
159
|
+
Options:
|
|
160
|
+
-y, --yes Skip the confirmation prompt
|
|
161
|
+
-h, --help display help for command
|
|
162
|
+
```
|
|
163
|
+
|
|
23
164
|
### `assinafy webhooks register`
|
|
24
165
|
|
|
25
166
|
```text
|
|
26
167
|
Usage: assinafy webhooks register [options]
|
|
27
168
|
|
|
28
|
-
Register (or replace) the
|
|
169
|
+
Register (or replace) the account's oldest webhook endpoint
|
|
29
170
|
|
|
30
171
|
Options:
|
|
31
172
|
--url <url> Endpoint URL to receive events
|
|
@@ -40,7 +181,7 @@ Options:
|
|
|
40
181
|
```text
|
|
41
182
|
Usage: assinafy webhooks get [options]
|
|
42
183
|
|
|
43
|
-
Show the
|
|
184
|
+
Show the account's oldest webhook endpoint
|
|
44
185
|
|
|
45
186
|
Options:
|
|
46
187
|
-h, --help display help for command
|
|
@@ -51,7 +192,7 @@ Options:
|
|
|
51
192
|
```text
|
|
52
193
|
Usage: assinafy webhooks inactivate [options]
|
|
53
194
|
|
|
54
|
-
Inactivate the webhook
|
|
195
|
+
Inactivate the account's oldest webhook endpoint without deleting it
|
|
55
196
|
|
|
56
197
|
Options:
|
|
57
198
|
-h, --help display help for command
|
|
@@ -76,14 +217,15 @@ Usage: assinafy webhooks dispatches [options]
|
|
|
76
217
|
List webhook delivery history
|
|
77
218
|
|
|
78
219
|
Options:
|
|
79
|
-
--
|
|
80
|
-
--
|
|
81
|
-
--
|
|
82
|
-
--
|
|
83
|
-
--
|
|
84
|
-
--
|
|
85
|
-
--
|
|
86
|
-
|
|
220
|
+
--endpoint <endpointId> Only deliveries to this webhook endpoint
|
|
221
|
+
--event <event> Filter by event name
|
|
222
|
+
--delivered <bool> Filter by delivery status (true/false)
|
|
223
|
+
--from <unix> Start of time range (unix seconds)
|
|
224
|
+
--to <unix> End of time range (unix seconds)
|
|
225
|
+
--page <n> Page number to fetch
|
|
226
|
+
--per-page <n> Items per page
|
|
227
|
+
--sort <field> Sort by created_at (prefix with - for descending)
|
|
228
|
+
-h, --help display help for command
|
|
87
229
|
```
|
|
88
230
|
|
|
89
231
|
### `assinafy webhooks retry`
|
package/install.ps1
CHANGED
|
@@ -41,6 +41,13 @@ function Add-UserPath([string]$Directory) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function Test-ArchiveLayout([string]$Archive, [string]$Target) {
|
|
44
|
+
$details = @(& tar -tvzf $Archive)
|
|
45
|
+
if ($LASTEXITCODE -ne 0) {
|
|
46
|
+
Fail "Unable to read release archive"
|
|
47
|
+
}
|
|
48
|
+
if (@($details | Where-Object { -not $_.StartsWith("-") }).Count -gt 0) {
|
|
49
|
+
Fail "Release archive contained a link or special file"
|
|
50
|
+
}
|
|
44
51
|
$entries = @(& tar -tzf $Archive)
|
|
45
52
|
if ($LASTEXITCODE -ne 0) {
|
|
46
53
|
Fail "Unable to read release archive"
|
|
@@ -163,6 +170,9 @@ try {
|
|
|
163
170
|
Test-ArchiveLayout $archive $target
|
|
164
171
|
|
|
165
172
|
tar -xzf $archive -C $extractDir
|
|
173
|
+
if ($LASTEXITCODE -ne 0) {
|
|
174
|
+
Fail "Unable to extract release archive"
|
|
175
|
+
}
|
|
166
176
|
$unsafeEntry = Get-ChildItem $extractDir -Recurse -Force | Where-Object {
|
|
167
177
|
($_.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0
|
|
168
178
|
} | Select-Object -First 1
|
package/install.sh
CHANGED
|
@@ -243,6 +243,9 @@ validate_archive() {
|
|
|
243
243
|
local archive="$1"
|
|
244
244
|
local target="$2"
|
|
245
245
|
local entry expected executable_count=0 version_count=0
|
|
246
|
+
if ! tar -tvzf "$archive" | awk 'substr($0, 1, 1) != "-" { invalid = 1 } END { exit invalid }'; then
|
|
247
|
+
fail "Release archive contained a link or special file"
|
|
248
|
+
fi
|
|
246
249
|
if [[ "$target" == windows-* ]]; then
|
|
247
250
|
expected='assinafy.cmd|assinafy.cjs'
|
|
248
251
|
else
|