trailblazer-endpoint 0.0.1 → 0.0.6

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +16 -0
  3. data/Appraisals +5 -0
  4. data/CHANGES.md +26 -0
  5. data/README.md +40 -5
  6. data/Rakefile +7 -1
  7. data/gemfiles/rails_app.gemfile +12 -0
  8. data/lib/trailblazer/endpoint.rb +29 -14
  9. data/lib/trailblazer/endpoint/adapter.rb +30 -121
  10. data/lib/trailblazer/endpoint/builder.rb +1 -1
  11. data/lib/trailblazer/endpoint/controller.rb +223 -0
  12. data/lib/trailblazer/endpoint/dsl.rb +29 -0
  13. data/lib/trailblazer/endpoint/options.rb +92 -0
  14. data/lib/trailblazer/endpoint/protocol.rb +5 -8
  15. data/lib/trailblazer/endpoint/version.rb +1 -1
  16. data/test/adapter/api_test.rb +6 -11
  17. data/test/adapter/web_test.rb +2 -5
  18. data/test/config_test.rb +128 -0
  19. data/test/docs/controller_test.rb +339 -58
  20. data/test/endpoint_test.rb +1 -1
  21. data/test/rails-app/.gitignore +8 -2
  22. data/test/rails-app/.ruby-version +1 -0
  23. data/test/rails-app/Gemfile +15 -9
  24. data/test/rails-app/Gemfile.lock +162 -121
  25. data/test/rails-app/app/concepts/app/api/v1/representer/errors.rb +16 -0
  26. data/test/rails-app/app/concepts/auth/jwt.rb +35 -0
  27. data/test/rails-app/app/concepts/auth/operation/authenticate.rb +32 -0
  28. data/test/rails-app/app/concepts/auth/operation/policy.rb +9 -0
  29. data/test/rails-app/app/concepts/song/cell/create.rb +4 -0
  30. data/test/rails-app/app/concepts/song/cell/new.rb +4 -0
  31. data/test/rails-app/app/concepts/song/operation/create.rb +17 -0
  32. data/test/rails-app/app/concepts/song/operation/show.rb +10 -0
  33. data/test/rails-app/app/concepts/song/representer.rb +5 -0
  34. data/test/rails-app/app/concepts/song/view/create.erb +1 -0
  35. data/test/rails-app/app/concepts/song/view/new.erb +1 -0
  36. data/test/rails-app/app/controllers/api/v1/songs_controller.rb +41 -0
  37. data/test/rails-app/app/controllers/application_controller.rb +8 -1
  38. data/test/rails-app/app/controllers/application_controller/api.rb +107 -0
  39. data/test/rails-app/app/controllers/application_controller/web.rb +44 -0
  40. data/test/rails-app/app/controllers/auth_controller.rb +44 -0
  41. data/test/rails-app/app/controllers/home_controller.rb +5 -0
  42. data/test/rails-app/app/controllers/songs_controller.rb +71 -13
  43. data/test/rails-app/app/models/song.rb +3 -0
  44. data/test/rails-app/app/models/user.rb +7 -0
  45. data/test/rails-app/bin/bundle +114 -0
  46. data/test/rails-app/bin/rails +4 -0
  47. data/test/rails-app/bin/rake +4 -0
  48. data/test/rails-app/bin/setup +33 -0
  49. data/test/rails-app/config/application.rb +26 -3
  50. data/test/rails-app/config/credentials.yml.enc +1 -0
  51. data/test/rails-app/config/database.yml +2 -2
  52. data/test/rails-app/config/environments/development.rb +7 -17
  53. data/test/rails-app/config/environments/production.rb +28 -23
  54. data/test/rails-app/config/environments/test.rb +8 -12
  55. data/test/rails-app/config/initializers/application_controller_renderer.rb +6 -4
  56. data/test/rails-app/config/initializers/cors.rb +16 -0
  57. data/test/rails-app/config/initializers/trailblazer.rb +2 -0
  58. data/test/rails-app/config/locales/en.yml +11 -1
  59. data/test/rails-app/config/master.key +1 -0
  60. data/test/rails-app/config/routes.rb +16 -4
  61. data/test/rails-app/db/schema.rb +15 -0
  62. data/test/rails-app/test/controllers/api_songs_controller_test.rb +87 -0
  63. data/test/rails-app/test/controllers/songs_controller_test.rb +80 -147
  64. data/test/rails-app/test/test_helper.rb +7 -1
  65. data/test/test_helper.rb +0 -2
  66. data/trailblazer-endpoint.gemspec +2 -1
  67. metadata +70 -22
  68. data/test/rails-app/config/initializers/cookies_serializer.rb +0 -5
  69. data/test/rails-app/config/initializers/new_framework_defaults.rb +0 -24
  70. data/test/rails-app/config/initializers/session_store.rb +0 -3
  71. data/test/rails-app/config/secrets.yml +0 -22
  72. data/test/rails-app/test/helpers/.keep +0 -0
  73. data/test/rails-app/test/integration/.keep +0 -0
  74. data/test/rails-app/test/mailers/.keep +0 -0
  75. data/test/rails-app/vendor/assets/javascripts/.keep +0 -0
  76. data/test/rails-app/vendor/assets/stylesheets/.keep +0 -0
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -1,17 +1,23 @@
1
1
  source 'https://rubygems.org'
2
-
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
- gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
5
+ gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
6
6
  # Use sqlite3 as the database for Active Record
7
- gem 'sqlite3'
7
+ gem 'sqlite3', '~> 1.4'
8
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
9
+ # gem 'jbuilder', '~> 2.7'
10
+ # Use Active Model has_secure_password
11
+ # gem 'bcrypt', '~> 3.1.7'
8
12
 
9
- # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
10
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
13
+ # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
14
+ # gem 'rack-cors'
11
15
 
16
+ gem "trailblazer-operation"
12
17
  gem "trailblazer-endpoint", path: "../../."
13
- gem "trailblazer", path: "../../../trailblazer"
14
- gem "trailblazer-operation", path: "../../../operation"
15
- # gem "trailblazer-rails"
16
-
18
+ gem "jwt"
17
19
  gem "multi_json"
20
+ gem "minitest-line"
21
+ gem "trailblazer-cells"
22
+ gem "cells-erb"
23
+ gem "cells-rails"
@@ -1,157 +1,198 @@
1
1
  PATH
2
- remote: ../../../operation
2
+ remote: ../..
3
3
  specs:
4
- trailblazer-operation (0.0.6)
5
- declarative
6
- pipetree (>= 0.0.4, < 0.1.0)
7
- uber (>= 0.1.0, < 0.2.0)
8
-
9
- PATH
10
- remote: ../../../trailblazer
11
- specs:
12
- trailblazer (2.0.0.beta1)
13
- declarative
14
- reform (>= 2.2.0, < 3.0.0)
15
- trailblazer-operation
16
- uber (>= 0.1.0, < 0.2.0)
17
-
18
- PATH
19
- remote: ../../.
20
- specs:
21
- trailblazer-endpoint (0.0.1)
22
- dry-matcher
4
+ trailblazer-endpoint (0.0.5)
5
+ trailblazer-activity-dsl-linear (>= 0.3.0, < 0.4.0)
23
6
 
24
7
  GEM
25
8
  remote: https://rubygems.org/
26
9
  specs:
27
- actioncable (5.0.0.1)
28
- actionpack (= 5.0.0.1)
29
- nio4r (~> 1.2)
30
- websocket-driver (~> 0.6.1)
31
- actionmailer (5.0.0.1)
32
- actionpack (= 5.0.0.1)
33
- actionview (= 5.0.0.1)
34
- activejob (= 5.0.0.1)
10
+ actioncable (6.0.3.2)
11
+ actionpack (= 6.0.3.2)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.3.2)
15
+ actionpack (= 6.0.3.2)
16
+ activejob (= 6.0.3.2)
17
+ activerecord (= 6.0.3.2)
18
+ activestorage (= 6.0.3.2)
19
+ activesupport (= 6.0.3.2)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.3.2)
22
+ actionpack (= 6.0.3.2)
23
+ actionview (= 6.0.3.2)
24
+ activejob (= 6.0.3.2)
35
25
  mail (~> 2.5, >= 2.5.4)
36
26
  rails-dom-testing (~> 2.0)
37
- actionpack (5.0.0.1)
38
- actionview (= 5.0.0.1)
39
- activesupport (= 5.0.0.1)
40
- rack (~> 2.0)
41
- rack-test (~> 0.6.3)
27
+ actionpack (6.0.3.2)
28
+ actionview (= 6.0.3.2)
29
+ activesupport (= 6.0.3.2)
30
+ rack (~> 2.0, >= 2.0.8)
31
+ rack-test (>= 0.6.3)
42
32
  rails-dom-testing (~> 2.0)
43
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
44
- actionview (5.0.0.1)
45
- activesupport (= 5.0.0.1)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.3.2)
35
+ actionpack (= 6.0.3.2)
36
+ activerecord (= 6.0.3.2)
37
+ activestorage (= 6.0.3.2)
38
+ activesupport (= 6.0.3.2)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.3.2)
41
+ activesupport (= 6.0.3.2)
46
42
  builder (~> 3.1)
47
- erubis (~> 2.7.0)
43
+ erubi (~> 1.4)
48
44
  rails-dom-testing (~> 2.0)
49
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
50
- activejob (5.0.0.1)
51
- activesupport (= 5.0.0.1)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.3.2)
47
+ activesupport (= 6.0.3.2)
52
48
  globalid (>= 0.3.6)
53
- activemodel (5.0.0.1)
54
- activesupport (= 5.0.0.1)
55
- activerecord (5.0.0.1)
56
- activemodel (= 5.0.0.1)
57
- activesupport (= 5.0.0.1)
58
- arel (~> 7.0)
59
- activesupport (5.0.0.1)
49
+ activemodel (6.0.3.2)
50
+ activesupport (= 6.0.3.2)
51
+ activerecord (6.0.3.2)
52
+ activemodel (= 6.0.3.2)
53
+ activesupport (= 6.0.3.2)
54
+ activestorage (6.0.3.2)
55
+ actionpack (= 6.0.3.2)
56
+ activejob (= 6.0.3.2)
57
+ activerecord (= 6.0.3.2)
58
+ marcel (~> 0.3.1)
59
+ activesupport (6.0.3.2)
60
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (~> 0.7)
61
+ i18n (>= 0.7, < 2)
62
62
  minitest (~> 5.1)
63
63
  tzinfo (~> 1.1)
64
- arel (7.1.4)
65
- builder (3.2.2)
66
- concurrent-ruby (1.0.2)
67
- declarative (0.0.8)
68
- uber (>= 0.0.15)
69
- disposable (0.3.2)
70
- declarative (>= 0.0.8, < 1.0.0)
71
- representable (>= 2.4.0, <= 3.1.0)
72
- uber
73
- dry-matcher (0.5.0)
74
- erubis (2.7.0)
75
- globalid (0.3.7)
76
- activesupport (>= 4.1.0)
77
- i18n (0.7.0)
78
- loofah (2.0.3)
64
+ zeitwerk (~> 2.2, >= 2.2.2)
65
+ builder (3.2.4)
66
+ cells (4.1.7)
67
+ declarative-builder (< 0.2.0)
68
+ declarative-option (< 0.2.0)
69
+ tilt (>= 1.4, < 3)
70
+ uber (< 0.2.0)
71
+ cells-erb (0.1.0)
72
+ cells (~> 4.0)
73
+ erbse (>= 0.1.1)
74
+ cells-rails (0.1.1)
75
+ actionpack (>= 5.0)
76
+ cells (>= 4.1.6, < 5.0.0)
77
+ concurrent-ruby (1.1.7)
78
+ crass (1.0.6)
79
+ declarative (0.0.20)
80
+ declarative-builder (0.1.0)
81
+ declarative-option (< 0.2.0)
82
+ declarative-option (0.1.0)
83
+ erbse (0.1.4)
84
+ temple
85
+ erubi (1.9.0)
86
+ globalid (0.4.2)
87
+ activesupport (>= 4.2.0)
88
+ hashie (4.1.0)
89
+ hirb (0.7.3)
90
+ i18n (1.8.5)
91
+ concurrent-ruby (~> 1.0)
92
+ jwt (2.2.2)
93
+ loofah (2.7.0)
94
+ crass (~> 1.0.2)
79
95
  nokogiri (>= 1.5.9)
80
- mail (2.6.4)
81
- mime-types (>= 1.16, < 4)
82
- method_source (0.8.2)
83
- mime-types (3.1)
84
- mime-types-data (~> 3.2015)
85
- mime-types-data (3.2016.0521)
86
- mini_portile2 (2.1.0)
87
- minitest (5.9.1)
88
- multi_json (1.12.1)
89
- nio4r (1.2.1)
90
- nokogiri (1.6.8.1)
91
- mini_portile2 (~> 2.1.0)
92
- pipetree (0.0.4)
93
- rack (2.0.1)
94
- rack-test (0.6.3)
95
- rack (>= 1.0)
96
- rails (5.0.0.1)
97
- actioncable (= 5.0.0.1)
98
- actionmailer (= 5.0.0.1)
99
- actionpack (= 5.0.0.1)
100
- actionview (= 5.0.0.1)
101
- activejob (= 5.0.0.1)
102
- activemodel (= 5.0.0.1)
103
- activerecord (= 5.0.0.1)
104
- activesupport (= 5.0.0.1)
105
- bundler (>= 1.3.0, < 2.0)
106
- railties (= 5.0.0.1)
96
+ mail (2.7.1)
97
+ mini_mime (>= 0.1.1)
98
+ marcel (0.3.3)
99
+ mimemagic (~> 0.3.2)
100
+ method_source (1.0.0)
101
+ mimemagic (0.3.5)
102
+ mini_mime (1.0.2)
103
+ mini_portile2 (2.4.0)
104
+ minitest (5.14.2)
105
+ minitest-line (0.6.5)
106
+ minitest (~> 5.0)
107
+ multi_json (1.15.0)
108
+ nio4r (2.5.2)
109
+ nokogiri (1.10.10)
110
+ mini_portile2 (~> 2.4.0)
111
+ rack (2.2.3)
112
+ rack-test (1.1.0)
113
+ rack (>= 1.0, < 3)
114
+ rails (6.0.3.2)
115
+ actioncable (= 6.0.3.2)
116
+ actionmailbox (= 6.0.3.2)
117
+ actionmailer (= 6.0.3.2)
118
+ actionpack (= 6.0.3.2)
119
+ actiontext (= 6.0.3.2)
120
+ actionview (= 6.0.3.2)
121
+ activejob (= 6.0.3.2)
122
+ activemodel (= 6.0.3.2)
123
+ activerecord (= 6.0.3.2)
124
+ activestorage (= 6.0.3.2)
125
+ activesupport (= 6.0.3.2)
126
+ bundler (>= 1.3.0)
127
+ railties (= 6.0.3.2)
107
128
  sprockets-rails (>= 2.0.0)
108
- rails-dom-testing (2.0.1)
109
- activesupport (>= 4.2.0, < 6.0)
110
- nokogiri (~> 1.6.0)
111
- rails-html-sanitizer (1.0.3)
112
- loofah (~> 2.0)
113
- railties (5.0.0.1)
114
- actionpack (= 5.0.0.1)
115
- activesupport (= 5.0.0.1)
129
+ rails-dom-testing (2.0.3)
130
+ activesupport (>= 4.2.0)
131
+ nokogiri (>= 1.6)
132
+ rails-html-sanitizer (1.3.0)
133
+ loofah (~> 2.3)
134
+ railties (6.0.3.2)
135
+ actionpack (= 6.0.3.2)
136
+ activesupport (= 6.0.3.2)
116
137
  method_source
117
138
  rake (>= 0.8.7)
118
- thor (>= 0.18.1, < 2.0)
119
- rake (11.3.0)
120
- reform (2.2.3)
121
- disposable (>= 0.3.0, < 0.4.0)
122
- representable (>= 2.4.0, < 3.1.0)
123
- uber (>= 0.0.15, < 0.2.0)
124
- representable (3.0.2)
125
- declarative (~> 0.0.5)
126
- uber (>= 0.0.15, < 0.2.0)
127
- sprockets (3.7.0)
139
+ thor (>= 0.20.3, < 2.0)
140
+ rake (13.0.1)
141
+ representable (3.0.4)
142
+ declarative (< 0.1.0)
143
+ declarative-option (< 0.2.0)
144
+ uber (< 0.2.0)
145
+ sprockets (4.0.2)
128
146
  concurrent-ruby (~> 1.0)
129
147
  rack (> 1, < 3)
130
- sprockets-rails (3.2.0)
148
+ sprockets-rails (3.2.1)
131
149
  actionpack (>= 4.0)
132
150
  activesupport (>= 4.0)
133
151
  sprockets (>= 3.0.0)
134
- sqlite3 (1.3.12)
135
- thor (0.19.1)
136
- thread_safe (0.3.5)
137
- tzinfo (1.2.2)
152
+ sqlite3 (1.4.2)
153
+ temple (0.8.2)
154
+ thor (1.0.1)
155
+ thread_safe (0.3.6)
156
+ tilt (2.0.10)
157
+ trailblazer-activity (0.11.3)
158
+ trailblazer-context (>= 0.3.1, < 0.4.0)
159
+ trailblazer-activity-dsl-linear (0.3.2)
160
+ trailblazer-activity (>= 0.11.2, < 1.0.0)
161
+ trailblazer-cells (0.0.3)
162
+ cells (>= 4.1.0.rc1, < 5.0.0)
163
+ trailblazer-context (0.3.1)
164
+ hashie (~> 4.1)
165
+ trailblazer-developer (0.0.16)
166
+ hirb
167
+ representable
168
+ trailblazer-activity (>= 0.11.0, < 1.0.0)
169
+ trailblazer-activity-dsl-linear
170
+ trailblazer-operation (0.6.5)
171
+ trailblazer-activity (>= 0.11.2, < 1.0.0)
172
+ trailblazer-activity-dsl-linear (>= 0.3.2, < 1.0.0)
173
+ trailblazer-developer (>= 0.0.8)
174
+ tzinfo (1.2.7)
138
175
  thread_safe (~> 0.1)
139
176
  uber (0.1.0)
140
- websocket-driver (0.6.4)
177
+ websocket-driver (0.7.3)
141
178
  websocket-extensions (>= 0.1.0)
142
- websocket-extensions (0.1.2)
179
+ websocket-extensions (0.1.5)
180
+ zeitwerk (2.4.0)
143
181
 
144
182
  PLATFORMS
145
183
  ruby
146
184
 
147
185
  DEPENDENCIES
186
+ cells-erb
187
+ cells-rails
188
+ jwt
189
+ minitest-line
148
190
  multi_json
149
- rails (~> 5.0.0, >= 5.0.0.1)
150
- sqlite3
151
- trailblazer!
191
+ rails (~> 6.0.3, >= 6.0.3.1)
192
+ sqlite3 (~> 1.4)
193
+ trailblazer-cells
152
194
  trailblazer-endpoint!
153
- trailblazer-operation!
154
- tzinfo-data
195
+ trailblazer-operation
155
196
 
156
197
  BUNDLED WITH
157
- 1.12.5
198
+ 2.1.4
@@ -0,0 +1,16 @@
1
+ module App
2
+ module Api
3
+ module V1
4
+ module Representer
5
+ class Errors < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ self.representation_wrap= :errors
9
+
10
+ property :message
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'date'
2
+ require "jwt"
3
+
4
+ # Thanks to pocketrocket GmbH for providing this sample code.
5
+ module Auth
6
+ class Jwt
7
+ # Generate a JWT from arguments
8
+ def self.generate(encoding_key, encoding_value, payload)
9
+ # expiration_time = Rails.application.credentials[:jwt_expiration_time].hours.from_now.to_i # TODO: show how to inject config options
10
+ expiration_time = 1.hours.from_now.to_i
11
+ payload['exp'] = expiration_time
12
+ jwt = JWT.encode(payload,
13
+ Rails.application.credentials[:secret_key_base], 'HS512',
14
+ { exp: expiration_time, encoding_key.to_sym => encoding_value }
15
+ )
16
+ return jwt
17
+ end
18
+
19
+ # Validate tokens expiration date
20
+ def self.expired?(token)
21
+ decoded_token = JwtService.decode(token)
22
+ expiry_timestamp = decoded_token.first['exp']
23
+ expiration_date = Time.at(expiry_timestamp).to_datetime
24
+ return DateTime.now > expiration_date
25
+ rescue => err
26
+ return true
27
+ end
28
+
29
+ def self.decode(token)
30
+ JWT.decode(token, Rails.application.credentials[:secret_key_base], true, { algorithm: 'HS512'})
31
+ rescue => err # FIXME: is there any way to call {JWT.decode} without an exception?
32
+ nil
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # FIXME: this is not final, yet!
2
+ class Auth::Operation::Authenticate < Trailblazer::Activity::Railway
3
+ step :verify_token
4
+ step :is_token_expired?
5
+ step :set_current_user
6
+
7
+ def verify_token(ctx, request:, **)
8
+ auth_header = request.headers['Authorization'] || ""
9
+ jwt_encoded_token = auth_header.split(' ').last
10
+ ctx[:encoded_jwt_token] = jwt_encoded_token
11
+
12
+ # FIXME
13
+ #raise StandardError if JwtService.expired?(jwt_encoded_token)
14
+ ctx[:decoded_jwt_token] = Auth::Jwt.decode(jwt_encoded_token)
15
+ end
16
+
17
+ def is_token_expired?(ctx, decoded_jwt_token:, **)
18
+ expiration_integer = decoded_jwt_token.first['exp']
19
+ return false if expiration_integer.nil?
20
+ return false if (expiration_integer - DateTime.now.to_i) <= 0
21
+ return true
22
+ end
23
+
24
+ def set_current_user(ctx, decoded_jwt_token:, **)
25
+ user_id = decoded_jwt_token.first['user_id']
26
+
27
+ ctx[:current_user] = User.find_by(
28
+ id: user_id
29
+ )
30
+ true # FIXME
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module Auth
2
+ module Operation
3
+ class Policy
4
+ def self.call(ctx, domain_ctx:, **)
5
+ domain_ctx[:params][:policy] == false ? false : true
6
+ end
7
+ end
8
+ end
9
+ end