datadome_fraud_sdk_ruby 2.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fff528a204778f50d85c8eccd4c202a66d94a24109f994cfc5cd3a64c53d0bdb
4
- data.tar.gz: 49bd243556c8c8b756d7f738cb9cf969f1c080a0d960dc208970d0c29509ee13
3
+ metadata.gz: af46bd76291b91fa6eed5fd45415a7661783391ff657e6d202a9da6a006ee662
4
+ data.tar.gz: d3437a3c2e3f4a51bc44a3e4337454910281edccc5e4c05b9382feddbe3416d1
5
5
  SHA512:
6
- metadata.gz: c6030c2e8c3ccca6d88b60ff5814795d45f0313f613103fdc987d46ca5cd376557aa1a44c75e1f9361e076a38dcd164166ee27b375c2db20bcdf63b4a7c969d2
7
- data.tar.gz: 565a4385c6367b9d5a0f6e46d9cc4cd1c651083262e02fe521b3a9a88eca0fa94819880ed59f44765892fe1fb3cfabb7272336ead08e96c8dc2d3e0c9cd00ebb
6
+ metadata.gz: 9ffdf60d53ae616ade9ce9dace737b6df6e1a4a54ec198514dbd1a305ad4575232fbae7e9e58a847888b277b5da81bcce7a1d9495536558bac1a6d9fde0e8044
7
+ data.tar.gz: c33e5e9069a1d693a87b5fb8278e852d49ae87cb7ee013c77faf6634f0451e950fb9c4b627389b9d176fff8a77d494358d9a68e0bb5e9581ba9a4801da407f3d
data/lib/constants.rb CHANGED
@@ -1,2 +1,2 @@
1
- SDK_VERSION = '2.1.0'
1
+ SDK_VERSION = '2.3.0'
2
2
  SDK_NAME = 'datadome_fraud_sdk_ruby'
@@ -6,6 +6,7 @@ require_relative "model/events"
6
6
  require_relative "model/location"
7
7
  require_relative "model/user"
8
8
  require_relative "model/session"
9
+ require_relative "model/authentication"
9
10
  require_relative "model/operation"
10
11
  require_relative "model/api/request"
11
12
  require_relative "model/api/response"
@@ -20,7 +21,7 @@ class DataDome
20
21
  end
21
22
 
22
23
  def validate(request:, event:)
23
- if event.status == DataDomeStatusType::UNDEFINED
24
+ if event.respond_to?(:status) && event.status == DataDomeStatusType::UNDEFINED
24
25
  event.status = DataDomeStatusType::SUCCEEDED
25
26
  end
26
27
 
@@ -33,29 +34,34 @@ class DataDome
33
34
  body = JSON.parse(api_response.body) unless api_response.body.nil?
34
35
  rescue JSON::ParserError => e
35
36
  @logger.error("DataDome: error parsing JSON from Fraud API /validate #{e.message}")
36
- return DataDomeResponseError.new(DataDomeResponseAction::ALLOW, DataDomeResponseStatus::FAILURE, "DataDome: error parsing JSON from Fraud API", e.message)
37
+ return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome: error parsing JSON from Fraud API", errors: e.message)
37
38
  end
38
39
 
39
40
  if api_response.success?
40
- datadome_response = DataDomeResponseSuccess.new(DataDomeResponseAction::ALLOW, body["score"], DataDomeResponseStatus::OK, body["reasons"], body["ip"], DataDomeLocation.new(location: body["location"]))
41
+ datadome_response = DataDomeResponseSuccess.new(status:DataDomeResponseStatus::OK, score:body["score"],
42
+ event_id:body["eventId"]&.to_s, reasons: body["reasons"], ip: body["ip"], location: DataDomeLocation.new(location: body["location"]))
41
43
  if body["action"] === DataDomeResponseAction::DENY
42
44
  datadome_response.action = DataDomeResponseAction::DENY
45
+ elsif body["action"] === DataDomeResponseAction::REVIEW
46
+ datadome_response.action = DataDomeResponseAction::REVIEW
47
+ elsif body["action"] === DataDomeResponseAction::CHALLENGE
48
+ datadome_response.action = DataDomeResponseAction::CHALLENGE
43
49
  end
44
50
  else
45
51
  @logger.error("DataDome: error on Fraud API /validate response #{body["errors"]}")
46
- return DataDomeResponseError.new(DataDomeResponseAction::ALLOW, DataDomeResponseStatus::FAILURE, body["message"], body["errors"].map { |error| DataDomeError.new(error) })
52
+ return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: body["message"], errors: body["errors"].map { |error| DataDomeError.new(error) })
47
53
  end
48
54
  rescue Faraday::TimeoutError => e
49
- return DataDomeResponseError.new(DataDomeResponseAction::ALLOW, DataDomeResponseStatus::TIMEOUT, "DataDome Fraud API request timeout", e.message)
55
+ return DataDomeResponseError.new(status: DataDomeResponseStatus::TIMEOUT, message: "DataDome Fraud API request timeout", errors: e.message)
50
56
  rescue Faraday::ConnectionFailed => e
51
- return DataDomeResponseError.new(DataDomeResponseAction::ALLOW, DataDomeResponseStatus::FAILURE, "DataDome Fraud API request failed", e.message)
57
+ return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome Fraud API request failed", errors: e.message)
52
58
  end
53
59
 
54
60
  datadome_response
55
61
  end
56
62
 
57
63
  def collect(request:, event:)
58
- if event.status == DataDomeStatusType::UNDEFINED
64
+ if event.respond_to?(:status) && event.status == DataDomeStatusType::UNDEFINED
59
65
  event.status = DataDomeStatusType::FAILED
60
66
  end
61
67
 
@@ -65,21 +71,21 @@ class DataDome
65
71
  api_response = send_request(DataDomeOperationType::COLLECT, event.action, payload)
66
72
 
67
73
  if api_response.success?
68
- datadome_response = DataDomeResponseSuccess.new(nil, nil, DataDomeResponseStatus::OK, nil, nil, nil)
74
+ datadome_response = DataDomeResponseSuccess.new(status: DataDomeResponseStatus::OK)
69
75
  else
70
76
  begin
71
77
  body = JSON.parse(api_response.body)
72
78
  @logger.error("DataDome: error on Fraud API /collect response #{body["errors"]}")
73
- datadome_response = DataDomeResponseError.new(nil, DataDomeResponseStatus::FAILURE, body["message"], body["errors"].map { |error| DataDomeError.new(error) })
79
+ datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: body["message"], errors: body["errors"].map { |error| DataDomeError.new(error) })
74
80
  rescue JSON::ParserError => e
75
81
  @logger.error("DataDome: error parsing JSON from Fraud API /collect #{e.message}")
76
- return DataDomeResponseError.new(nil, DataDomeResponseStatus::FAILURE, "DataDome: error parsing JSON from Fraud API", e.message)
82
+ return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome: error parsing JSON from Fraud API", errors: e.message)
77
83
  end
78
84
  end
79
85
  rescue Faraday::TimeoutError => e
80
- datadome_response = DataDomeResponseError.new(nil, DataDomeResponseStatus::TIMEOUT, "DataDome Fraud API request timeout", e.message)
86
+ datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::TIMEOUT, message: "DataDome Fraud API request timeout", errors: e.message)
81
87
  rescue Faraday::ConnectionFailed => e
82
- datadome_response = DataDomeResponseError.new(nil, DataDomeResponseStatus::FAILURE, "DataDome Fraud API request failed", e.message)
88
+ datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome Fraud API request failed", errors: e.message)
83
89
  end
84
90
 
85
91
  datadome_response
@@ -149,7 +149,7 @@ class DataDomeHeaders
149
149
  contentType: @content_type,
150
150
  host: @host,
151
151
  port: @port,
152
- xRealIP: @x_real_ip,
152
+ xRealIp: @x_real_ip,
153
153
  xForwardedForIp: @x_forwarded_for_ip,
154
154
  acceptEncoding: @accept_encoding,
155
155
  acceptLanguage: @accept_language,
@@ -177,7 +177,7 @@ class DataDomeHeaders
177
177
  end
178
178
 
179
179
  class DataDomeRequest
180
- attr_reader :module, :header, :account, :status, :session, :user
180
+ attr_reader :module, :header, :account, :status, :session, :user, :authentication, :reason
181
181
 
182
182
  def initialize(datadome_headers)
183
183
  @module = DataDomeModule.new
@@ -189,6 +189,8 @@ class DataDomeRequest
189
189
  @status = {}
190
190
  @session = {}
191
191
  @user = {}
192
+ @authentication = {}
193
+ @reason = nil
192
194
  end
193
195
 
194
196
  def to_json(options = {})
@@ -199,6 +201,8 @@ class DataDomeRequest
199
201
  status: @status,
200
202
  session: @session,
201
203
  user: @user,
204
+ authentication: @authentication,
205
+ reason: @reason,
202
206
  }
203
207
  JSON.generate(data, options)
204
208
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module DataDomeResponseAction
4
4
  ALLOW = "allow"
5
+ CHALLENGE = "challenge"
6
+ REVIEW = "review"
5
7
  DENY = "deny"
6
8
  end
7
9
 
@@ -21,16 +23,17 @@ class DataDomeError
21
23
  end
22
24
 
23
25
  class DataDomeResponse
24
- attr_accessor :action, :score, :status
26
+ attr_accessor :action, :score, :status, :event_id
25
27
 
26
- def initialize(action, score, status)
27
- @action = action
28
- @score = score
28
+ def initialize(status:, score:nil, event_id:nil)
29
+ @action = DataDomeResponseAction::ALLOW
29
30
  @status = status
31
+ @score = score
32
+ @event_id = event_id
30
33
  end
31
34
 
32
35
  def to_s
33
- "DataDomeResponse: action=#{@action}, score=#{@score}, status=#{@status}"
36
+ "DataDomeResponse: action=#{@action}, score=#{@score}, status=#{@status}, event_id=#{@event_id}"
34
37
  end
35
38
 
36
39
  def to_json(options = {})
@@ -38,6 +41,7 @@ class DataDomeResponse
38
41
  action: @action,
39
42
  score: @score,
40
43
  status: @status,
44
+ event_id: @event_id,
41
45
  }.to_json
42
46
  end
43
47
  end
@@ -45,15 +49,15 @@ end
45
49
  class DataDomeResponseSuccess < DataDomeResponse
46
50
  attr_reader :ip, :reasons, :location
47
51
 
48
- def initialize(action, score, status, reasons, ip, location)
49
- super(action, score, status)
52
+ def initialize(status:, score:, event_id:, reasons:, ip:, location:)
53
+ super(status: status, score: score, event_id: event_id)
50
54
  @reasons = reasons
51
55
  @ip = ip
52
56
  @location = location
53
57
  end
54
58
 
55
59
  def to_s
56
- "DataDomeResponseSuccess: action=#{@action}, score=#{@score}, status=#{@status}, reasons=#{@reasons}, ip=#{@ip}, location=#{@location}"
60
+ "DataDomeResponseSuccess: action=#{@action}, score=#{@score}, status=#{@status}, event_id=#{@event_id}, reasons=#{@reasons}, ip=#{@ip}, location=#{@location}"
57
61
  end
58
62
 
59
63
  def to_json(options = {})
@@ -61,6 +65,7 @@ class DataDomeResponseSuccess < DataDomeResponse
61
65
  action: @action,
62
66
  score: @score,
63
67
  status: @status,
68
+ event_id: @event_id,
64
69
  reasons: @reasons,
65
70
  ip: @ip,
66
71
  location: @location,
@@ -71,8 +76,8 @@ end
71
76
  class DataDomeResponseError < DataDomeResponse
72
77
  attr_reader :message, :errors
73
78
 
74
- def initialize(action, status, message, errors)
75
- super(action, nil, status)
79
+ def initialize(status:, message:, errors:)
80
+ super(status: status)
76
81
  @message = message
77
82
  @errors = errors
78
83
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DataDomeAuthenticationMode
4
+ OTHER = "other"
5
+ BIOMETRIC = "biometric"
6
+ MAIL = "mail"
7
+ MFA = "mfa"
8
+ OTP = "otp"
9
+ PASSWORD = "password"
10
+ end
11
+
12
+ module DataDomeAuthenticationType
13
+ OTHER = "other"
14
+ LOCAL = "local"
15
+ SOCIAL = "social"
16
+ end
17
+
18
+ module DataDomeSocialProvider
19
+ OTHER = "other"
20
+ AMAZON = "amazon"
21
+ APPLE = "apple"
22
+ FACEBOOK = "facebook"
23
+ GITHUB = "github"
24
+ GOOGLE = "google"
25
+ LINKEDIN = "linkedin"
26
+ MICROSOFT = "microsoft"
27
+ TWITTER = "twitter"
28
+ YAHOO = "yahoo"
29
+ end
30
+
31
+ class DataDomeAuthentication
32
+ attr_accessor :mode, :type, :social_provider
33
+
34
+ def initialize(mode: DataDomeAuthenticationMode::OTHER, type: DataDomeAuthenticationType::OTHER, social_provider: DataDomeSocialProvider::OTHER)
35
+ @mode = mode
36
+ @type = type
37
+ @social_provider = social_provider
38
+ end
39
+
40
+ def to_s
41
+ "DataDomeAuthentication: mode=#{@mode}, type=#{@type}, socialProvider=#{@social_provider}"
42
+ end
43
+
44
+ def to_json(options = {})
45
+ {
46
+ mode: @mode,
47
+ type: @type,
48
+ socialProvider: @social_provider,
49
+ }.to_json
50
+ end
51
+ end
data/lib/model/events.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "./authentication"
4
+ require_relative "./session"
5
+
3
6
  module DataDomeActionType
4
7
  LOGIN = "login"
5
8
  REGISTER = "registration"
9
+ ACCOUNT_UPDATE = "account/update"
10
+ PASSWORD_UPDATE = "password/update"
6
11
  end
7
12
 
8
13
  module DataDomeStatusType
@@ -11,41 +16,117 @@ module DataDomeStatusType
11
16
  UNDEFINED = "undefined"
12
17
  end
13
18
 
19
+ module DataDomePasswordUpdateReason
20
+ FORCED_RESET = "forcedReset"
21
+ FORGOT_PASSWORD = "forgotPassword"
22
+ USER_UPDATE = "userUpdate"
23
+ end
24
+
25
+ module DataDomePasswordUpdateStatus
26
+ ATTEMPTED = "attempted"
27
+ FAILED = "failed"
28
+ SUCCEEDED = "succeeded"
29
+ LINK_EXPIRED = "linkExpired"
30
+ end
31
+
32
+ class DataDomeUserId
33
+ attr_accessor :id
34
+
35
+ def initialize(id:)
36
+ @id = id
37
+ end
38
+
39
+ def to_s
40
+ "DataDomeUserId: id=#{@id}"
41
+ end
42
+
43
+ def to_json(options = {})
44
+ {
45
+ id: @id,
46
+ }.to_json
47
+ end
48
+ end
49
+
14
50
  class DataDomeEvent
15
- attr_accessor :action, :status, :account
51
+ attr_accessor :action, :account, :authentication, :session
16
52
 
17
- def initialize(action, account, status = DataDomeStatusType::UNDEFINED)
53
+ def initialize(action, account, authentication: nil, session: nil)
18
54
  @action = action
19
55
  @account = account
20
- @status = status
56
+ @authentication = authentication
57
+ @session = session
21
58
  end
22
59
 
23
60
  def merge_with(request_data)
24
61
  request_data.instance_variable_set(:@account, @account)
25
- request_data.instance_variable_set(:@status, @status)
62
+ request_data.instance_variable_set(:@authentication, @authentication) if @authentication
63
+ request_data.instance_variable_set(:@session, @session) if @session
26
64
  request_data
27
65
  end
28
66
  end
29
67
 
30
68
  class DataDomeLoginEvent < DataDomeEvent
31
- def initialize(account:, status: DataDomeStatusType::UNDEFINED)
32
- super(DataDomeActionType::LOGIN, account, status)
69
+ attr_accessor :user, :status
70
+
71
+ def initialize(account:, status: DataDomeStatusType::UNDEFINED, authentication: nil, session: nil, user: nil)
72
+ super(DataDomeActionType::LOGIN, account, authentication: authentication, session: session)
73
+ @user = user
74
+ @status = status
75
+ end
76
+
77
+ def merge_with(request_data)
78
+ super(request_data)
79
+ request_data.instance_variable_set(:@user, @user) if @user
80
+ request_data.instance_variable_set(:@status, @status)
81
+ request_data
33
82
  end
34
83
  end
35
84
 
36
85
  class DataDomeRegistrationEvent < DataDomeEvent
37
- attr_accessor :user, :session
86
+ attr_accessor :user
38
87
 
39
- def initialize(account:, user:, session: nil, status: DataDomeStatusType::UNDEFINED)
40
- super(DataDomeActionType::REGISTER, account, status)
41
- @session = session
88
+ def initialize(account:, user:, authentication: nil, session: nil)
89
+ super(DataDomeActionType::REGISTER, account, authentication: authentication, session: session)
42
90
  @user = user
43
91
  end
44
92
 
45
93
  def merge_with(request_data)
46
94
  super(request_data)
47
- request_data.instance_variable_set(:@session, @session)
48
95
  request_data.instance_variable_set(:@user, @user)
49
96
  request_data
50
97
  end
51
98
  end
99
+
100
+ class DataDomeAccountUpdateEvent < DataDomeEvent
101
+ attr_accessor :user
102
+
103
+ def initialize(account:, user: nil, authentication: nil, session: nil)
104
+ super(DataDomeActionType::ACCOUNT_UPDATE, account, authentication: authentication, session: session)
105
+ @user = user
106
+ end
107
+
108
+ def merge_with(request_data)
109
+ super(request_data)
110
+ request_data.instance_variable_set(:@user, @user) if @user
111
+ request_data
112
+ end
113
+ end
114
+
115
+ class DataDomePasswordUpdateEvent < DataDomeEvent
116
+ attr_accessor :reason, :user, :status
117
+
118
+ def initialize(account:, reason: nil, status:, authentication: nil, session: nil, user: nil)
119
+ super(DataDomeActionType::PASSWORD_UPDATE, account, authentication: authentication, session: session)
120
+ @reason = reason
121
+ @user = user
122
+ @status = status
123
+ end
124
+
125
+ def merge_with(request_data)
126
+ super(request_data)
127
+ request_data.instance_variable_set(:@reason, @reason)
128
+ request_data.instance_variable_set(:@user, @user) if @user
129
+ request_data.instance_variable_set(:@status, @status)
130
+ request_data
131
+ end
132
+ end
data/lib/model/user.rb CHANGED
@@ -1,19 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "time"
4
3
  require_relative "./address"
5
4
 
6
5
  module DataDomeTitle
7
- EMPTY = nil
8
6
  MR = "mr"
9
7
  MRS = "mrs"
10
8
  MX = "mx"
11
9
  end
12
10
 
13
11
  class DataDomeUser
14
- attr_accessor :id, :title, :first_name, :last_name, :created_at, :phone, :email, :address
12
+ attr_accessor :id, :title, :first_name, :last_name, :created_at, :phone, :email, :display_name, :description, :picture_urls, :external_urls, :address, :payment_method_updated
15
13
 
16
- def initialize(id:, title: nil, first_name: nil, last_name: nil, created_at: Time.now.iso8601, phone: nil, email: nil, address: nil)
14
+ def initialize(id:, title: nil, first_name: nil, last_name: nil, created_at: nil, phone: nil, email: nil, display_name: nil, description: nil, picture_urls: nil, external_urls: nil, address: nil, payment_method_updated: nil)
17
15
  @id = id
18
16
  @title = title
19
17
  @first_name = first_name
@@ -21,22 +19,33 @@ class DataDomeUser
21
19
  @created_at = created_at
22
20
  @phone = phone
23
21
  @email = email
22
+ @display_name = display_name
23
+ @description = description
24
+ @picture_urls = picture_urls || []
25
+ @external_urls = external_urls || []
24
26
  @address = address
27
+ @payment_method_updated = payment_method_updated
25
28
  end
26
29
 
27
30
  def to_s
28
- "DataDomeUser: id=#{@id}, title=#{@title}, firstName=#{@first_name}, lastName=#{@last_name}, createdAt=#{@created_at}, phone=#{@phone}, address=#{@address}"
31
+ "DataDomeUser: id=#{@id}, title=#{@title}, firstName=#{@first_name}, lastName=#{@last_name}, createdAt=#{@created_at}, phone=#{@phone}, email=#{@email}, displayName=#{@display_name}, description=#{@description}, pictureUrls=#{@picture_urls}, externalUrls=#{@external_urls}, address=#{@address}, paymentMethodUpdated=#{@payment_method_updated}"
29
32
  end
30
33
 
31
34
  def to_json(options = {})
32
35
  {
33
36
  id: @id,
37
+ title: @title,
34
38
  firstName: @first_name,
35
39
  lastName: @last_name,
36
40
  createdAt: @created_at,
37
41
  phone: @phone,
38
42
  email: @email,
39
- address: @address,
43
+ displayName: @display_name,
44
+ description: @description,
45
+ pictureUrls: @picture_urls,
46
+ externalUrls: @external_urls,
47
+ address: @address.respond_to?(:to_json) ? JSON.parse(@address.to_json) : @address,
48
+ paymentMethodUpdated: @payment_method_updated,
40
49
  }.to_json
41
50
  end
42
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadome_fraud_sdk_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DataDome
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-18 00:00:00.000000000 Z
11
+ date: 2025-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -36,6 +36,7 @@ files:
36
36
  - lib/model/address.rb
37
37
  - lib/model/api/request.rb
38
38
  - lib/model/api/response.rb
39
+ - lib/model/authentication.rb
39
40
  - lib/model/events.rb
40
41
  - lib/model/location.rb
41
42
  - lib/model/operation.rb