assinafy 2.1.1 → 2.3.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.
@@ -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
 
@@ -142,14 +142,15 @@ module Assinafy
142
142
  # `email` or `whatsapp_phone_number` is rejected while that channel is
143
143
  # verified on an in-flight document; changing an unverified channel rotates
144
144
  # its access and verification codes.
145
+ # Explicit nil or empty String clears email, WhatsApp number or government ID.
145
146
  #
146
147
  # @param signer_id [String]
147
148
  # @param payload [Hash]
148
149
  # @option payload [String] :full_name
149
- # @option payload [String] :email
150
- # @option payload [String] :whatsapp_phone_number E.164; normalized on save
151
- # @option payload [String] :phone alias for `:whatsapp_phone_number`
152
- # @option payload [String] :government_id CPF (digits) or CNPJ (may be alphanumeric); normalized on save
150
+ # @option payload [String, nil] :email
151
+ # @option payload [String, nil] :whatsapp_phone_number E.164; normalized on save
152
+ # @option payload [String, nil] :phone alias for `:whatsapp_phone_number`
153
+ # @option payload [String, nil] :government_id CPF (digits) or CNPJ (may be alphanumeric); normalized on save
153
154
  # @param account_id_override [String, nil]
154
155
  # @return [Hash] updated signer object (envelope `data` unwrapped)
155
156
  # @raise [Assinafy::ApiError] on an unsuccessful API response
@@ -334,7 +335,7 @@ module Assinafy
334
335
  # other signer-authenticated endpoint. This operation has no request body.
335
336
  #
336
337
  # @param signer_access_code [String]
337
- # @return [nil] the documented success envelope has no `data` payload
338
+ # @return [Hash] full_name, email and has_accepted_terms
338
339
  # @raise [Assinafy::ApiError] on an unsuccessful API response
339
340
  # @raise [Assinafy::NetworkError] on transport or TLS failure
340
341
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -345,8 +346,8 @@ module Assinafy
345
346
  # # Request: PUT /signers/accept-terms?signer-access-code=signer-access-code
346
347
  # # Body: none
347
348
  #
348
- # # Response: { "status": 200, "message": "Terms accepted" }
349
- # # => nil
349
+ # # => { "full_name" => "Example Signer", "email" => "signer@example.com",
350
+ # # "has_accepted_terms" => true }
350
351
  def accept_terms(signer_access_code:)
351
352
  code = require_signer_access_code(signer_access_code)
352
353
 
@@ -355,11 +356,11 @@ module Assinafy
355
356
  end
356
357
  end
357
358
 
358
- # Verify the signer's email with a one-time verification code.
359
+ # Verify the signer's Email or Whatsapp one-time code.
359
360
  #
360
361
  # @param verification_code [String]
361
362
  # @param signer_access_code [String]
362
- # @return [nil] the documented success envelope has no `data` payload
363
+ # @return [Array, nil] empty Array; nil for older no-data responses
363
364
  # @raise [Assinafy::ApiError] on an unsuccessful API response
364
365
  # @raise [Assinafy::NetworkError] on transport or TLS failure
365
366
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -373,8 +374,8 @@ module Assinafy
373
374
  # # Request: POST /verify?signer-access-code=signer-access-code
374
375
  # # Body: { "verification-code": "123456" }
375
376
  #
376
- # # Response: { "status": 200, "message": "Code verified successfully" }
377
- # # => nil
377
+ # # Response: { "status": 200, "data": [], "message": "Code verified successfully" }
378
+ # # => []
378
379
  def verify_email(verification_code:, signer_access_code:)
379
380
  verification = require_string(verification_code, 'Verification code')
380
381
  code = require_signer_access_code(signer_access_code)
@@ -389,33 +390,24 @@ module Assinafy
389
390
  end
390
391
  end
391
392
 
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.
393
+ # Confirm the contact used by the assignment and optionally accept terms. Certificate signers
394
+ # must do both before opening GET /sign. Existing additional payload fields are passed through.
395
+ # Only email, whatsapp_phone_number and has_accepted_terms are read by the API.
396
396
  #
397
- # @param document_id [String]
398
- # @param payload [Hash] `:full_name`, `:email`, `:government_id`
397
+ # @param document_id [String]
398
+ # @param payload [Hash] email, whatsapp_phone_number and has_accepted_terms
399
399
  # @param signer_access_code [String]
400
- # @return [Hash] the updated signer object (envelope `data` unwrapped)
400
+ # @return [Array] empty Array on success
401
401
  # @raise [Assinafy::ApiError] on an unsuccessful API response
402
402
  # @raise [Assinafy::NetworkError] on transport or TLS failure
403
403
  # @raise [Assinafy::ValidationError] on invalid required input
404
404
  # @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
- # # }
405
+ # @example Confirm contact and terms using only the signer access code
406
+ # client.signers.confirm_data('document-id',
407
+ # { email: 'signer@example.com', has_accepted_terms: true }, signer_access_code: 'access-code')
408
+ # # PUT /documents/document-id/signers/confirm-data?signer-access-code=access-code
409
+ # # Body: { 'email' => 'signer@example.com', 'has_accepted_terms' => true }
410
+ # # => []
419
411
  def confirm_data(document_id, payload, signer_access_code:)
420
412
  doc_id = require_id(document_id, 'Document ID')
421
413
  body = body_params(require_payload(payload))
@@ -423,6 +415,8 @@ module Assinafy
423
415
  require_string(body['full_name'], 'Full name') if body.key?('full_name')
424
416
  Utils.require_email(body['email']) if body.key?('email')
425
417
  require_string(body['government_id'], 'Government ID') if body.key?('government_id')
418
+ require_string(body['whatsapp_phone_number'], 'WhatsApp number') if body.key?('whatsapp_phone_number')
419
+ require_boolean(body['has_accepted_terms'], 'has_accepted_terms') if body.key?('has_accepted_terms')
426
420
 
427
421
  call('Failed to confirm signer data') do
428
422
  http_put("documents/#{doc_id}/signers/confirm-data", body,
@@ -438,8 +432,7 @@ module Assinafy
438
432
  # @param content_type [String] must be `image/png`
439
433
  # @param reuse [Boolean, nil] when true, marks the signature as
440
434
  # reusable for future documents (documented `reuse` query flag)
441
- # @return [nil, Array] `nil` for the OpenAPI's no-data envelope; some deployed
442
- # versions return `data: []`, which the SDK passes through as an empty Array
435
+ # @return [Array, nil] empty Array; nil for older no-data responses
443
436
  # @raise [Assinafy::ApiError] on an unsuccessful API response
444
437
  # @raise [Assinafy::NetworkError] on transport or TLS failure
445
438
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -456,8 +449,7 @@ module Assinafy
456
449
  # # The SDK sends the RAW image bytes as the body, with
457
450
  # # Content-Type: image/png and ?signer-access-code=...&type=signature query params.
458
451
  #
459
- # # => nil # documented no-data envelope
460
- # # => [] # when a deployed API version returns data: []
452
+ # # => []
461
453
  def upload_signature(content, signer_access_code:, type: 'signature', content_type: 'image/png', reuse: nil)
462
454
  unless content.is_a?(String) && !content.empty?
463
455
  raise ValidationError.new('Signature content must be a non-empty String')
@@ -511,6 +503,47 @@ module Assinafy
511
503
  end
512
504
  end
513
505
 
506
+ # Read the signing workspace's brand using the signer's access code.
507
+ #
508
+ # @param signer_access_code [String]
509
+ # @return [Hash] account_name, primary_color, secondary_color and nullable logo URL
510
+ # @raise [Assinafy::ValidationError] on an invalid access code
511
+ # @raise [Assinafy::ApiError] on an unsuccessful API response
512
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
513
+ # @see GET /sign/theme
514
+ # @example Read branding (no body, no workspace credentials)
515
+ # client.signers.theme(signer_access_code: 'access-code')
516
+ # # GET /sign/theme?signer-access-code=access-code
517
+ # # => { 'account_name' => 'Example Workspace', 'primary_color' => 'aabbcc',
518
+ # # 'secondary_color' => 'ffffff', 'logo' => 'https://api.assinafy.com.br/v1/sign/logo' }
519
+ def theme(signer_access_code:)
520
+ code = require_signer_access_code(signer_access_code)
521
+
522
+ call('Failed to read signing theme') do
523
+ http_get('sign/theme', { signer_access_code: code }, workspace_auth: false)
524
+ end
525
+ end
526
+
527
+ # Download the signing workspace's logo with signer-only authentication.
528
+ #
529
+ # @param signer_access_code [String]
530
+ # @return [String] binary image bytes
531
+ # @raise [Assinafy::ValidationError] on an invalid access code
532
+ # @raise [Assinafy::ApiError] on an unsuccessful API response, including 404 without a logo
533
+ # @raise [Assinafy::NetworkError] on transport or TLS failure
534
+ # @see GET /sign/logo
535
+ # @example Download branding (no request body)
536
+ # client.signers.download_logo(signer_access_code: 'access-code')
537
+ # # GET /sign/logo?signer-access-code=access-code
538
+ # # => "PNG image bytes" # binary String
539
+ def download_logo(signer_access_code:)
540
+ code = require_signer_access_code(signer_access_code)
541
+
542
+ call_binary('Failed to download signing logo') do
543
+ http_get('sign/logo', { signer_access_code: code }, workspace_auth: false)
544
+ end
545
+ end
546
+
514
547
  private
515
548
 
516
549
  def assert_email!(email)
@@ -524,7 +557,7 @@ module Assinafy
524
557
  full_name = signer_full_name(p, require_full_name)
525
558
 
526
559
  email = p['email']
527
- assert_email!(email) unless email.nil?
560
+ assert_email!(email) unless email.nil? || (!require_full_name && email == '')
528
561
 
529
562
  phone = signer_phone(p)
530
563
 
@@ -535,6 +568,15 @@ module Assinafy
535
568
  )
536
569
  government_id = signer_government_id(p)
537
570
  body['government_id'] = government_id unless government_id.nil?
571
+ require_full_name ? body : signer_update_payload(p, body)
572
+ end
573
+
574
+ def signer_update_payload(p, body)
575
+ p['whatsapp_phone_number'] = p['phone'] if !p.key?('whatsapp_phone_number') && p.key?('phone')
576
+ %w[email whatsapp_phone_number government_id].each do |key|
577
+ body[key] = nil if p.key?(key) && p[key].nil?
578
+ end
579
+ require_string(body['full_name'], 'Full name') if p.key?('full_name') || p.key?('name')
538
580
  body
539
581
  end
540
582
 
@@ -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
@@ -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.1'
4
+ VERSION = '2.3.0'
5
5
  USER_AGENT = "Assinafy-Ruby-SDK/v#{VERSION}".freeze
6
6
  end
data/lib/assinafy.rb CHANGED
@@ -21,6 +21,8 @@ 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'
25
+ require_relative 'assinafy/resources/scheduled_send_resource'
24
26
  require_relative 'assinafy/resources/webhook_resource'
25
27
  require_relative 'assinafy/resources/template_resource'
26
28
  require_relative 'assinafy/resources/field_resource'