atlas_engine 1.1.0 → 1.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -17
  3. data/app/graphql/atlas_engine/schema.graphql +10 -1
  4. data/app/graphql/atlas_engine/types/address_validation/concern_type.rb +8 -1
  5. data/app/graphql/atlas_engine/types/address_validation/suggestion_type.rb +4 -0
  6. data/app/graphql/atlas_engine/types/message_format_type.rb +11 -0
  7. data/app/graphql/atlas_engine/types/query_type.rb +3 -1
  8. data/app/lib/atlas_engine/validation_transcriber/address_parsings.rb +14 -9
  9. data/app/models/atlas_engine/address_validation/es/validators/full_address.rb +18 -5
  10. data/app/models/atlas_engine/address_validation/es/validators/full_address_street.rb +2 -2
  11. data/app/models/atlas_engine/address_validation/full_address_validator_base.rb +6 -2
  12. data/app/models/atlas_engine/address_validation/message_format.rb +13 -0
  13. data/app/models/atlas_engine/address_validation/predicate_pipeline_builder.rb +90 -0
  14. data/app/models/atlas_engine/address_validation/request.rb +1 -0
  15. data/app/models/atlas_engine/address_validation/suggestion.rb +26 -1
  16. data/app/models/atlas_engine/address_validation/validator.rb +31 -14
  17. data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result.rb +9 -5
  18. data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result_base.rb +4 -3
  19. data/app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb +19 -4
  20. data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_concern_builder.rb +4 -3
  21. data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_country_concern_builder.rb +6 -4
  22. data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_province_concern_builder.rb +4 -2
  23. data/app/models/atlas_engine/address_validation/validators/full_address/no_candidate_result.rb +1 -1
  24. data/app/models/atlas_engine/address_validation/validators/full_address/suggestion_builder.rb +5 -2
  25. data/app/models/atlas_engine/address_validation/validators/full_address/unknown_address_concern_builder.rb +16 -4
  26. data/app/models/atlas_engine/address_validation/validators/full_address/unknown_province_concern_builder.rb +8 -3
  27. data/app/models/atlas_engine/address_validation/validators/full_address/unmatched_field_concern_builder.rb +13 -3
  28. data/app/models/atlas_engine/address_validation/validators/full_address/unsupported_script_result.rb +1 -1
  29. data/app/models/atlas_engine/address_validation/validators/predicates/city/present.rb +1 -1
  30. data/app/models/atlas_engine/address_validation/validators/predicates/country/exists.rb +5 -1
  31. data/app/models/atlas_engine/address_validation/validators/predicates/country/valid_for_zip.rb +1 -1
  32. data/app/models/atlas_engine/address_validation/validators/predicates/neighborhood/present.rb +35 -0
  33. data/app/models/atlas_engine/address_validation/validators/predicates/not_exceed_max_length.rb +18 -3
  34. data/app/models/atlas_engine/address_validation/validators/predicates/phone/valid.rb +3 -1
  35. data/app/models/atlas_engine/address_validation/validators/predicates/predicate.rb +6 -2
  36. data/app/models/atlas_engine/address_validation/validators/predicates/province/exists.rb +3 -1
  37. data/app/models/atlas_engine/address_validation/validators/predicates/province/valid_for_country.rb +3 -1
  38. data/app/models/atlas_engine/address_validation/validators/predicates/street/present.rb +3 -1
  39. data/app/models/atlas_engine/address_validation/validators/predicates/street_name/present.rb +35 -0
  40. data/app/models/atlas_engine/address_validation/validators/predicates/street_number/present.rb +35 -0
  41. data/app/models/atlas_engine/address_validation/validators/predicates/zip/present.rb +2 -2
  42. data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_country.rb +1 -1
  43. data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_province.rb +1 -1
  44. data/app/models/atlas_engine/services/validation.rb +4 -0
  45. data/db/data/validation_pipelines/es.yml +46 -0
  46. data/db/data/validation_pipelines/es_street.yml +46 -0
  47. data/db/data/validation_pipelines/local.yml +46 -0
  48. data/lib/atlas_engine/version.rb +1 -1
  49. metadata +39 -5
@@ -8,7 +8,12 @@ module AtlasEngine
8
8
  class ConcernBuilder
9
9
  extend T::Sig
10
10
 
11
- attr_reader :unmatched_component, :unmatched_field, :matched_components, :address, :suggestion_ids
11
+ attr_reader :unmatched_component,
12
+ :unmatched_field,
13
+ :matched_components,
14
+ :address,
15
+ :suggestion_ids,
16
+ :message_format
12
17
 
13
18
  class << self
14
19
  extend T::Sig
@@ -79,15 +84,24 @@ module AtlasEngine
79
84
  matched_components: T::Array[Symbol],
80
85
  address: AbstractAddress,
81
86
  suggestion_ids: T::Array[String],
87
+ message_format: MessageFormat,
82
88
  unmatched_field: T.nilable(Symbol),
83
89
  ).void
84
90
  end
85
- def initialize(unmatched_component:, matched_components:, address:, suggestion_ids:, unmatched_field: nil)
91
+ def initialize(
92
+ unmatched_component:,
93
+ matched_components:,
94
+ address:,
95
+ suggestion_ids:,
96
+ message_format:,
97
+ unmatched_field: nil
98
+ )
86
99
  @unmatched_component = unmatched_component
87
100
  @unmatched_field = unmatched_field
88
101
  @matched_components = matched_components
89
102
  @address = address
90
103
  @suggestion_ids = suggestion_ids
104
+ @message_format = message_format
91
105
  end
92
106
 
93
107
  sig { returns(AddressValidation::Concern) }
@@ -106,7 +120,7 @@ module AtlasEngine
106
120
 
107
121
  sig { returns(AddressValidation::Concern) }
108
122
  def build_zip_concern
109
- concern = InvalidZipConcernBuilder.for(address, suggestion_ids)
123
+ concern = InvalidZipConcernBuilder.for(address, suggestion_ids, message_format)
110
124
  return concern if concern
111
125
 
112
126
  build_default_concern
@@ -115,7 +129,7 @@ module AtlasEngine
115
129
  sig { returns(AddressValidation::Concern) }
116
130
  def build_province_concern
117
131
  if ([:zip, :city] - matched_components).empty?
118
- UnknownProvinceConcernBuilder.new(address).build(suggestion_ids)
132
+ UnknownProvinceConcernBuilder.new(address, message_format).build(suggestion_ids)
119
133
  else
120
134
  build_default_concern
121
135
  end
@@ -128,6 +142,7 @@ module AtlasEngine
128
142
  matched_components,
129
143
  address,
130
144
  unmatched_field,
145
+ message_format,
131
146
  ).build(suggestion_ids)
132
147
  end
133
148
  end
@@ -13,9 +13,10 @@ module AtlasEngine
13
13
  params(
14
14
  address: AbstractAddress,
15
15
  suggestion_ids: T::Array[String],
16
+ message_format: MessageFormat,
16
17
  ).returns(T.nilable(AddressValidation::Concern))
17
18
  end
18
- def for(address, suggestion_ids)
19
+ def for(address, suggestion_ids, message_format)
19
20
  country = Worldwide.region(code: address.country_code)
20
21
 
21
22
  province = country.zone(code: address.province_code.presence || "")
@@ -24,11 +25,11 @@ module AtlasEngine
24
25
  if country_expects_zone_in_address?(country) && province.province?
25
26
  return if province.valid_zip?(address.zip)
26
27
 
27
- InvalidZipForProvinceConcernBuilder.new(address).build
28
+ InvalidZipForProvinceConcernBuilder.new(address, message_format).build
28
29
  else
29
30
  return if country.valid_zip?(address.zip)
30
31
 
31
- InvalidZipForCountryConcernBuilder.new(address).build(suggestion_ids)
32
+ InvalidZipForCountryConcernBuilder.new(address, message_format).build(suggestion_ids)
32
33
  end
33
34
  end
34
35
 
@@ -9,16 +9,18 @@ module AtlasEngine
9
9
  extend T::Sig
10
10
  include ConcernFormatter
11
11
  attr_reader :address
12
+ attr_reader :message_format
12
13
 
13
- sig { params(address: AbstractAddress).void }
14
- def initialize(address)
14
+ sig { params(address: AbstractAddress, message_format: MessageFormat).void }
15
+ def initialize(address, message_format)
15
16
  @address = address
17
+ @message_format = message_format
16
18
  end
17
19
 
18
20
  sig { params(suggestion_ids: T::Array[String]).returns(Concern) }
19
21
  def build(suggestion_ids = [])
20
- message = country.field(key: :zip).error(
21
- code: :invalid_for_country,
22
+ message = country.field(key: :zip).error(
23
+ code: "invalid_for_country_#{message_format.serialize}".to_sym,
22
24
  options: { country: country.full_name },
23
25
  ).to_s
24
26
 
@@ -9,15 +9,17 @@ module AtlasEngine
9
9
  extend T::Sig
10
10
  include ConcernFormatter
11
11
  attr_reader :address
12
+ attr_reader :message_format
12
13
 
13
- def initialize(address)
14
+ def initialize(address, message_format)
14
15
  @address = address
16
+ @message_format = message_format
15
17
  end
16
18
 
17
19
  sig { params(suggestion_ids: T::Array[String]).returns(Concern) }
18
20
  def build(suggestion_ids = [])
19
21
  message = country.field(key: :zip).error(
20
- code: :invalid_for_province,
22
+ code: "invalid_for_province_#{message_format.serialize}".to_sym,
21
23
  options: { province: province_name },
22
24
  ).to_s
23
25
 
@@ -12,7 +12,7 @@ module AtlasEngine
12
12
  def update_result
13
13
  result.concerns << UnknownAddressConcernBuilder.new(address).build
14
14
 
15
- concern = InvalidZipConcernBuilder.for(address, [])
15
+ concern = InvalidZipConcernBuilder.for(address, [], message_format)
16
16
  result.concerns << concern if concern
17
17
 
18
18
  update_result_scope
@@ -74,9 +74,12 @@ module AtlasEngine
74
74
  original_street = comparison.left_sequence.raw_value
75
75
  field = unmatched_fields[:street]
76
76
 
77
- if field == :address1
77
+ case field
78
+ when :street_name
79
+ suggestion.street_name = suggested_street
80
+ when :address1
78
81
  suggestion.address1 = suggestion.address1.to_s.sub(original_street, suggested_street)
79
- elsif field == :address2
82
+ when :address2
80
83
  suggestion.address2 = suggestion.address2.to_s.sub(original_street, suggested_street)
81
84
  end
82
85
 
@@ -12,14 +12,20 @@ module AtlasEngine
12
12
  sig { returns(TAddress) }
13
13
  attr_reader :address
14
14
 
15
- sig { params(address: TAddress).void }
16
- def initialize(address)
15
+ sig { returns(MessageFormat) }
16
+ attr_reader :message_format
17
+
18
+ sig { params(address: TAddress, message_format: MessageFormat).void }
19
+ def initialize(address, message_format = MessageFormat::Instructional)
17
20
  @address = address
21
+ @message_format = message_format
18
22
  end
19
23
 
20
24
  sig { params(suggestion_ids: T::Array[String]).returns(Concern) }
21
25
  def build(suggestion_ids = [])
22
- message = country.field(key: :address).error(code: :may_not_exist)
26
+ message = country.field(key: :address).error(
27
+ code: "may_not_exist_#{message_format.serialize}".to_sym,
28
+ ).to_s
23
29
 
24
30
  Concern.new(
25
31
  code: :address_unknown,
@@ -27,9 +33,15 @@ module AtlasEngine
27
33
  type: T.must(Concern::TYPES[:warning]),
28
34
  type_level: 1,
29
35
  suggestion_ids: suggestion_ids,
30
- field_names: [:address1],
36
+ field_names: [field],
31
37
  )
32
38
  end
39
+
40
+ private
41
+
42
+ def field
43
+ address.street_name.present? ? :street_name : :address1
44
+ end
33
45
  end
34
46
  end
35
47
  end
@@ -8,17 +8,22 @@ module AtlasEngine
8
8
  class UnknownProvinceConcernBuilder
9
9
  extend T::Sig
10
10
  include ConcernFormatter
11
+
11
12
  attr_reader :address
12
13
 
13
- sig { params(address: AbstractAddress).void }
14
- def initialize(address)
14
+ sig { returns(MessageFormat) }
15
+ attr_reader :message_format
16
+
17
+ sig { params(address: AbstractAddress, message_format: MessageFormat).void }
18
+ def initialize(address, message_format = MessageFormat::Instructional)
15
19
  @address = address
20
+ @message_format = message_format
16
21
  end
17
22
 
18
23
  sig { params(suggestion_ids: T::Array[String]).returns(Concern) }
19
24
  def build(suggestion_ids = [])
20
25
  message = country.field(key: :province).error(
21
- code: :unknown_for_city_and_zip,
26
+ code: "unknown_for_city_and_zip_#{message_format.serialize}".to_sym,
22
27
  options: { city: address.city, zip: address.zip },
23
28
  ).to_s
24
29
 
@@ -8,7 +8,7 @@ module AtlasEngine
8
8
  class UnmatchedFieldConcernBuilder
9
9
  extend T::Sig
10
10
  include ConcernFormatter
11
- attr_reader :address, :unmatched_component, :matched_components, :unmatched_field
11
+ attr_reader :address, :unmatched_component, :matched_components, :unmatched_field, :message_format
12
12
 
13
13
  COMPONENTS_TO_LABELS = {
14
14
  zip: "ZIP",
@@ -27,13 +27,21 @@ module AtlasEngine
27
27
  matched_components: T::Array[Symbol],
28
28
  address: AbstractAddress,
29
29
  unmatched_field: T.nilable(Symbol),
30
+ message_format: MessageFormat,
30
31
  ).void
31
32
  end
32
- def initialize(unmatched_component, matched_components, address, unmatched_field = nil)
33
+ def initialize(
34
+ unmatched_component,
35
+ matched_components,
36
+ address,
37
+ unmatched_field = nil,
38
+ message_format = MessageFormat::Instructional
39
+ )
33
40
  @address = address
34
41
  @unmatched_component = unmatched_component
35
42
  @matched_components = matched_components
36
43
  @unmatched_field = unmatched_field || unmatched_component
44
+ @message_format = message_format
37
45
  end
38
46
 
39
47
  sig do
@@ -56,7 +64,9 @@ module AtlasEngine
56
64
 
57
65
  sig { returns(String) }
58
66
  def message
59
- country.field(key: field_name).error(code: :unknown_for_address).to_s
67
+ country.field(key: field_name).error(
68
+ code: "unknown_for_address_#{message_format.serialize}".to_sym,
69
+ ).to_s
60
70
  end
61
71
 
62
72
  sig { returns(Symbol) }
@@ -10,7 +10,7 @@ module AtlasEngine
10
10
 
11
11
  sig { void }
12
12
  def update_result
13
- concern = InvalidZipConcernBuilder.for(address, [])
13
+ concern = InvalidZipConcernBuilder.for(address, [], message_format)
14
14
  result.concerns << concern if concern
15
15
 
16
16
  update_result_scope
@@ -24,7 +24,7 @@ module AtlasEngine
24
24
  type: T.must(Concern::TYPES[:error]),
25
25
  type_level: 3,
26
26
  suggestion_ids: [],
27
- message: @cache.country.field(key: :city).error(code: :blank).to_s,
27
+ message: @cache.country.field(key: :city).error(code: "blank_#{message_format.serialize}".to_sym).to_s,
28
28
  )
29
29
  end
30
30
  end
@@ -23,7 +23,11 @@ module AtlasEngine
23
23
  type: T.must(Concern::TYPES[:error]),
24
24
  type_level: 3,
25
25
  suggestion_ids: [],
26
- message: Worldwide.region(code: "US").field(key: :country).error(code: :blank),
26
+ message: Worldwide
27
+ .region(code: "US")
28
+ .field(key: :country)
29
+ .error(code: "blank_#{message_format.serialize}".to_sym)
30
+ .to_s,
27
31
  )
28
32
  end
29
33
  end
@@ -34,7 +34,7 @@ module AtlasEngine
34
34
  type_level: 1,
35
35
  suggestion_ids: [T.must(suggestion.id)],
36
36
  message: @cache.country.field(key: :zip).error(
37
- code: :invalid_for_country,
37
+ code: "invalid_for_country_#{message_format.serialize}".to_sym,
38
38
  options: { country: @cache.country.full_name },
39
39
  ),
40
40
  suggestion: suggestion,
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module AtlasEngine
5
+ module AddressValidation
6
+ module Validators
7
+ module Predicates
8
+ module Neighborhood
9
+ class Present < Predicate
10
+ sig { override.returns(T.nilable(Concern)) }
11
+ def evaluate
12
+ build_concern if @address.neighborhood.blank? && @cache.country.neighborhood_required?
13
+ end
14
+
15
+ private
16
+
17
+ sig { returns(Concern) }
18
+ def build_concern
19
+ Concern.new(
20
+ field_names: [:neighborhood],
21
+ code: :neighborhood_blank,
22
+ type: T.must(Concern::TYPES[:error]),
23
+ type_level: 3,
24
+ suggestion_ids: [],
25
+ message: @cache.country.field(key: :neighborhood).error(
26
+ code: "blank_#{message_format.serialize}".to_sym,
27
+ ).to_s,
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -6,14 +6,29 @@ module AtlasEngine
6
6
  module Validators
7
7
  module Predicates
8
8
  class NotExceedMaxLength < Predicate
9
- MAX_COMPONENT_LENGTH = 255
9
+ MAX_COMPONENT_LENGTH = T.let(
10
+ {
11
+ street_name: 200,
12
+ street_number: 50,
13
+ line2: 175,
14
+ neighborhood: 75,
15
+ default: 255,
16
+ },
17
+ T::Hash[Symbol, Integer],
18
+ )
19
+
10
20
  sig { override.returns(T.nilable(Concern)) }
11
21
  def evaluate
12
- build_concern if address.send(@field).to_s.length > MAX_COMPONENT_LENGTH
22
+ build_concern if address.send(@field).to_s.length > limit
13
23
  end
14
24
 
15
25
  private
16
26
 
27
+ sig { returns(Integer) }
28
+ def limit
29
+ @limit ||= T.let(MAX_COMPONENT_LENGTH[@field] || T.must(MAX_COMPONENT_LENGTH[:default]), T.nilable(Integer))
30
+ end
31
+
17
32
  sig { returns(Concern) }
18
33
  def build_concern
19
34
  Concern.new(
@@ -22,7 +37,7 @@ module AtlasEngine
22
37
  type: T.must(Concern::TYPES[:error]),
23
38
  type_level: 3,
24
39
  suggestion_ids: [],
25
- message: @cache.country.field(key: @field)&.error(code: :too_long).to_s,
40
+ message: @cache.country.field(key: @field)&.error(code: :too_long, options: { limit: limit }).to_s,
26
41
  )
27
42
  end
28
43
  end
@@ -28,7 +28,9 @@ module AtlasEngine
28
28
  type: T.must(Concern::TYPES[:error]),
29
29
  type_level: 3,
30
30
  suggestion_ids: [],
31
- message: @cache.country.field(key: :phone).error(code: :invalid).to_s,
31
+ message: @cache.country.field(key: :phone).error(
32
+ code: "invalid_#{message_format.serialize}".to_sym,
33
+ ).to_s,
32
34
  )
33
35
  end
34
36
  end
@@ -19,13 +19,17 @@ module AtlasEngine
19
19
  sig { returns(Cache) }
20
20
  attr_reader :cache
21
21
 
22
+ sig { returns(MessageFormat) }
23
+ attr_reader :message_format
24
+
22
25
  delegate :address1, :address2, :city, :zip, :province_code, :country_code, to: :address
23
26
 
24
- sig { params(field: Symbol, address: Address, cache: Cache).void }
25
- def initialize(field:, address:, cache: Cache.new(address))
27
+ sig { params(field: Symbol, address: Address, message_format: MessageFormat, cache: Cache).void }
28
+ def initialize(field:, address:, message_format: MessageFormat::Instructional, cache: Cache.new(address))
26
29
  @field = field
27
30
  @address = address
28
31
  @cache = cache
32
+ @message_format = message_format
29
33
  end
30
34
 
31
35
  sig { abstract.returns(T.nilable(Concern)) }
@@ -26,7 +26,9 @@ module AtlasEngine
26
26
  type: T.must(Concern::TYPES[:error]),
27
27
  type_level: 3,
28
28
  suggestion_ids: [],
29
- message: @cache.country.field(key: :province)&.error(code: :blank).to_s,
29
+ message: @cache.country.field(key: :province)&.error(
30
+ code: "blank_#{message_format.serialize}".to_sym,
31
+ ).to_s,
30
32
  )
31
33
  end
32
34
 
@@ -28,7 +28,9 @@ module AtlasEngine
28
28
  type: T.must(Concern::TYPES[:error]),
29
29
  type_level: 3,
30
30
  suggestion_ids: [],
31
- message: @cache.country.field(key: :province).error(code: :blank),
31
+ message: @cache.country.field(key: :province).error(
32
+ code: "blank_#{message_format.serialize}".to_sym,
33
+ ).to_s,
32
34
  )
33
35
  end
34
36
 
@@ -22,7 +22,9 @@ module AtlasEngine
22
22
  type: T.must(Concern::TYPES[:error]),
23
23
  type_level: 3,
24
24
  suggestion_ids: [],
25
- message: @cache.country.field(key: :address1).error(code: :blank).to_s,
25
+ message: @cache.country.field(key: :address1).error(
26
+ code: "blank_#{message_format.serialize}".to_sym,
27
+ ).to_s,
26
28
  )
27
29
  end
28
30
  end
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module AtlasEngine
5
+ module AddressValidation
6
+ module Validators
7
+ module Predicates
8
+ module StreetName
9
+ class Present < Predicate
10
+ sig { override.returns(T.nilable(Concern)) }
11
+ def evaluate
12
+ build_concern if @address.street_name.blank? && @cache.country.street_name_required?
13
+ end
14
+
15
+ private
16
+
17
+ sig { returns(Concern) }
18
+ def build_concern
19
+ Concern.new(
20
+ field_names: [:street_name],
21
+ code: :street_name_blank,
22
+ type: T.must(Concern::TYPES[:error]),
23
+ type_level: 3,
24
+ suggestion_ids: [],
25
+ message: @cache.country.field(key: :street_name).error(
26
+ code: "blank_#{message_format.serialize}".to_sym,
27
+ ).to_s,
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module AtlasEngine
5
+ module AddressValidation
6
+ module Validators
7
+ module Predicates
8
+ module StreetNumber
9
+ class Present < Predicate
10
+ sig { override.returns(T.nilable(Concern)) }
11
+ def evaluate
12
+ build_concern if @address.street_number.blank? && @cache.country.street_number_required?
13
+ end
14
+
15
+ private
16
+
17
+ sig { returns(Concern) }
18
+ def build_concern
19
+ Concern.new(
20
+ field_names: [:street_number],
21
+ code: :street_number_blank,
22
+ type: T.must(Concern::TYPES[:error]),
23
+ type_level: 3,
24
+ suggestion_ids: [],
25
+ message: @cache.country.field(key: :street_number).error(
26
+ code: "blank_#{message_format.serialize}".to_sym,
27
+ ).to_s,
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -40,12 +40,12 @@ module AtlasEngine
40
40
  province_name = @cache.province.province? ? @cache.province.full_name : address.province_code
41
41
  if province_name.present?
42
42
  @cache.country.field(key: :zip).error(
43
- code: :invalid_for_province,
43
+ code: "invalid_for_province_#{message_format.serialize}".to_sym,
44
44
  options: { province: province_name },
45
45
  ).to_s
46
46
  else
47
47
  @cache.country.field(key: :zip).error(
48
- code: :invalid_for_country,
48
+ code: "invalid_for_country_#{message_format.serialize}".to_sym,
49
49
  options: { country: @cache.country.short_name },
50
50
  ).to_s
51
51
  end
@@ -32,7 +32,7 @@ module AtlasEngine
32
32
  type_level: 3,
33
33
  suggestion_ids: [],
34
34
  message: @cache.country.field(key: :zip).error(
35
- code: :invalid_for_country,
35
+ code: "invalid_for_country_#{message_format.serialize}".to_sym,
36
36
  options: { country: @cache.country.short_name },
37
37
  ).to_s,
38
38
  )
@@ -43,7 +43,7 @@ module AtlasEngine
43
43
  province_name = @cache.province.province? ? @cache.province.full_name : address.province_code
44
44
 
45
45
  @cache.country.field(key: :zip).error(
46
- code: :invalid_for_province,
46
+ code: "invalid_for_province_#{message_format.serialize}".to_sym,
47
47
  options: { province: province_name },
48
48
  ).to_s
49
49
  end
@@ -22,11 +22,15 @@ module AtlasEngine
22
22
  AddressValidation::MatchingStrategies::Local
23
23
  end
24
24
 
25
+ message_format = AddressValidation::MessageFormat.try_deserialize(request.message_format) ||
26
+ AddressValidation::MessageFormat::Instructional
27
+
25
28
  validator = AddressValidation::Validator.new(
26
29
  address: request.address,
27
30
  locale: request.locale,
28
31
  matching_strategy: matching_strategy,
29
32
  context: request.address.context.to_h,
33
+ message_format: message_format,
30
34
  )
31
35
  result = validator.run
32
36
 
@@ -52,6 +52,52 @@ pipeline:
52
52
  class: AtlasEngine::AddressValidation::Validators::Predicates::Street::BuildingNumberInAddress1OrAddress2
53
53
  - field: address1
54
54
  class: AtlasEngine::AddressValidation::Validators::Predicates::Street::BuildingNumberInAddress1
55
+ - field: street_name
56
+ class: AtlasEngine::AddressValidation::Validators::Predicates::StreetName::Present
57
+ - field: street_name
58
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoEmojis
59
+ - field: street_name
60
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxTokenCount
61
+ - field: street_name
62
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxLength
63
+ - field: street_name
64
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoUrl
65
+ - field: street_name
66
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoHtmlTags
67
+ - field: street_number
68
+ class: AtlasEngine::AddressValidation::Validators::Predicates::StreetNumber::Present
69
+ - field: street_number
70
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoEmojis
71
+ - field: street_number
72
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxTokenCount
73
+ - field: street_number
74
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxLength
75
+ - field: street_number
76
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoUrl
77
+ - field: street_number
78
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoHtmlTags
79
+ - field: neighborhood
80
+ class: AtlasEngine::AddressValidation::Validators::Predicates::Neighborhood::Present
81
+ - field: neighborhood
82
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoEmojis
83
+ - field: neighborhood
84
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxTokenCount
85
+ - field: neighborhood
86
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxLength
87
+ - field: neighborhood
88
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoUrl
89
+ - field: neighborhood
90
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoHtmlTags
91
+ - field: line2
92
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoEmojis
93
+ - field: line2
94
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxTokenCount
95
+ - field: line2
96
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NotExceedMaxLength
97
+ - field: line2
98
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoUrl
99
+ - field: line2
100
+ class: AtlasEngine::AddressValidation::Validators::Predicates::NoHtmlTags
55
101
  - field: phone
56
102
  class: AtlasEngine::AddressValidation::Validators::Predicates::Phone::Valid
57
103