assinafy 2.3.0 → 2.4.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.
@@ -22,8 +22,12 @@ module Assinafy
22
22
  # `update` alias). Accounts with several endpoints should use
23
23
  # {#create_endpoint} / {#update_endpoint}.
24
24
  #
25
+ # `is_active` defaults to `true`, so a call that leaves it out reactivates an inactive endpoint
26
+ # and lifts a pause. The `url` is always required and must be HTTPS; to change the events of an
27
+ # older endpoint registered over HTTP, use {#update_endpoint}.
28
+ #
25
29
  # @param payload [Hash]
26
- # @option payload [String] :url endpoint that will receive events
30
+ # @option payload [String] :url HTTPS endpoint that will receive events
27
31
  # @option payload [String] :email contact email for delivery health
28
32
  # @option payload [Array<String>] :events event-type IDs (see {#list_event_types})
29
33
  # @option payload [Boolean] :is_active default `true` when omitted
@@ -71,11 +75,11 @@ module Assinafy
71
75
 
72
76
  alias update register
73
77
 
74
- # Fetch the account's oldest webhook endpoint. Returns `nil` on 404
75
- # (no endpoint configured yet).
78
+ # Fetch the account's oldest webhook endpoint. An account with nothing configured answers 200
79
+ # with `url`, `email` and `updated_at` set to nil.
76
80
  #
77
81
  # @param account_id_override [String, nil]
78
- # @return [Hash, nil] subscription object, or `nil` when none is configured (404)
82
+ # @return [Hash, nil] subscription object; `nil` only if the API answers 404
79
83
  # @raise [Assinafy::ApiError] on an unsuccessful API response
80
84
  # @raise [Assinafy::NetworkError] on transport or TLS failure
81
85
  # @raise [Assinafy::ValidationError] on invalid required input
@@ -83,7 +87,7 @@ module Assinafy
83
87
  # @example Fetch the current subscription
84
88
  # client.webhooks.get
85
89
  # # GET /accounts/{account_id}/webhooks/subscriptions
86
- # # => unwrapped data payload returned (nil if no subscription exists):
90
+ # # => unwrapped data payload returned:
87
91
  # # {
88
92
  # # 'events' => ["document_ready", "signer_signed_document"],
89
93
  # # 'is_active' => false,
@@ -93,6 +97,9 @@ module Assinafy
93
97
  # # 'email' => "webhook@example.com",
94
98
  # # 'updated_at' => "2026-06-05T21:13:24Z"
95
99
  # # }
100
+ # # With nothing configured:
101
+ # # { 'events' => [], 'is_active' => false, 'is_held' => false, 'held_since' => nil,
102
+ # # 'url' => nil, 'email' => nil, 'updated_at' => nil }
96
103
  def get(account_id_override = nil)
97
104
  acc_id = account_id(account_id_override)
98
105
 
@@ -146,14 +153,11 @@ module Assinafy
146
153
  # # GET /webhooks/event-types
147
154
  # # => unwrapped data payload returned:
148
155
  # # [
149
- # # { 'id' => "document_uploaded", 'description' => "Document uploaded" },
150
- # # { 'id' => "document_metadata_ready", 'description' => "Document metadata ready" },
151
- # # { 'id' => "document_prepared", 'description' => "Document prepared" },
152
- # # { 'id' => "assignment_created", 'description' => "Assignment created" },
153
- # # { 'id' => "signature_requested", 'description' => "Signature requested" },
154
- # # { 'id' => "document_ready", 'description' => "All signers signed" },
155
- # # { 'id' => "signer_created", 'description' => "Signer created" },
156
- # # { 'id' => "signer_email_verified", 'description' => "Signer email verified" }
156
+ # # { 'id' => "document_uploaded", 'description' => "Triggered when a document is uploaded." },
157
+ # # { 'id' => "signature_requested", 'description' => "Triggered when a signature is requested." },
158
+ # # { 'id' => "signer_signed_document", 'description' => "Triggered when a signer signs a document." },
159
+ # # { 'id' => "document_ready",
160
+ # # 'description' => "Triggered when a document is certificated, after all signers have signed." }
157
161
  # # # ... (read list_event_types for the complete current catalogue)
158
162
  # # ]
159
163
  def list_event_types
@@ -173,27 +177,30 @@ module Assinafy
173
177
  # @raise [Assinafy::ValidationError] on invalid required input
174
178
  # @see GET /accounts/{account_id}/webhooks
175
179
  # @example List delivery attempts, filtered to undelivered
176
- # client.webhooks.list_dispatches(delivered: false, 'per-page': 20)
180
+ # client.webhooks.list_dispatches(delivered: false, per_page: 20)
177
181
  # # GET /accounts/{account_id}/webhooks?delivered=false&per-page=20
178
182
  # # => unwrapped data payload returned (pagination from x-pagination-* headers):
179
183
  # # {
180
184
  # # data: [
181
185
  # # {
182
- # # 'id' => "dispatch-id",
183
- # # event: "signature_requested",
184
- # # activity_id: 15431,
185
- # # endpoint: "https://example.com/webhook",
186
- # # payload: { 'id' => 15431, event: "signature_requested", object: {}, subject: {}, payload: {} },
187
- # # delivered: false,
188
- # # webhook_id: "webhook-id-placeholder",
189
- # # attempt: 2,
190
- # # kind: "scheduled",
191
- # # will_retry: false,
192
- # # http_status: 404,
193
- # # response_body: "{\"success\":false,...}",
194
- # # error: "Client error: `POST https://example.com/webhook` resulted in a 404 ...",
195
- # # 'created_at' => "2026-07-20T15:57:38Z",
196
- # # 'updated_at' => "2026-07-20T15:57:38Z"
186
+ # # 'id' => "dispatch-id",
187
+ # # 'event' => "signature_requested",
188
+ # # 'activity_id' => 15431,
189
+ # # 'endpoint_id' => "webhook-endpoint-id",
190
+ # # 'endpoint' => "https://example.com/webhook",
191
+ # # 'payload' => { 'id' => 15431, 'event' => "signature_requested", 'object' => {},
192
+ # # 'subject' => {}, 'payload' => {} },
193
+ # # 'delivered' => false,
194
+ # # 'webhook_id' => "webhook-id-placeholder",
195
+ # # 'attempt' => 2,
196
+ # # 'kind' => "scheduled",
197
+ # # 'will_retry' => false,
198
+ # # 'duration_ms' => 184,
199
+ # # 'http_status' => 404,
200
+ # # 'response_body' => "{\"success\":false,...}",
201
+ # # 'error' => "Client error: `POST https://example.com/webhook` resulted in a 404 ...",
202
+ # # 'created_at' => "2026-07-20T15:57:38Z",
203
+ # # 'updated_at' => "2026-07-20T15:57:38Z"
197
204
  # # }
198
205
  # # # ... (see docs for full dispatch shape)
199
206
  # # ],
@@ -221,22 +228,24 @@ module Assinafy
221
228
  # # POST /accounts/{account_id}/webhooks/dispatch-id/retry (no request body)
222
229
  # # => unwrapped data payload returned:
223
230
  # # {
224
- # # resource: "activity_dispatching_history",
225
- # # 'id' => "dispatch-id",
226
- # # event: "signature_requested",
227
- # # activity_id: 15431,
228
- # # endpoint: "https://example.com/webhook",
229
- # # payload: { 'id' => 15431, event: "signature_requested", object: {}, subject: {} },
230
- # # delivered: true,
231
- # # webhook_id: "webhook-id-placeholder",
232
- # # attempt: 1,
233
- # # kind: "manual",
234
- # # will_retry: false,
235
- # # http_status: 200,
236
- # # response_body: "OK",
237
- # # error: nil,
238
- # # 'created_at' => "2026-07-20T15:57:38Z",
239
- # # 'updated_at' => "2026-07-20T15:57:39Z"
231
+ # # 'resource' => "activity_dispatching_history",
232
+ # # 'id' => "dispatch-id",
233
+ # # 'event' => "signature_requested",
234
+ # # 'activity_id' => 15431,
235
+ # # 'endpoint_id' => "webhook-endpoint-id",
236
+ # # 'endpoint' => "https://example.com/webhook",
237
+ # # 'payload' => { 'id' => 15431, 'event' => "signature_requested", 'object' => {}, 'subject' => {} },
238
+ # # 'delivered' => true,
239
+ # # 'webhook_id' => "webhook-id-placeholder",
240
+ # # 'attempt' => 1,
241
+ # # 'kind' => "manual",
242
+ # # 'will_retry' => false,
243
+ # # 'duration_ms' => 184,
244
+ # # 'http_status' => 200,
245
+ # # 'response_body' => "OK",
246
+ # # 'error' => nil,
247
+ # # 'created_at' => "2026-07-20T15:57:38Z",
248
+ # # 'updated_at' => "2026-07-20T15:57:39Z"
240
249
  # # }
241
250
  def retry_dispatch(dispatch_id, account_id_override = nil)
242
251
  acc_id = account_id(account_id_override)
@@ -522,8 +531,7 @@ module Assinafy
522
531
  def webhook_body(payload, allowed, required)
523
532
  body = require_payload(payload, 'Webhook payload').transform_keys(&:to_sym)
524
533
 
525
- unknown = body.keys - allowed
526
- raise ValidationError.new("Unknown webhook fields: #{unknown.join(', ')}") unless unknown.empty?
534
+ reject_unknown_keys!(body, allowed, 'webhook fields')
527
535
 
528
536
  missing = required - body.keys
529
537
  raise ValidationError.new("Missing webhook fields: #{missing.join(', ')}") unless missing.empty?
@@ -79,7 +79,7 @@ module Assinafy
79
79
  return false unless secret && !secret.empty?
80
80
  return false unless signature && !signature.to_s.strip.empty?
81
81
 
82
- body = payload.is_a?(String) ? payload : payload.to_s
82
+ body = payload.to_s
83
83
  expected = OpenSSL::HMAC.hexdigest('SHA256', secret, body)
84
84
  provided = signature.to_s.strip
85
85
 
@@ -94,7 +94,7 @@ module Assinafy
94
94
  # @param payload [String]
95
95
  # @return [Hash, nil]
96
96
  def extract_event(payload)
97
- text = payload.is_a?(String) ? payload : payload.to_s
97
+ text = payload.to_s
98
98
  parsed = JSON.parse(text)
99
99
  parsed.is_a?(Hash) ? parsed : nil
100
100
  rescue JSON::ParserError
@@ -10,6 +10,16 @@ module Assinafy
10
10
  module Utils
11
11
  MAX_NORMALIZATION_DEPTH = 100
12
12
  EMAIL_PATTERN = /\A[^\s@]+@[^\s@]+\.[^\s@]+\z/
13
+ QUERY_KEY_MAP = {
14
+ 'access_token' => 'access-token',
15
+ 'per_page' => 'per-page',
16
+ 'signer_access_code' => 'signer-access-code'
17
+ }.freeze
18
+ BODY_KEY_MAP = {
19
+ 'signer_access_code' => 'signer-access-code',
20
+ 'verification_code' => 'verification-code'
21
+ }.freeze
22
+ private_constant :QUERY_KEY_MAP, :BODY_KEY_MAP
13
23
 
14
24
  class << self
15
25
  # Validate a spending ceiling without changing the caller's numeric representation.
@@ -52,9 +62,7 @@ module Assinafy
52
62
  return nil if value.nil?
53
63
  raise ValidationError.new('expires_at must be a String') unless value.is_a?(String)
54
64
 
55
- unless value.match?(/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?
56
- (?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)\z/x) &&
57
- DateTime.iso8601(value).to_time >= Time.now + 3600
65
+ unless value.match?(Validation::ZONED_ISO8601) && DateTime.iso8601(value).to_time >= Time.now + 3600
58
66
  raise ValidationError.new('expires_at must be an ISO 8601 timestamp at least one hour in the future')
59
67
  end
60
68
 
@@ -97,13 +105,13 @@ module Assinafy
97
105
  end
98
106
 
99
107
  # Build a query-string Hash, translating the Ruby-friendly snake_case
100
- # aliases in {query_key_map} to the hyphenated forms documented in the
108
+ # aliases (`per_page`, `access_token`, `signer_access_code`) to the hyphenated forms documented in the
101
109
  # Assinafy API (e.g. `per_page` → `per-page`).
102
110
  #
103
111
  # @param hash [Hash, nil]
104
112
  # @return [Hash{String=>Object}]
105
113
  def query_params(hash)
106
- normalize_keys(clean_params(hash), query_key_map)
114
+ normalize_keys(clean_params(hash), QUERY_KEY_MAP)
107
115
  end
108
116
 
109
117
  # Build a body Hash, translating documented hyphenated body keys
@@ -113,7 +121,7 @@ module Assinafy
113
121
  # @param hash [Hash, nil]
114
122
  # @return [Hash{String=>Object}]
115
123
  def body_params(hash)
116
- normalize_keys(clean_params(hash), body_key_map)
124
+ normalize_keys(clean_params(hash), BODY_KEY_MAP)
117
125
  end
118
126
 
119
127
  private
@@ -157,21 +165,6 @@ module Assinafy
157
165
  raw = key.to_s
158
166
  key_map.fetch(raw, raw)
159
167
  end
160
-
161
- def query_key_map
162
- {
163
- 'access_token' => 'access-token',
164
- 'per_page' => 'per-page',
165
- 'signer_access_code' => 'signer-access-code'
166
- }
167
- end
168
-
169
- def body_key_map
170
- {
171
- 'signer_access_code' => 'signer-access-code',
172
- 'verification_code' => 'verification-code'
173
- }
174
- end
175
168
  end
176
169
  end
177
170
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Assinafy
4
+ # Stateless argument checks shared by resources, class-level payload builders,
5
+ # the client and the OAuth helpers.
6
+ #
7
+ # @api private
8
+ module Validation
9
+ PATH_SEGMENT = /\A[A-Za-z0-9._~-]+\z/
10
+ ZONED_ISO8601 = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)\z/
11
+
12
+ module_function
13
+
14
+ def require_present(value, name)
15
+ return value unless value.nil? || value.to_s.strip.empty?
16
+
17
+ raise ValidationError.new("#{name} is required")
18
+ end
19
+
20
+ # A value is interpolated into a request path only when this holds, which
21
+ # keeps `.`, `..` and separators from changing the route.
22
+ def path_segment?(value)
23
+ value.is_a?(String) && PATH_SEGMENT.match?(value) && value != '.' && value != '..'
24
+ end
25
+
26
+ def require_id(value, name)
27
+ id = require_string(value, name)
28
+ return id if path_segment?(id)
29
+
30
+ raise ValidationError.new("#{name} contains invalid characters")
31
+ end
32
+
33
+ def require_string(value, name, max_length: nil)
34
+ string = require_present(value, name)
35
+ raise ValidationError.new("#{name} must be a String") unless string.is_a?(String)
36
+ if max_length && string.length > max_length
37
+ raise ValidationError.new("#{name} must be at most #{max_length} characters")
38
+ end
39
+
40
+ string
41
+ end
42
+
43
+ def require_boolean(value, name)
44
+ return value if [true, false].include?(value)
45
+
46
+ raise ValidationError.new("#{name} must be true or false")
47
+ end
48
+
49
+ def require_payload(payload, name = 'Payload')
50
+ raise ValidationError.new("#{name} must be a Hash") unless payload.is_a?(Hash)
51
+
52
+ payload
53
+ end
54
+
55
+ def require_array(value, name)
56
+ return value if value.is_a?(Array) && !value.empty?
57
+
58
+ raise ValidationError.new("#{name} must be a non-empty Array")
59
+ end
60
+
61
+ def require_one_of(value, allowed, name)
62
+ return value if allowed.include?(value)
63
+
64
+ raise ValidationError.new("#{name} must be one of: #{allowed.join(', ')}")
65
+ end
66
+
67
+ def require_integer(value, name, minimum, maximum = nil)
68
+ return value if value.is_a?(Integer) && value >= minimum && (maximum.nil? || value <= maximum)
69
+
70
+ range = maximum ? "between #{minimum} and #{maximum}" : "at least #{minimum}"
71
+ raise ValidationError.new("#{name} must be an Integer #{range}")
72
+ end
73
+
74
+ def reject_unknown_keys!(hash, allowed, name)
75
+ unknown = hash.keys - allowed
76
+ raise ValidationError.new("Unknown #{name}: #{unknown.join(', ')}") unless unknown.empty?
77
+ end
78
+ end
79
+ private_constant :Validation
80
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Assinafy
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
5
5
  USER_AGENT = "Assinafy-Ruby-SDK/v#{VERSION}".freeze
6
6
  end
data/lib/assinafy.rb CHANGED
@@ -7,12 +7,12 @@ require 'stringio'
7
7
 
8
8
  require_relative 'assinafy/version'
9
9
  require_relative 'assinafy/errors'
10
+ require_relative 'assinafy/validation'
10
11
  require_relative 'assinafy/null_logger'
11
12
  require_relative 'assinafy/configuration'
12
13
  require_relative 'assinafy/utils'
13
14
  require_relative 'assinafy/oauth'
14
15
  require_relative 'assinafy/resources/base_resource'
15
- require_relative 'assinafy/resources/auth_resource'
16
16
  require_relative 'assinafy/resources/oauth_resource'
17
17
  require_relative 'assinafy/resources/account_resource'
18
18
  require_relative 'assinafy/resources/user_resource'
data/sig/assinafy.rbs CHANGED
@@ -138,7 +138,7 @@ module Assinafy
138
138
  redirect_uri: String,
139
139
  ?code_verifier: String?,
140
140
  ?code_challenge: String?,
141
- ?scope: Array[String] | String | nil,
141
+ scope: Array[String] | String,
142
142
  ?state: String?,
143
143
  ?resource: String?,
144
144
  ?authorization_endpoint: String,
@@ -158,30 +158,6 @@ module Assinafy
158
158
  def initialize: (untyped connection, ?String? default_account_id, ?_Logger? logger) -> void
159
159
  end
160
160
 
161
- class AuthResource < BaseResource
162
- def login: (email: String, password: String) -> api_object
163
- def social_login: (provider: String, token: String, has_accepted_terms: bool) -> api_object
164
- def link_social_login: (provider: String, token: String) -> nil
165
- def create_api_key: (password: String) -> api_object
166
- def get_api_key: () -> api_object?
167
- def api_key: () -> api_object?
168
- def delete_api_key: () -> nil
169
- def change_password: (email: String, password: String, new_password: String) -> api_object
170
- def request_password_reset: (email: String) -> api_object
171
- def reset_password: (email: String, new_password: String, ?token: String?) -> api_object
172
- def verify_mfa: (mfa_token: String, code: String) -> api_object
173
- def mfa_methods: () -> api_object
174
- def start_totp_enrollment: (?label: String?) -> api_object
175
- def confirm_totp_enrollment: (
176
- method_id: String,
177
- code: String,
178
- ?password: String?,
179
- ?reauth_code: String?
180
- ) -> api_object
181
- def regenerate_recovery_codes: (?password: String?, ?code: String?) -> api_object
182
- def delete_mfa_method: (String method_id, ?password: String?, ?code: String?) -> api_object
183
- end
184
-
185
161
  class OAuthResource < BaseResource
186
162
  GRANT_TYPES: Array[String]
187
163
  TOKEN_TYPE_HINTS: Array[String]
@@ -210,7 +186,7 @@ module Assinafy
210
186
  ) -> nil
211
187
  def userinfo: () -> api_object
212
188
  def protected_resource_metadata: () -> api_object
213
- def authorization_server_metadata: (?String url) -> api_object
189
+ def authorization_server_metadata: (?String? url) -> api_object
214
190
  end
215
191
 
216
192
  class AccountResource < BaseResource
@@ -268,6 +244,7 @@ module Assinafy
268
244
  def activities: (String document_id, ?params params) -> Array[api_object]
269
245
  def activities_page: (String document_id, ?params params) -> list_result
270
246
  def delete: (String document_id) -> nil
247
+ def cancel: (String document_id) -> api_object
271
248
  def create_from_template: (
272
249
  String template_id,
273
250
  Array[params] | params signers_or_payload,
@@ -357,7 +334,7 @@ module Assinafy
357
334
  def start_identity_verification: (consent: bool, signer_access_code: String) -> api_object
358
335
  def accept_terms: (signer_access_code: String) -> api_object?
359
336
  def verify_email: (verification_code: String, signer_access_code: String) -> Array[untyped]?
360
- def confirm_data: (String document_id, params payload, signer_access_code: String) -> Array[untyped]
337
+ def confirm_data: (String document_id, params payload, signer_access_code: String) -> Array[untyped]?
361
338
  def upload_signature: (
362
339
  String content,
363
340
  signer_access_code: String,
@@ -390,7 +367,7 @@ module Assinafy
390
367
  String signer_id,
391
368
  String document_id,
392
369
  ?String artifact_name,
393
- ?signer_access_code: String?
370
+ signer_access_code: String
394
371
  ) -> String
395
372
  end
396
373
 
@@ -513,7 +490,6 @@ module Assinafy
513
490
  end
514
491
 
515
492
  class Client
516
- attr_reader auth: Resources::AuthResource
517
493
  attr_reader oauth: Resources::OAuthResource
518
494
  attr_reader accounts: Resources::AccountResource
519
495
  attr_reader users: Resources::UserResource
@@ -550,7 +526,8 @@ module Assinafy
550
526
  ?wait_for_ready: bool,
551
527
  ?expires_at: String?,
552
528
  ?copy_receivers: Array[String]?,
553
- ?account_id: String?
529
+ ?account_id: String?,
530
+ ?max_total_credits: Numeric | String | nil
554
531
  ) -> workflow_result
555
532
  def faraday_connection: () -> untyped
556
533
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assinafy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assinafy SDK Contributors
@@ -133,10 +133,9 @@ dependencies:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
135
  version: '3.0'
136
- description: Ruby SDK for Assinafy. Covers the documented authentication, OAuth 2.1,
137
- account, user, document, envelope, contract, signer, assignment, scheduled-send,
138
- webhook, template, tag, and field APIs, plus the high-level upload_and_request_signatures
139
- helper.
136
+ description: Ruby SDK for Assinafy. Covers the documented OAuth 2.1, account, user,
137
+ document, envelope, contract, signer, assignment, scheduled-send, webhook, template,
138
+ tag, and field APIs, plus the high-level upload_and_request_signatures helper.
140
139
  email:
141
140
  - sdk@assinafy.com.br
142
141
  executables: []
@@ -148,6 +147,7 @@ files:
148
147
  - README.en.md
149
148
  - README.md
150
149
  - docs/API_REFERENCE.md
150
+ - docs/GUIDE.md
151
151
  - lib/assinafy.rb
152
152
  - lib/assinafy/client.rb
153
153
  - lib/assinafy/configuration.rb
@@ -156,7 +156,6 @@ files:
156
156
  - lib/assinafy/oauth.rb
157
157
  - lib/assinafy/resources/account_resource.rb
158
158
  - lib/assinafy/resources/assignment_resource.rb
159
- - lib/assinafy/resources/auth_resource.rb
160
159
  - lib/assinafy/resources/base_resource.rb
161
160
  - lib/assinafy/resources/contract_resource.rb
162
161
  - lib/assinafy/resources/document_resource.rb
@@ -172,6 +171,7 @@ files:
172
171
  - lib/assinafy/resources/webhook_resource.rb
173
172
  - lib/assinafy/support/webhook_verifier.rb
174
173
  - lib/assinafy/utils.rb
174
+ - lib/assinafy/validation.rb
175
175
  - lib/assinafy/version.rb
176
176
  - sig/assinafy.rbs
177
177
  homepage: https://www.assinafy.com.br