salestation 5.3.1 → 5.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6df52858cd7f5226e95ecf1336818ed60f021222f749e6f3a4969e6c05c309b
4
- data.tar.gz: 2221e592b6070e403ef763f94834ae142ec03ac7277674c9dc16668a54bbbecb
3
+ metadata.gz: e67e18c608d03d9fa6f1e3cff2345dd87eb55f76d7e087e57a75c4ce2b6f591f
4
+ data.tar.gz: '086a420e0dcd1483b346253be2d3a18405f02ee310956ae69501dd47832a1800'
5
5
  SHA512:
6
- metadata.gz: c10039d2261c8bfdec7a434de314d2152b59f8b50a55b4d12d0f47e59b14417f40181332be990924673dbb13131e4453267f352f0a63daa94e3ab0ccc3a08f16
7
- data.tar.gz: e9691491f6c13690129f5297b411d49034eb8fd628869e7b6b71c0f07551e477c5ca288beea2d0c679ca2ae98b334ebb441d12412946e7f2f6e41e2161eb2371
6
+ metadata.gz: 0fc035f130d5e795c15facde88ab5b2961a188e6c33bd40fa742f8b7700996c6b6a2dabc637b4a9083b4c364e9ed37ba97aca977231051a3410d91adb6fd4657
7
+ data.tar.gz: 4a1e69e9fd30f9c6c1e7d46853849f5db4614c684051ae38c39af0075fad267ad5ecba456c559866bb032f909bbf95bbe838ada29390c6a8b062f881758d8747
@@ -15,8 +15,9 @@ jobs:
15
15
 
16
16
 
17
17
  - name: Release Gem
18
- uses: discourse/publish-rubygems-action@b55d7b91b55e61752dc6cbc2972f8e16fe6c1a02
18
+ uses: discourse/publish-rubygems-action@4bd305c65315cb691bad1e8de97a87aaf29a0a85
19
19
  env:
20
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
20
  RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
21
  RELEASE_COMMAND: rake release
22
+ GIT_EMAIL: support@salemove.com
23
+ GIT_NAME: sm-deployer
@@ -15,15 +15,13 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
  strategy:
17
17
  matrix:
18
- ruby-version: ['2.6', '2.7', '3.0']
18
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
19
19
 
20
20
  steps:
21
21
  - uses: actions/checkout@v2
22
22
  - name: Set up Ruby
23
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
- # uses: ruby/setup-ruby@v1
26
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
23
+ # Automatically get bug fixes and new Ruby versions for ruby/setup-ruby
24
+ uses: ruby/setup-ruby@v1
27
25
  with:
28
26
  ruby-version: ${{ matrix.ruby-version }}
29
27
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --plugin yard-doctest
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ # Contributing to salestation
2
+
3
+ We currently do not accept any contributions from external sources.
4
+
5
+ The code is still open source and if you wish to add any changes, feel free to fork it and add changes to your fork.
6
+
7
+ Issues for any security-related bugs found are still welcome, but we offer no guarantees on whether or when they will be acted upon.
8
+
9
+ For any exceptional cases, please contact us at open-source@glia.com.
data/Rakefile CHANGED
@@ -1,6 +1,13 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'yard/doctest/rake'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
8
+ YARD::Doctest::RakeTask.new
5
9
 
6
- task :default => :spec
10
+ task :default do
11
+ Rake::Task['spec'].invoke
12
+ Rake::Task['yard:doctest'].invoke
13
+ end
@@ -52,6 +52,11 @@ module Salestation
52
52
  attribute? :message, Types::Strict::String
53
53
  attribute? :debug_message, Types::Strict::String
54
54
  end
55
+
56
+ class BadRequest < Error
57
+ attribute? :message, Types::Strict::String
58
+ attribute? :debug_message, Types::Strict::String
59
+ end
55
60
  end
56
61
  end
57
62
  end
@@ -7,12 +7,7 @@ require 'dry-types'
7
7
  module Salestation
8
8
  class App
9
9
  module Types
10
- dry_types_version = Gem.loaded_specs['dry-types'].version
11
- if dry_types_version < Gem::Version.new('0.15.0')
12
- include Dry::Types.module
13
- else
14
- include Dry::Types()
15
- end
10
+ include Dry::Types()
16
11
  end
17
12
 
18
13
  def initialize(env:, hooks: {})
@@ -13,6 +13,7 @@ module Salestation
13
13
  @fields = []
14
14
  @field_error_types = {}
15
15
  @field_error_messages = {}
16
+ @expect_exact_match = false
16
17
  end
17
18
 
18
19
  def on(*nested_fields)
@@ -20,6 +21,11 @@ module Salestation
20
21
  self
21
22
  end
22
23
 
24
+ def exactly
25
+ @expect_exact_match = true
26
+ self
27
+ end
28
+
23
29
  def with_type(*types)
24
30
  @field_error_types[field_to_key(@fields.last)] = types
25
31
  self
@@ -31,15 +37,32 @@ module Salestation
31
37
  end
32
38
 
33
39
  def matches?(actual)
34
- @fields.all? do |field|
35
- check_field_exists(actual, *field) &&
36
- check_field_error_types(field, actual) &&
37
- check_field_error_messages(field, actual)
38
- end
40
+ check_exact_match(actual, self.class.path_list_to_trie(@fields)) &&
41
+ @fields.all? do |field|
42
+ check_field_exists(actual, *field) &&
43
+ check_field_error_types(field, actual) &&
44
+ check_field_error_messages(field, actual)
45
+ end
39
46
  end
40
47
 
41
48
  private
42
49
 
50
+ def check_exact_match(actual, field_trie)
51
+ return true unless @expect_exact_match
52
+
53
+ actual[:error_details].keys.all? do |key|
54
+ field_trie.any? do |field, nested_field_trie|
55
+ if nested_field_trie.empty?
56
+ field == key
57
+ else
58
+ actual[:error_details][field].all? do |nested_actual|
59
+ check_exact_match(nested_actual, nested_field_trie)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
43
66
  def check_field_exists(actual, field, *nested_fields)
44
67
  actual[:error_details].key?(field) &&
45
68
  (
@@ -80,6 +103,33 @@ module Salestation
80
103
  def field_to_key(fields)
81
104
  fields.join('->').to_sym
82
105
  end
106
+
107
+ class << self
108
+ # @example
109
+ # path_list_to_trie([[:a, :b, :c], [:a, :b, :d], [:a, :e]])
110
+ # #=> {a: {b: {c: {}, d: {}}, e: {}}}
111
+ def path_list_to_trie(paths)
112
+ paths.reduce({}) do |acc, path|
113
+ deep_merge(acc, path_to_trie(*path))
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ # @example
120
+ # path_to_trie(*[:a, :b, :c])
121
+ # #=> {a: {b: {c: {}}}}
122
+ def path_to_trie(element, *rest)
123
+ {element.to_sym => rest.empty? ? {} : path_to_trie(*rest)}
124
+ end
125
+
126
+ # @example
127
+ # deep_merge({a: {b: {c: {}}}}, {a: {b: {d: {}}, e: {}}})
128
+ # #=> {a: {b: {c: {}, d: {}}, e: {}}}
129
+ def deep_merge(a, b)
130
+ a.merge(b) { |_key, nested_a, nested_b| deep_merge(nested_a, nested_b) }
131
+ end
132
+ end
83
133
  end
84
134
  end
85
135
  end
@@ -31,6 +31,9 @@ module Salestation
31
31
  App::Errors::UnsupportedMediaType => -> (error) {
32
32
  Responses::UnsupportedMediaType.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
33
33
  },
34
+ App::Errors::BadRequest => -> (error) {
35
+ Responses::BadRequest.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
36
+ },
34
37
  App::Errors::RequestEntityTooLarge => -> (error) {
35
38
  Responses::RequestEntityTooLarge.new(message: error.message, debug_message: error.debug_message, base_error: error.base_error)
36
39
  }
@@ -61,14 +61,15 @@ module Salestation
61
61
  # Handles coercing input values
62
62
  #
63
63
  # @example
64
- # extractor = BodyParamExtractor[:x, :y]
64
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
65
65
  # .coerce(x: ->(value) { "x_#{value}"})
66
66
  # input = {
67
67
  # 'x' => 'a',
68
68
  # 'y' => 'b',
69
69
  # }
70
70
  # # rack_request is Rack::Request with 'rack.request.form_hash' set to input
71
- # extractor.call(rack_request).value #=> {x: 'x_a', y: 'b'}
71
+ # extractor.call(rack_request(input)).value
72
+ # #=> {x: 'x_a', y: 'b'}
72
73
  class InputCoercer
73
74
  def initialize(extractor, rules)
74
75
  @extractor = extractor
@@ -106,28 +107,25 @@ module Salestation
106
107
  # values can be compared in rename.
107
108
  #
108
109
  # @example
109
- # original_input = {
110
- # x: 'a',
111
- # y: 'b'
110
+ # input = {
111
+ # 'x' => 'a',
112
+ # 'y' => 'b'
112
113
  # }
113
114
  #
114
- # extractor = BodyParamExtractor[:x, :y]
115
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
115
116
  # .rename(x: :z)
116
- # input = {
117
- # z: 'a',
118
- # y: 'b'
119
- # }
117
+ # extractor.call(rack_request(input)).value
118
+ # #=> {z: 'a', y: 'b'}
120
119
  #
121
- # extractor = BodyParamExtractor[:x, :y]
120
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
122
121
  # .rename(x: :y)
123
- # input = {
124
- # y: 'b'
125
- # }
126
- # extractor = BodyParamExtractor[:x, :y]
122
+ # extractor.call(rack_request(input)).value
123
+ # #=> {y: 'b'}
124
+ #
125
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y]
127
126
  # .rename(x: {new_key: :y, override: true})
128
- # input = {
129
- # y: 'a'
130
- # }
127
+ # extractor.call(rack_request(input)).value
128
+ # #=> {y: 'a'}
131
129
  class InputRenamer
132
130
  def initialize(extractor, rules)
133
131
  @extractor = extractor
@@ -217,7 +215,7 @@ module Salestation
217
215
  # Extracts and symbolizes params from request body
218
216
  #
219
217
  # @example
220
- # extractor = BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}, :aaa]
218
+ # extractor = Salestation::Web::Extractors::BodyParamExtractor[:x, :y, {foo: [:bar, :baz]}, :aaa]
221
219
  # input = {
222
220
  # 'x' => '1',
223
221
  # 'y' => '2',
@@ -232,7 +230,8 @@ module Salestation
232
230
  # ]
233
231
  # }
234
232
  # # rack_request is Rack::Request with 'rack.request.form_hash' set to input
235
- # extractor.call(rack_request).value #=> {x: 1, y: 2, foo: {bar: 'qq'}, aaa: [{bb: 'cc'}]}
233
+ # extractor.call(rack_request(input)).value
234
+ # #=> {x: '1', y: '2', foo: {bar: 'qq'}, aaa: [{bb: 'cc'}]}
236
235
  #
237
236
  class BodyParamExtractor
238
237
  def self.[](*filters)
@@ -115,6 +115,7 @@ module Salestation
115
115
  Accepted = Success.with_code(202)
116
116
  NoContent = Success.with_code(204)
117
117
 
118
+ BadRequest = Error.with_code(400)
118
119
  Unauthorized = Error.with_code(401)
119
120
  Forbidden = Error.with_code(403)
120
121
  NotFound = Error.with_code(404)
@@ -8,12 +8,7 @@ require 'json'
8
8
  module Salestation
9
9
  class Web < Module
10
10
  module Types
11
- dry_types_version = Gem.loaded_specs['dry-types'].version
12
- if dry_types_version < Gem::Version.new('0.15.0')
13
- include Dry::Types.module
14
- else
15
- include Dry::Types()
16
- end
11
+ include Dry::Types()
17
12
  end
18
13
 
19
14
  def initialize(errors: {})
data/salestation.gemspec CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "salestation"
7
- spec.version = "5.3.1"
7
+ spec.version = "5.3.3"
8
8
  spec.authors = ["Glia TechMovers"]
9
- spec.email = ["techmovers@glia.com"]
9
+ spec.email = ["open-source@glia.com"]
10
10
 
11
11
  spec.summary = %q{}
12
12
  spec.description = %q{}
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 2.0"
23
23
  spec.add_development_dependency "rake", "~> 13.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
- spec.add_development_dependency "pry", "~> 0.10.4"
25
+ spec.add_development_dependency "pry", "~> 0.14.2"
26
26
  spec.add_development_dependency "glia-errors", "~> 0.11.4"
27
27
  spec.add_development_dependency "dry-validation", "~> 1.7"
28
+ spec.add_development_dependency "yard-doctest", "~> 0.1.17"
28
29
 
29
30
  spec.add_dependency 'deterministic'
30
31
  spec.add_dependency 'dry-struct'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salestation
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.1
4
+ version: 5.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.4
61
+ version: 0.14.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.10.4
68
+ version: 0.14.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: glia-errors
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard-doctest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.17
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.17
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: deterministic
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -166,7 +180,7 @@ dependencies:
166
180
  version: '0'
167
181
  description: ''
168
182
  email:
169
- - techmovers@glia.com
183
+ - open-source@glia.com
170
184
  executables: []
171
185
  extensions: []
172
186
  extra_rdoc_files: []
@@ -175,6 +189,8 @@ files:
175
189
  - ".github/workflows/ruby.yml"
176
190
  - ".gitignore"
177
191
  - ".rspec"
192
+ - ".yardopts"
193
+ - CONTRIBUTING.md
178
194
  - Gemfile
179
195
  - LICENSE.txt
180
196
  - README.md
@@ -204,7 +220,7 @@ homepage: ''
204
220
  licenses:
205
221
  - MIT
206
222
  metadata: {}
207
- post_install_message:
223
+ post_install_message:
208
224
  rdoc_options: []
209
225
  require_paths:
210
226
  - lib
@@ -219,8 +235,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
235
  - !ruby/object:Gem::Version
220
236
  version: '0'
221
237
  requirements: []
222
- rubygems_version: 3.1.6
223
- signing_key:
238
+ rubygems_version: 3.5.3
239
+ signing_key:
224
240
  specification_version: 4
225
241
  summary: ''
226
242
  test_files: []