assinafy 2.1.0 → 2.2.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.
@@ -50,6 +50,7 @@ module Assinafy
50
50
  body = with_explicit_regex(raw, body_params(raw))
51
51
  require_string(body['name'], 'Field name')
52
52
  require_string(body['type'], 'Field type')
53
+ require_string(body['regex'], 'Field regex') if body.key?('regex') && !body['regex'].nil?
53
54
  require_boolean(body['is_required'], 'is_required') if body.key?('is_required')
54
55
 
55
56
  call('Failed to create field definition') do
@@ -171,6 +172,7 @@ module Assinafy
171
172
  raw = require_payload(payload)
172
173
  body = with_explicit_regex(raw, body_params(raw))
173
174
  require_string(body['name'], 'Field name') if body.key?('name')
175
+ require_string(body['regex'], 'Field regex') if body.key?('regex') && !body['regex'].nil?
174
176
  require_boolean(body['is_active'], 'is_active') if body.key?('is_active')
175
177
 
176
178
  call('Failed to update field definition') do
@@ -201,9 +203,8 @@ module Assinafy
201
203
 
202
204
  # Validate a single value against a field definition.
203
205
  #
204
- # The OpenAPI declares workspace Authorization, which is used when
205
- # `signer_access_code:` is omitted. The deployed API also accepts the signer
206
- # access code: when the keyword is given it must be a non-blank code, and
206
+ # Workspace authorization is used when `signer_access_code:` is omitted.
207
+ # When the keyword is given it must be a non-blank code, and
207
208
  # only the code is sent (never the workspace credentials).
208
209
  #
209
210
  # @param field_id [String]
@@ -287,6 +287,8 @@ module Assinafy
287
287
  # @raise [Assinafy::NetworkError] on transport or TLS failure
288
288
  # @raise [Assinafy::ValidationError] on invalid required input
289
289
  def revoke(token:, client_id:, token_type_hint: nil, client_secret: nil)
290
+ require_string(client_secret, 'Client secret') unless client_secret.nil?
291
+
290
292
  if !token_type_hint.nil? && !TOKEN_TYPE_HINTS.include?(token_type_hint.to_s)
291
293
  raise ValidationError.new(
292
294
  "Token type hint must be one of: #{TOKEN_TYPE_HINTS.join(', ')}",
@@ -396,6 +398,10 @@ module Assinafy
396
398
  # pass `"#{protected_resource_metadata['authorization_servers'].first}" \
397
399
  # "/.well-known/oauth-authorization-server"` to follow discovery strictly
398
400
  # @return [Hash{String=>Object}] the bare metadata object
401
+ # @raise [Assinafy::OAuthError] on an unsuccessful metadata response
402
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
403
+ # @raise [Assinafy::ValidationError] when the URL is not absolute HTTPS without userinfo or fragment
404
+ # @see GET https://auth.assinafy.com.br/.well-known/oauth-authorization-server
399
405
  #
400
406
  # @example Discover endpoints instead of hardcoding them
401
407
  # metadata = client.oauth.authorization_server_metadata
@@ -25,6 +25,7 @@ module Assinafy
25
25
  #
26
26
  # @param signer_id [String]
27
27
  # @param signer_access_code [String]
28
+ # @param expand [String, Array<String>, nil] envelope to include its id and name
28
29
  # @return [Hash] the document (envelope `data` unwrapped)
29
30
  # @raise [Assinafy::ApiError] on an unsuccessful API response
30
31
  # @raise [Assinafy::NetworkError] on transport or TLS failure
@@ -51,12 +52,14 @@ module Assinafy
51
52
  # # "assignment" => { "id" => "1", "method" => "virtual", "items" => [{ ... }] }
52
53
  # # # ... (see docs for full shape)
53
54
  # # }
54
- def current(signer_id, signer_access_code:)
55
+ def current(signer_id, signer_access_code:, expand: nil)
55
56
  sid = require_id(signer_id, 'Signer ID')
56
57
  access_code = require_signer_access_code(signer_access_code)
58
+ expansion = signing_expansion(expand)
57
59
 
58
60
  call('Failed to fetch signer document') do
59
- http_get("signers/#{sid}/document", { signer_access_code: access_code }, workspace_auth: false)
61
+ http_get("signers/#{sid}/document", { signer_access_code: access_code, expand: expansion },
62
+ workspace_auth: false)
60
63
  end
61
64
  end
62
65
 
@@ -252,30 +255,22 @@ module Assinafy
252
255
  end
253
256
  end
254
257
 
255
- # Download an artifact for one of the signer's documents.
256
- #
257
- # This endpoint is public (no auth required) — only the document and
258
- # artifact IDs are needed — so `signer_access_code:` is optional and
259
- # omitted from the query when nil.
258
+ # Download a signer's original document. Certified copies use {#download_certified_copy}.
260
259
  #
261
- # @param signer_id [String]
262
- # @param document_id [String]
263
- # @param artifact_name [String] `original`, `certificated`, `certificate-page`, `pades`, or
264
- # `bundle`
265
- # @param signer_access_code [String, nil] retained for call compatibility;
266
- # validated when present but never transmitted by this public endpoint
267
- # @return [String] binary file body (ASCII-8BIT), e.g. the raw PDF bytes
268
- # @raise [Assinafy::ApiError] on an unsuccessful API response
260
+ # @param signer_id [String]
261
+ # @param document_id [String]
262
+ # @param artifact_name [String] original; other names are passed to the API for compatibility
263
+ # @param signer_access_code [String] required; no workspace credentials are transmitted
264
+ # @return [String] binary PDF bytes
265
+ # @raise [Assinafy::ValidationError] on invalid IDs, artifact or access code
266
+ # @raise [Assinafy::ApiError] on an unsuccessful response, including unavailable artifacts
269
267
  # @raise [Assinafy::NetworkError] on transport or TLS failure
270
- # @raise [Assinafy::ValidationError] on invalid required input
271
- # @see GET /signers/{signer_id}/documents/{document_id}/download/{artifact_name}
272
- # @example Download the original PDF and write it to disk (no access code needed)
273
- # pdf = client.signer_documents.download('signer-id', 'document-id', 'original')
274
- #
275
- # # Response is the raw artifact body (Content-Type: application/pdf):
276
- # # => "%PDF-1.7\n..." (binary string)
277
- # File.binwrite('document.pdf', pdf)
278
- def download(signer_id, document_id, artifact_name = 'certificated', signer_access_code: nil)
268
+ # @see GET /signers/{signerId}/documents/{documentId}/download/{artifactName}
269
+ # @example Download the original (no request body)
270
+ # client.signer_documents.download('signer-id', 'document-id', signer_access_code: 'access-code')
271
+ # # GET /signers/signer-id/documents/document-id/download/original?signer-access-code=access-code
272
+ # # => "%PDF-1.7..." # binary String
273
+ def download(signer_id, document_id, artifact_name = 'original', signer_access_code: nil)
279
274
  sid = require_id(signer_id, 'Signer ID')
280
275
  did = require_id(document_id, 'Document ID')
281
276
  art = require_id(artifact_name, 'Artifact name')
@@ -283,10 +278,82 @@ module Assinafy
283
278
  raise ValidationError.new('Invalid artifact type', { artifact_name: artifact_name })
284
279
  end
285
280
 
286
- require_signer_access_code(signer_access_code) unless signer_access_code.nil?
281
+ code = require_signer_access_code(signer_access_code)
287
282
 
288
283
  call_binary('Failed to download signer document') do
289
- http_get("signers/#{sid}/documents/#{did}/download/#{art}", {}, workspace_auth: false)
284
+ http_get("signers/#{sid}/documents/#{did}/download/#{art}",
285
+ { signer_access_code: code }, workspace_auth: false)
286
+ end
287
+ end
288
+
289
+ # Send the certified copy to the contact used during signing, including after the code closes.
290
+ # Email allows one resend per two minutes and ten per day; Whatsapp allows one per request.
291
+ #
292
+ # @param signer_access_code [String]
293
+ # @param document_id [String, nil] another document in the code's envelope
294
+ # @return [Hash] available, notification_method, nullable resends_left and masked sent_to
295
+ # @raise [Assinafy::ValidationError] on an invalid code or document ID
296
+ # @raise [Assinafy::ApiError] when unavailable or rate limited
297
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
298
+ # @see POST /sign/certified-copy
299
+ # @example Request a new 30-minute link with signer-only authentication
300
+ # client.signer_documents.send_certified_copy(signer_access_code: 'access-code', document_id: 'document-id')
301
+ # # POST /sign/certified-copy?signer-access-code=access-code
302
+ # # Body: { 'document_id' => 'document-id' }
303
+ # # => { 'available' => true, 'notification_method' => 'Email',
304
+ # # 'resends_left' => nil, 'sent_to' => 's***@example.com' }
305
+ def send_certified_copy(signer_access_code:, document_id: nil)
306
+ code = require_signer_access_code(signer_access_code)
307
+ require_id(document_id, 'Document ID') unless document_id.nil?
308
+
309
+ call('Failed to send certified copy') do
310
+ http_post('sign/certified-copy', body_params(document_id: document_id),
311
+ { signer_access_code: code }, workspace_auth: false)
312
+ end
313
+ end
314
+
315
+ # Download a certified PDF with the token from a completion or resend message.
316
+ # An expired link returns 302 as ApiError; redirects are never followed.
317
+ #
318
+ # @param token [String] download-link token
319
+ # @param pades [Boolean] request the PAdES variant, when available
320
+ # @return [String] binary PDF bytes
321
+ # @raise [Assinafy::ValidationError] on an invalid token or pades flag
322
+ # @raise [Assinafy::ApiError] on an expired link or unavailable artifact
323
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
324
+ # @see GET /signers/downloads/{token}
325
+ # @example Download using the link token alone (no request body)
326
+ # client.signer_documents.download_certified_copy('download-token')
327
+ # # GET /signers/downloads/download-token
328
+ # # => "%PDF-1.7..." # binary String
329
+ def download_certified_copy(token, pades: false)
330
+ link_token = require_id(token, 'Download token')
331
+ require_boolean(pades, 'pades')
332
+ path = "signers/downloads/#{link_token}"
333
+ path += '/pades' if pades
334
+
335
+ call_binary('Failed to download certified copy') { http_get(path, {}, workspace_auth: false) }
336
+ end
337
+
338
+ # Send a fresh certified-copy link using a known expired download token.
339
+ # Uses the same contact and resend limits as {#send_certified_copy}.
340
+ #
341
+ # @param token [String] download-link token
342
+ # @return [Hash] available, notification_method, nullable resends_left and masked sent_to
343
+ # @raise [Assinafy::ValidationError] on an invalid token
344
+ # @raise [Assinafy::ApiError] on an unknown link, unavailable copy or rate limit
345
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
346
+ # @see POST /signers/downloads/{token}/resend
347
+ # @example Request a replacement link without workspace credentials (no body)
348
+ # client.signer_documents.resend_certified_copy('download-token')
349
+ # # POST /signers/downloads/download-token/resend
350
+ # # => { 'available' => true, 'notification_method' => 'Email',
351
+ # # 'resends_left' => nil, 'sent_to' => 's***@example.com' }
352
+ def resend_certified_copy(token)
353
+ link_token = require_id(token, 'Download token')
354
+
355
+ call('Failed to resend certified copy') do
356
+ http_post("signers/downloads/#{link_token}/resend", workspace_auth: false)
290
357
  end
291
358
  end
292
359
 
@@ -334,7 +334,7 @@ module Assinafy
334
334
  # other signer-authenticated endpoint. This operation has no request body.
335
335
  #
336
336
  # @param signer_access_code [String]
337
- # @return [nil] the documented success envelope has no `data` payload
337
+ # @return [Hash] full_name, email and has_accepted_terms
338
338
  # @raise [Assinafy::ApiError] on an unsuccessful API response
339
339
  # @raise [Assinafy::NetworkError] on transport or TLS failure
340
340
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -345,8 +345,8 @@ module Assinafy
345
345
  # # Request: PUT /signers/accept-terms?signer-access-code=signer-access-code
346
346
  # # Body: none
347
347
  #
348
- # # Response: { "status": 200, "message": "Terms accepted" }
349
- # # => nil
348
+ # # => { "full_name" => "Example Signer", "email" => "signer@example.com",
349
+ # # "has_accepted_terms" => true }
350
350
  def accept_terms(signer_access_code:)
351
351
  code = require_signer_access_code(signer_access_code)
352
352
 
@@ -355,11 +355,11 @@ module Assinafy
355
355
  end
356
356
  end
357
357
 
358
- # Verify the signer's email with a one-time verification code.
358
+ # Verify the signer's Email or Whatsapp one-time code.
359
359
  #
360
360
  # @param verification_code [String]
361
361
  # @param signer_access_code [String]
362
- # @return [nil] the documented success envelope has no `data` payload
362
+ # @return [Array, nil] empty Array; nil for older no-data responses
363
363
  # @raise [Assinafy::ApiError] on an unsuccessful API response
364
364
  # @raise [Assinafy::NetworkError] on transport or TLS failure
365
365
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -373,8 +373,8 @@ module Assinafy
373
373
  # # Request: POST /verify?signer-access-code=signer-access-code
374
374
  # # Body: { "verification-code": "123456" }
375
375
  #
376
- # # Response: { "status": 200, "message": "Code verified successfully" }
377
- # # => nil
376
+ # # Response: { "status": 200, "data": [], "message": "Code verified successfully" }
377
+ # # => []
378
378
  def verify_email(verification_code:, signer_access_code:)
379
379
  verification = require_string(verification_code, 'Verification code')
380
380
  code = require_signer_access_code(signer_access_code)
@@ -389,37 +389,32 @@ module Assinafy
389
389
  end
390
390
  end
391
391
 
392
- # Confirm signer data before signing a virtual assignment. The documented
393
- # body fields are `full_name`, `email`, and `government_id`; the payload is
394
- # passed through unchanged, so any additional fields the API accepts can be
395
- # supplied as well.
392
+ # Confirm the contact used by the assignment and optionally accept terms. Certificate signers
393
+ # must do both before opening GET /sign. Existing additional payload fields are passed through.
396
394
  #
397
- # @param document_id [String]
398
- # @param payload [Hash] `:full_name`, `:email`, `:government_id`
395
+ # @param document_id [String]
396
+ # @param payload [Hash] email, whatsapp_phone_number and has_accepted_terms
399
397
  # @param signer_access_code [String]
400
- # @return [Hash] the updated signer object (envelope `data` unwrapped)
398
+ # @return [Array] empty Array on success
401
399
  # @raise [Assinafy::ApiError] on an unsuccessful API response
402
400
  # @raise [Assinafy::NetworkError] on transport or TLS failure
403
401
  # @raise [Assinafy::ValidationError] on invalid required input
404
402
  # @see PUT /documents/{documentId}/signers/confirm-data
405
- # @example Confirm the signer's data
406
- # result = client.signers.confirm_data(
407
- # 'document-id',
408
- # { full_name: 'Signer Name', email: 'signer@example.com', government_id: '00000000000' },
409
- # signer_access_code: 'signer-access-code'
410
- # )
411
- #
412
- # # signer-access-code is sent as a query param; the JSON body the SDK sends:
413
- # # { "full_name": "Signer Name", "email": "signer@example.com", "government_id": "00000000000" }
414
- #
415
- # # => {
416
- # # "resource" => "signer", "id" => "signer-id", "full_name" => "Signer Name",
417
- # # "email" => "signer@example.com", "whatsapp_phone_number" => nil, "has_accepted_terms" => false
418
- # # }
403
+ # @example Confirm contact and terms using only the signer access code
404
+ # client.signers.confirm_data('document-id',
405
+ # { email: 'signer@example.com', has_accepted_terms: true }, signer_access_code: 'access-code')
406
+ # # PUT /documents/document-id/signers/confirm-data?signer-access-code=access-code
407
+ # # Body: { 'email' => 'signer@example.com', 'has_accepted_terms' => true }
408
+ # # => []
419
409
  def confirm_data(document_id, payload, signer_access_code:)
420
410
  doc_id = require_id(document_id, 'Document ID')
421
411
  body = body_params(require_payload(payload))
422
412
  code = require_signer_access_code(signer_access_code)
413
+ require_string(body['full_name'], 'Full name') if body.key?('full_name')
414
+ Utils.require_email(body['email']) if body.key?('email')
415
+ require_string(body['government_id'], 'Government ID') if body.key?('government_id')
416
+ require_string(body['whatsapp_phone_number'], 'WhatsApp number') if body.key?('whatsapp_phone_number')
417
+ require_boolean(body['has_accepted_terms'], 'has_accepted_terms') if body.key?('has_accepted_terms')
423
418
 
424
419
  call('Failed to confirm signer data') do
425
420
  http_put("documents/#{doc_id}/signers/confirm-data", body,
@@ -435,8 +430,7 @@ module Assinafy
435
430
  # @param content_type [String] must be `image/png`
436
431
  # @param reuse [Boolean, nil] when true, marks the signature as
437
432
  # reusable for future documents (documented `reuse` query flag)
438
- # @return [nil, Array] `nil` for the OpenAPI's no-data envelope; some deployed
439
- # versions return `data: []`, which the SDK passes through as an empty Array
433
+ # @return [Array, nil] empty Array; nil for older no-data responses
440
434
  # @raise [Assinafy::ApiError] on an unsuccessful API response
441
435
  # @raise [Assinafy::NetworkError] on transport or TLS failure
442
436
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -453,8 +447,7 @@ module Assinafy
453
447
  # # The SDK sends the RAW image bytes as the body, with
454
448
  # # Content-Type: image/png and ?signer-access-code=...&type=signature query params.
455
449
  #
456
- # # => nil # documented no-data envelope
457
- # # => [] # when a deployed API version returns data: []
450
+ # # => []
458
451
  def upload_signature(content, signer_access_code:, type: 'signature', content_type: 'image/png', reuse: nil)
459
452
  unless content.is_a?(String) && !content.empty?
460
453
  raise ValidationError.new('Signature content must be a non-empty String')
@@ -508,6 +501,47 @@ module Assinafy
508
501
  end
509
502
  end
510
503
 
504
+ # Read the signing workspace's brand using the signer's access code.
505
+ #
506
+ # @param signer_access_code [String]
507
+ # @return [Hash] account_name, primary_color, secondary_color and nullable logo URL
508
+ # @raise [Assinafy::ValidationError] on an invalid access code
509
+ # @raise [Assinafy::ApiError] on an unsuccessful API response
510
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
511
+ # @see GET /sign/theme
512
+ # @example Read branding (no body, no workspace credentials)
513
+ # client.signers.theme(signer_access_code: 'access-code')
514
+ # # GET /sign/theme?signer-access-code=access-code
515
+ # # => { 'account_name' => 'Example Workspace', 'primary_color' => 'aabbcc',
516
+ # # 'secondary_color' => 'ffffff', 'logo' => 'https://api.assinafy.com.br/v1/sign/logo' }
517
+ def theme(signer_access_code:)
518
+ code = require_signer_access_code(signer_access_code)
519
+
520
+ call('Failed to read signing theme') do
521
+ http_get('sign/theme', { signer_access_code: code }, workspace_auth: false)
522
+ end
523
+ end
524
+
525
+ # Download the signing workspace's logo with signer-only authentication.
526
+ #
527
+ # @param signer_access_code [String]
528
+ # @return [String] binary image bytes
529
+ # @raise [Assinafy::ValidationError] on an invalid access code
530
+ # @raise [Assinafy::ApiError] on an unsuccessful API response, including 404 without a logo
531
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
532
+ # @see GET /sign/logo
533
+ # @example Download branding (no request body)
534
+ # client.signers.download_logo(signer_access_code: 'access-code')
535
+ # # GET /sign/logo?signer-access-code=access-code
536
+ # # => "PNG image bytes" # binary String
537
+ def download_logo(signer_access_code:)
538
+ code = require_signer_access_code(signer_access_code)
539
+
540
+ call_binary('Failed to download signing logo') do
541
+ http_get('sign/logo', { signer_access_code: code }, workspace_auth: false)
542
+ end
543
+ end
544
+
511
545
  private
512
546
 
513
547
  def assert_email!(email)
@@ -52,7 +52,7 @@ module Assinafy
52
52
  #
53
53
  # @param payload [Hash]
54
54
  # @option payload [String] :name required tag display name
55
- # @option payload [String, nil] :color optional 6-character hex color
55
+ # @option payload [String, nil] :color optional 6-digit hex color, with or without `#`
56
56
  # @param account_id_override [String, nil]
57
57
  # @return [Hash] the created tag object
58
58
  # @raise [Assinafy::ValidationError] if `:name` is missing or blank
@@ -168,6 +168,10 @@ module Assinafy
168
168
  body['color'] = nil if explicit_nil_color?(raw)
169
169
 
170
170
  validate_tag_name!(body, require_name: require_name)
171
+ if body.key?('color') && !body['color'].nil?
172
+ color = require_string(body['color'], 'Tag color')
173
+ raise ValidationError.new('Tag color must be a 6-digit hex color') unless color.match?(/\A#?[0-9a-f]{6}\z/i)
174
+ end
171
175
 
172
176
  if !require_name && body.empty?
173
177
  raise ValidationError.new('Provide at least one of name or color to update')
@@ -22,6 +22,11 @@ module Assinafy
22
22
  ContractRenewed
23
23
  ].freeze
24
24
 
25
+ PUSH_PREFERENCE_CODES = %w[
26
+ SignerViewed SignerSigned DocumentCompleted SignerDeclined DocumentAboutToExpire
27
+ DocumentExpired SignerIdentityReviewRequired SignerWhatsappFailed
28
+ ].freeze
29
+
25
30
  # Fetch the authenticated user's profile. The current OpenAPI response is
26
31
  # an `AuthUser` directly, while the deployed API returns the login-like
27
32
  # `{ 'user' => AuthUser, 'accounts' => [...] }` shape. The SDK does not reshape
@@ -86,7 +91,7 @@ module Assinafy
86
91
  # @note Documented in the API reference, but gated on the account's plan:
87
92
  # this route answers 404 where the KPI feature is not enabled.
88
93
  # @param granularity [String, nil] `"monthly"` or `"daily"`
89
- # @param month [String, nil] e.g. `"2026-06"`
94
+ # @param month [String, nil] e.g. `"2026-06"`; required with daily granularity
90
95
  # @return [Array<Hash>] one KPI entry per period
91
96
  # @raise [Assinafy::ApiError] on an unsuccessful API response
92
97
  # @raise [Assinafy::NetworkError] on transport or TLS failure
@@ -189,23 +194,52 @@ module Assinafy
189
194
  # 'ContractRenewed' => true
190
195
  # }
191
196
  def update_notification_preferences(preferences)
192
- preferences = require_payload(preferences, 'Notification preferences')
193
- raise ValidationError.new('At least one notification preference is required') if preferences.empty?
194
-
195
- preferences.each do |code, enabled|
196
- code = code.to_s
197
- unless NOTIFICATION_PREFERENCE_CODES.include?(code)
198
- raise ValidationError.new("Unknown notification preference: #{code}")
199
- end
200
- unless [true, false].include?(enabled)
201
- raise ValidationError.new("Notification preference #{code} must be boolean")
202
- end
203
- end
197
+ require_preferences(preferences, NOTIFICATION_PREFERENCE_CODES)
204
198
 
205
199
  call('Failed to update notification preferences') do
206
200
  http_put('users/self/notification-preferences', body_params(preferences))
207
201
  end
208
202
  end
203
+
204
+ # Read phone push preferences, independently of email preferences.
205
+ # Third-party OAuth applications cannot access these personal settings.
206
+ #
207
+ # @return [Hash{String=>Boolean}] all eight push preference codes
208
+ # @raise [Assinafy::ApiError] on an unsuccessful API response
209
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
210
+ # @see GET /users/self/push-preferences
211
+ # @example Read push preferences
212
+ # client.users.push_preferences
213
+ # # Request: GET /users/self/push-preferences (no body)
214
+ # # => { 'SignerViewed' => true, 'SignerSigned' => true, 'DocumentCompleted' => true,
215
+ # # 'SignerDeclined' => true, 'DocumentAboutToExpire' => true, 'DocumentExpired' => true,
216
+ # # 'SignerIdentityReviewRequired' => true, 'SignerWhatsappFailed' => true }
217
+ def push_preferences
218
+ call('Failed to fetch push preferences') { http_get('users/self/push-preferences') }
219
+ end
220
+
221
+ # Merge phone push preferences; omitted codes keep their current value.
222
+ # Third-party OAuth applications cannot access these personal settings.
223
+ #
224
+ # @param preferences [Hash{String,Symbol=>Boolean}] non-empty partial map
225
+ # @return [Hash{String=>Boolean}] all eight push preference codes
226
+ # @raise [Assinafy::ValidationError] on empty, unknown or non-boolean preferences
227
+ # @raise [Assinafy::ApiError] on an unsuccessful API response
228
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
229
+ # @see PUT /users/self/push-preferences
230
+ # @example Disable signer-viewed pushes
231
+ # client.users.update_push_preferences(SignerViewed: false)
232
+ # # Request: PUT /users/self/push-preferences
233
+ # # Body: { "SignerViewed": false }
234
+ # # => { 'SignerViewed' => false, 'SignerSigned' => true, 'DocumentCompleted' => true,
235
+ # # 'SignerDeclined' => true, 'DocumentAboutToExpire' => true, 'DocumentExpired' => true,
236
+ # # 'SignerIdentityReviewRequired' => true, 'SignerWhatsappFailed' => true }
237
+ def update_push_preferences(preferences)
238
+ require_preferences(preferences, PUSH_PREFERENCE_CODES)
239
+ call('Failed to update push preferences') do
240
+ http_put('users/self/push-preferences', body_params(preferences))
241
+ end
242
+ end
209
243
  end
210
244
  end
211
245
  end
@@ -361,6 +361,7 @@ module Assinafy
361
361
  # Change a webhook endpoint. Only the fields sent are updated.
362
362
  # `signing_enabled: true` generates a secret when the endpoint has none
363
363
  # and keeps the current one otherwise; `false` discards the secret.
364
+ # Enabling signing returns the new secret once in this response.
364
365
  #
365
366
  # @param endpoint_id [String]
366
367
  # @param payload [Hash] any of `url`, `email`, `events`, `name`, `is_active`, `signing_enabled`
@@ -455,31 +456,62 @@ module Assinafy
455
456
  end
456
457
  end
457
458
 
458
- # Replace an endpoint's signing secret. The old secret stops working
459
- # immediately, so update the receiver right away. Not available to OAuth
460
- # applications.
459
+ # Replace an endpoint's signing secret. By default the old secret stops immediately.
460
+ # `keep_previous: true` keeps it signing for 24 hours while receivers migrate.
461
+ # OAuth applications can rotate with the webhooks:write scope.
461
462
  #
462
463
  # @param endpoint_id [String]
463
464
  # @param account_id_override [String, nil]
464
- # @return [Hash] `{ "secret" => "whsec_..." }` (the new secret)
465
+ # @return [Hash] the new `secret`, plus `previous_secret_expires_at` with keep_previous
465
466
  # @raise [Assinafy::ApiError] `400` when signing is disabled; `404` on an unknown ID
466
467
  # @raise [Assinafy::NetworkError] on transport or TLS failure
467
468
  # @raise [Assinafy::ValidationError] on invalid required input
469
+ # @param keep_previous [Boolean] keep the replaced secret signing for 24 hours
468
470
  # @see POST /accounts/{account_id}/webhooks/endpoints/{endpoint_id}/secret/rotate
469
471
  # @example Rotate the signing secret
470
472
  # client.webhooks.rotate_endpoint_secret('webhook-endpoint-id')
471
473
  # # POST /accounts/{account_id}/webhooks/endpoints/webhook-endpoint-id/secret/rotate (no request body)
472
474
  # # => { 'secret' => "whsec_new-secret-placeholder" }
473
- def rotate_endpoint_secret(endpoint_id, account_id_override = nil)
475
+ def rotate_endpoint_secret(endpoint_id, account_id_override = nil, keep_previous: false)
476
+ require_boolean(keep_previous, 'keep_previous')
474
477
  path = endpoint_path(endpoint_id, account_id_override)
475
478
 
476
479
  @logger.info('Rotating webhook endpoint secret')
477
480
 
478
481
  call('Failed to rotate webhook endpoint secret') do
479
- http_post("#{path}/secret/rotate")
482
+ http_post("#{path}/secret/rotate", keep_previous ? { keep_previous: true } : nil)
480
483
  end
481
484
  end
482
485
 
486
+ # Send one webhook_test delivery now, even to a paused or inactive endpoint.
487
+ # The endpoint gets ten seconds to respond. Limited to ten tests per user per ten minutes;
488
+ # OAuth requires webhooks:write. The call does not change the endpoint's subscription or pause.
489
+ #
490
+ # @param endpoint_id [String]
491
+ # @param account_id_override [String, nil]
492
+ # @return [Hash] WebhookDispatch recording this attempt
493
+ # @raise [Assinafy::ValidationError] on an invalid endpoint or account ID
494
+ # @raise [Assinafy::ApiError] on failure, including 404 and 429
495
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
496
+ # @see POST /accounts/{accountId}/webhooks/endpoints/{endpointId}/test
497
+ # @example Send a test delivery
498
+ # client.webhooks.test_endpoint('endpoint-id')
499
+ # # Request: POST /accounts/{accountId}/webhooks/endpoints/endpoint-id/test (no body)
500
+ # # => { 'resource' => 'activity_dispatching_history', 'id' => 'dispatch-id',
501
+ # # 'event' => 'webhook_test', 'activity_id' => 123, 'endpoint_id' => 'endpoint-id',
502
+ # # 'endpoint' => 'https://example.com/webhook', 'delivered' => true,
503
+ # # 'payload' => { 'event' => 'webhook_test', 'account_id' => 'account-id',
504
+ # # 'payload' => nil, 'origin' => nil,
505
+ # # 'subject' => { 'id' => 'endpoint-id' }, 'object' => { 'id' => 'endpoint-id' } },
506
+ # # 'webhook_id' => 'webhook-id', 'attempt' => 1, 'kind' => 'manual',
507
+ # # 'will_retry' => false, 'duration_ms' => 184, 'http_status' => 200,
508
+ # # 'response_body' => 'OK', 'error' => nil,
509
+ # # 'created_at' => '2026-11-04T12:05:00Z', 'updated_at' => '2026-11-04T12:05:00Z' }
510
+ def test_endpoint(endpoint_id, account_id_override = nil)
511
+ path = endpoint_path(endpoint_id, account_id_override)
512
+ call('Failed to send webhook test') { http_post("#{path}/test") }
513
+ end
514
+
483
515
  private
484
516
 
485
517
  def endpoint_path(endpoint_id, account_id_override)
@@ -12,6 +12,23 @@ module Assinafy
12
12
  EMAIL_PATTERN = /\A[^\s@]+@[^\s@]+\.[^\s@]+\z/
13
13
 
14
14
  class << self
15
+ # Validate a spending ceiling without changing the caller's numeric representation.
16
+ # @param value [Numeric, String, nil] a finite, nonnegative number of credits
17
+ # @return [Numeric, String, nil] the unchanged value
18
+ # @raise [ValidationError] on invalid credits
19
+ # @example
20
+ # Assinafy::Utils.require_credit_ceiling('1.5') # => '1.5'
21
+ def require_credit_ceiling(value)
22
+ return nil if value.nil?
23
+
24
+ raw = value.to_s.strip if value.is_a?(Numeric) || value.is_a?(String)
25
+ decimal = /\A([+-]?)(\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/.match(raw.to_s)
26
+ return value if decimal && !(decimal[1] == '-' && decimal[2].match?(/[1-9]/)) &&
27
+ Float(raw, exception: false)&.finite?
28
+
29
+ raise ValidationError.new('max_total_credits must be a finite nonnegative number')
30
+ end
31
+
15
32
  # Validate a contact address without exposing it in error metadata.
16
33
  # @param email [String]
17
34
  # @return [String] the unchanged address
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Assinafy
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  USER_AGENT = "Assinafy-Ruby-SDK/v#{VERSION}".freeze
6
6
  end
data/lib/assinafy.rb CHANGED
@@ -21,6 +21,7 @@ require_relative 'assinafy/resources/contract_resource'
21
21
  require_relative 'assinafy/resources/signer_resource'
22
22
  require_relative 'assinafy/resources/signer_document_resource'
23
23
  require_relative 'assinafy/resources/assignment_resource'
24
+ require_relative 'assinafy/resources/envelope_resource'
24
25
  require_relative 'assinafy/resources/webhook_resource'
25
26
  require_relative 'assinafy/resources/template_resource'
26
27
  require_relative 'assinafy/resources/field_resource'