daidan 0.1.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da756040fd2fcaebe748b6533b4216bcb25aae4a554c018e81e05380b4e721e4
4
- data.tar.gz: 634513d9b7ce3588e35155ddfaee1dfafa83ccac14b6b866d6373417d42ba4ee
3
+ metadata.gz: 7dc0f5d42394d742a6917422c54096702538d959efe4e88f2b8c9337ef8b737c
4
+ data.tar.gz: 3949477b36461799a0c135bca07ed02627d9d5f482bd7bdcac30ab7dacb07612
5
5
  SHA512:
6
- metadata.gz: a13f2d9507e15a8a8810e802766f25a614d9a005d424efe7413d9415a23b57a856a1a408099af54132103bcda77dc581a7fb8b2818c1b73c54237e7acf621aef
7
- data.tar.gz: e63537fab9ec1ad7d94b0f3d5191e211d66a46bd99a6eab7de6c72557146c0efee4551f7cc319b736a1f6f852b5043e7292881fa64dad31b39cb52ba09dac005
6
+ metadata.gz: 5c5e8a583d4df3a37d90d1b81ace49474488ba7872d8caa92ed1cce7dda6dc176915044a3fd7c8289ff14cde2254cb71a47f1dd1ca63ec9041bf29a79c2b359a
7
+ data.tar.gz: 3c80d8788e84979fe7917e94c83c50e771c2448b9830286c1384cb3a1af62e8c7159090fbb7680ef697463717d6325ab123e9e96e32673008226c3246e921402
data/CHANGELOG.md CHANGED
@@ -1,9 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## [0.1.0] - YYYY-MM-DD
3
+ ## [0.1.0] - 2024-12-19
4
4
 
5
5
  - Initial release with core features:
6
6
  - GraphQL schema support
7
7
  - Resource generator for models, migrations, and types
8
8
  - Middleware for JWT authentication
9
9
  - Database connection handling
10
+
11
+ ## [0.2.0] - 2025-01-12
12
+
13
+ - Improved core features:
14
+ - Added expiration date to JWT authentication mechanism
15
+ - Added hooks to Daidan::BaseMutation
16
+ - Added unit tests for Daidan::Application and generator classes
data/Gemfile CHANGED
@@ -9,5 +9,7 @@ gem 'dotenv'
9
9
  gem 'graphql'
10
10
  gem 'jwt'
11
11
  gem 'rake'
12
+ gem 'rack'
13
+ gem 'rspec'
12
14
  gem 'sequel'
13
15
  gem 'zeitwerk'
data/Gemfile.lock CHANGED
@@ -14,6 +14,7 @@ GEM
14
14
  base64 (0.2.0)
15
15
  bcrypt (3.1.20)
16
16
  bigdecimal (3.1.8)
17
+ diff-lcs (1.5.1)
17
18
  dotenv (3.1.7)
18
19
  fiber-storage (1.0.0)
19
20
  graphql (2.4.8)
@@ -21,7 +22,21 @@ GEM
21
22
  fiber-storage
22
23
  jwt (2.9.3)
23
24
  base64
25
+ rack (3.1.8)
24
26
  rake (13.2.1)
27
+ rspec (3.13.0)
28
+ rspec-core (~> 3.13.0)
29
+ rspec-expectations (~> 3.13.0)
30
+ rspec-mocks (~> 3.13.0)
31
+ rspec-core (3.13.2)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-expectations (3.13.3)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.13.0)
36
+ rspec-mocks (3.13.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.13.0)
39
+ rspec-support (3.13.2)
25
40
  sequel (5.87.0)
26
41
  bigdecimal
27
42
  zeitwerk (2.7.1)
@@ -36,7 +51,9 @@ DEPENDENCIES
36
51
  dotenv
37
52
  graphql
38
53
  jwt
54
+ rack
39
55
  rake
56
+ rspec
40
57
  sequel
41
58
  zeitwerk
42
59
 
data/daidan.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'daidan'
5
- spec.version = '0.1.0'
5
+ spec.version = '0.2.0'
6
6
  spec.authors = ['Bernard Cesarz']
7
7
  spec.email = ['cesarzb@protonmail.com']
8
8
 
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata['changelog_uri'] = 'https://github.com/cesarzb/daidan/blob/main/CHANGELOG.md'
17
17
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
18
  spec.metadata['license_uri'] = 'https://opensource.org/licenses/MIT'
19
+ spec.platform = Gem::Platform::RUBY
19
20
 
20
21
  spec.files = Dir.chdir(__dir__) do
21
22
  `git ls-files -z`.split("\x0").reject do |file|
@@ -1,4 +1,28 @@
1
1
  module Daidan
2
2
  class BaseMutation < GraphQL::Schema::Mutation
3
+ def resolve(**args)
4
+ call_hook(:before_mutation, **args)
5
+ result = execute_mutation(**args)
6
+ call_hook(:after_mutation, **args)
7
+ result
8
+ rescue StandardError => e
9
+ handle_error(e)
10
+ end
11
+
12
+ private
13
+
14
+ def execute_mutation(**_args)
15
+ raise NotImplementedError, 'Implement mutation logic.'
16
+ end
17
+
18
+ def call_hook(hook_name, **args)
19
+ return unless respond_to?(hook_name, true)
20
+
21
+ method(hook_name).arity == 0 ? send(hook_name) : send(hook_name, **args)
22
+ end
23
+
24
+ def handle_error(error)
25
+ raise GraphQL::ExecutionError, "Error occured during mutation: #{error.message}"
26
+ end
3
27
  end
4
28
  end
@@ -11,10 +11,17 @@ module Daidan
11
11
 
12
12
  raise GraphQL::ExecutionError, 'Invalid email or password' unless user && user.authenticate(password)
13
13
 
14
- payload = { user_id: user.id }
14
+ exp_time = Time.now.to_i + (24 * 60 * 60)
15
+ payload = {
16
+ user_id: user.id,
17
+ exp: exp_time
18
+ }
15
19
 
16
20
  token = JWT.encode(payload, ENV['JWT_SECRET'], 'HS256')
17
- { token: token, user: user }
21
+ {
22
+ token: token,
23
+ user: user
24
+ }
18
25
  end
19
26
  end
20
27
  end
@@ -7,12 +7,20 @@ module Daidan
7
7
 
8
8
  def call(env)
9
9
  auth_header = env['HTTP_AUTHORIZATION']
10
+
10
11
  if auth_header && auth_header.start_with?('Bearer ')
11
12
  token = auth_header.split(' ').last
12
-
13
13
  begin
14
- payload, = JWT.decode(token, ENV['JWT_SECRET'], true, { algorithm: 'HS256' })
14
+ payload, = JWT.decode(
15
+ token,
16
+ ENV['JWT_SECRET'],
17
+ true,
18
+ algorithm: 'HS256'
19
+ )
20
+
15
21
  env['current_user_id'] = payload['user_id']
22
+ rescue JWT::ExpiredSignature
23
+ env['current_user_id'] = nil
16
24
  rescue JWT::DecodeError
17
25
  env['current_user_id'] = nil
18
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daidan
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daidan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
- original_platform: ''
7
6
  authors:
8
7
  - Bernard Cesarz
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-18 00:00:00.000000000 Z
10
+ date: 2025-01-12 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bcrypt