salestation 5.3.1 → 5.3.3
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 +4 -4
- data/.github/workflows/publish.yml +3 -2
- data/.github/workflows/ruby.yml +3 -5
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +9 -0
- data/Rakefile +10 -3
- data/lib/salestation/app/errors.rb +5 -0
- data/lib/salestation/app.rb +1 -6
- data/lib/salestation/rspec/glia_input_validation_error_matcher.rb +55 -5
- data/lib/salestation/web/error_mapper.rb +3 -0
- data/lib/salestation/web/extractors.rb +19 -20
- data/lib/salestation/web/responses.rb +1 -0
- data/lib/salestation/web.rb +1 -6
- data/salestation.gemspec +4 -3
- metadata +25 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67e18c608d03d9fa6f1e3cff2345dd87eb55f76d7e087e57a75c4ce2b6f591f
|
4
|
+
data.tar.gz: '086a420e0dcd1483b346253be2d3a18405f02ee310956ae69501dd47832a1800'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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@
|
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
|
data/.github/workflows/ruby.yml
CHANGED
@@ -15,15 +15,13 @@ jobs:
|
|
15
15
|
runs-on: ubuntu-latest
|
16
16
|
strategy:
|
17
17
|
matrix:
|
18
|
-
ruby-version: ['2.
|
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
|
-
|
24
|
-
|
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
|
-
|
2
|
-
|
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
|
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
|
data/lib/salestation/app.rb
CHANGED
@@ -7,12 +7,7 @@ require 'dry-types'
|
|
7
7
|
module Salestation
|
8
8
|
class App
|
9
9
|
module Types
|
10
|
-
|
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
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
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
|
-
#
|
110
|
-
# x
|
111
|
-
# y
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
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)
|
data/lib/salestation/web.rb
CHANGED
@@ -8,12 +8,7 @@ require 'json'
|
|
8
8
|
module Salestation
|
9
9
|
class Web < Module
|
10
10
|
module Types
|
11
|
-
|
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.
|
7
|
+
spec.version = "5.3.3"
|
8
8
|
spec.authors = ["Glia TechMovers"]
|
9
|
-
spec.email = ["
|
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.
|
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.
|
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-
|
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.
|
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.
|
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
|
-
-
|
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.
|
223
|
-
signing_key:
|
238
|
+
rubygems_version: 3.5.3
|
239
|
+
signing_key:
|
224
240
|
specification_version: 4
|
225
241
|
summary: ''
|
226
242
|
test_files: []
|