jets 3.0.11 → 3.0.15
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/CHANGELOG.md +19 -0
- data/lib/jets/builders/md5_zip.rb +2 -2
- data/lib/jets/commands/help/delete.md +2 -2
- data/lib/jets/commands/new.rb +8 -1
- data/lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt +3 -2
- data/lib/jets/controller/middleware/local/route_matcher.rb +3 -3
- data/lib/jets/controller/middleware/local.rb +1 -0
- data/lib/jets/controller/redirection.rb +1 -10
- data/lib/jets/controller/rendering.rb +17 -4
- data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +1 -1
- data/lib/jets/internal/app/functions/jets/base_path_mapping.rb +19 -0
- data/lib/jets/middleware/default_stack.rb +3 -1
- data/lib/jets/overrides/rails/url_helper.rb +4 -1
- data/lib/jets/version.rb +1 -1
- metadata +2 -3
- data/lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js +0 -90
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 58e203dbd0ee79c9e7287badab576597b08f0b3f5fd3f1b5309bfa910cbf2858
         | 
| 4 | 
            +
              data.tar.gz: 1a29ba9a72f042b156312d47acdeebee565f6dc4a5c3d3ee109931723e59b583
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6c6f2d06e54b0837f30c9a064e48252330a72a770b1b0f51e1884ab4820291220565b696f505cfe5645a3de2d428a3c380bc2c7f8d8873ae8819f2f5f0c0a6ef
         | 
| 7 | 
            +
              data.tar.gz: 95a8262ad30c8a593a2c23fed954528e4d0801cd8260ae81e7c974f89d1e8c05c34c3778a7422f356de30c410bae9a9313ebf677e440d7b06d379aa7580421f8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -3,6 +3,25 @@ | |
| 3 3 | 
             
            All notable changes to this project will be documented in this file.
         | 
| 4 4 | 
             
            This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
         | 
| 5 5 |  | 
| 6 | 
            +
            ## [3.0.15] - 2021-09-05
         | 
| 7 | 
            +
            - [#587](https://github.com/boltops-tools/jets/pull/587) Fix private method names
         | 
| 8 | 
            +
            - [#588](https://github.com/boltops-tools/jets/pull/588) custom domain: adjust rate limit for base mapping
         | 
| 9 | 
            +
            - [#589](https://github.com/boltops-tools/jets/pull/589) Ujs
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## [3.0.14] - 2021-09-01
         | 
| 12 | 
            +
            - [#583](https://github.com/boltops-tools/jets/pull/583) Don't overwrite content_type  when rendering json or xml with content_type specified
         | 
| 13 | 
            +
            - [#584](https://github.com/boltops-tools/jets/pull/584) Adds an override flag to change behaviour when Jets is behind an ELB running Jets Server
         | 
| 14 | 
            +
            - [#585](https://github.com/boltops-tools/jets/pull/585) add_stage controller method
         | 
| 15 | 
            +
            - [#586](https://github.com/boltops-tools/jets/pull/586) JETS_ELB env var flag
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## [3.0.13] - 2021-08-17
         | 
| 18 | 
            +
            - [#582](https://github.com/boltops-tools/jets/pull/582) use Shotgun::Static middleware always
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ## [3.0.12] - 2021-08-08
         | 
| 21 | 
            +
            - [#578](https://github.com/boltops-tools/jets/pull/578) Update "jets delete" documentation to be --yes instead of --skip
         | 
| 22 | 
            +
            - [#580](https://github.com/boltops-tools/jets/pull/580) Use active support instead of actionview
         | 
| 23 | 
            +
            - [#581](https://github.com/boltops-tools/jets/pull/581) Csrf csrf-param authenticity_token and use @rails/ujs for crud
         | 
| 24 | 
            +
             | 
| 6 25 | 
             
            ## [3.0.11] - 2021-07-15
         | 
| 7 26 | 
             
            - update serverlessgems gem
         | 
| 8 27 |  | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            require  | 
| 1 | 
            +
            require "active_support/number_helper"
         | 
| 2 2 |  | 
| 3 3 | 
             
            # Examples:
         | 
| 4 4 | 
             
            #
         | 
| @@ -10,7 +10,7 @@ require 'action_view' | |
| 10 10 | 
             
            #
         | 
| 11 11 | 
             
            module Jets::Builders
         | 
| 12 12 | 
             
              class Md5Zip
         | 
| 13 | 
            -
                include  | 
| 13 | 
            +
                include ActiveSupport::NumberHelper # number_to_human_size
         | 
| 14 14 | 
             
                include Util
         | 
| 15 15 |  | 
| 16 16 | 
             
                def initialize(folder)
         | 
| @@ -17,6 +17,6 @@ This deletes the all the contents in the internal s3 bucket that jets uses and t | |
| 17 17 | 
             
                Project demo-dev deleted!
         | 
| 18 18 | 
             
                $
         | 
| 19 19 |  | 
| 20 | 
            -
            You can bypass the are you sure prompt with the `-- | 
| 20 | 
            +
            You can bypass the are you sure prompt with the `--yes` flag.
         | 
| 21 21 |  | 
| 22 | 
            -
                $ jets delete -- | 
| 22 | 
            +
                $ jets delete --yes
         | 
    
        data/lib/jets/commands/new.rb
    CHANGED
    
    | @@ -114,7 +114,14 @@ JS | |
| 114 114 | 
             
                  after = "const { environment } = require('@rails/webpacker')\n"
         | 
| 115 115 | 
             
                  insert_into_file("config/webpack/environment.js", jquery, after: after)
         | 
| 116 116 |  | 
| 117 | 
            -
                   | 
| 117 | 
            +
                  jets_ujs =<<-JS
         | 
| 118 | 
            +
            import Jets from "@rubyonjets/ujs-compat"
         | 
| 119 | 
            +
            Jets.start()
         | 
| 120 | 
            +
            JS
         | 
| 121 | 
            +
                  after = "Rails.start()\n"
         | 
| 122 | 
            +
                  insert_into_file("app/javascript/packs/application.js", jets_ujs, after: after)
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  run("yarn add bootstrap jquery popper.js postcss-cssnext @rails/ujs @rubyonjets/ujs-compat")
         | 
| 118 125 | 
             
                end
         | 
| 119 126 |  | 
| 120 127 | 
             
                def git_init
         | 
| @@ -5,17 +5,17 @@ class Jets::Controller::Middleware::Local | |
| 5 5 | 
             
                end
         | 
| 6 6 |  | 
| 7 7 | 
             
                def find_route
         | 
| 8 | 
            -
                  Jets::Router::Finder.new( | 
| 8 | 
            +
                  Jets::Router::Finder.new(path, method).run
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 11 | 
             
              private
         | 
| 12 12 | 
             
                attr_reader :env
         | 
| 13 13 |  | 
| 14 | 
            -
                def  | 
| 14 | 
            +
                def method
         | 
| 15 15 | 
             
                  env["REQUEST_METHOD"] || "GET"
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 | 
            -
                def  | 
| 18 | 
            +
                def path
         | 
| 19 19 | 
             
                  env["PATH_INFO"].sub(/^\//,'')
         | 
| 20 20 | 
             
                end
         | 
| 21 21 | 
             
              end
         | 
| @@ -70,6 +70,7 @@ module Jets::Controller::Middleware | |
| 70 70 |  | 
| 71 71 | 
             
                def on_aws?(env)
         | 
| 72 72 | 
             
                  return false if Jets.env.test? # usually with test we're passing in full API Gateway fixtures with the HTTP_X_AMZN_TRACE_ID
         | 
| 73 | 
            +
                  return false if ENV['JETS_ELB'] # If we're using an ELB and Jets is inside a container running jets server, we don't want to pretend we're on AWS.
         | 
| 73 74 | 
             
                  on_cloud9 = !!(env['HTTP_HOST'] =~ /cloud9\..*\.amazonaws\.com/)
         | 
| 74 75 | 
             
                  !!env['HTTP_X_AMZN_TRACE_ID'] && !on_cloud9
         | 
| 75 76 | 
             
                end
         | 
| @@ -7,16 +7,7 @@ class Jets::Controller | |
| 7 7 | 
             
                    raise "redirect_to url parameter must be a String. Please pass in a string"
         | 
| 8 8 | 
             
                  end
         | 
| 9 9 |  | 
| 10 | 
            -
                   | 
| 11 | 
            -
                  # if no location.host, we been provided a relative host
         | 
| 12 | 
            -
                  if !uri.host && actual_host
         | 
| 13 | 
            -
                    url = "/#{url}" unless url.starts_with?('/')
         | 
| 14 | 
            -
                    url = add_stage_name(url)
         | 
| 15 | 
            -
                    redirect_url = actual_host + url
         | 
| 16 | 
            -
                  else
         | 
| 17 | 
            -
                    redirect_url = url
         | 
| 18 | 
            -
                  end
         | 
| 19 | 
            -
             | 
| 10 | 
            +
                  redirect_url = add_stage(url)
         | 
| 20 11 | 
             
                  redirect_url = ensure_protocol(redirect_url)
         | 
| 21 12 |  | 
| 22 13 | 
             
                  aws_proxy = Rendering::RackRenderer.new(self,
         | 
| @@ -33,6 +33,8 @@ class Jets::Controller | |
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 35 | 
             
                def adjust_content_type!(options)
         | 
| 36 | 
            +
                  return if options.key?(:content_type)
         | 
| 37 | 
            +
             | 
| 36 38 | 
             
                  if options.key?(:json)
         | 
| 37 39 | 
             
                    options[:content_type] = "application/json"
         | 
| 38 40 | 
             
                  elsif options.key?(:xml)
         | 
| @@ -60,15 +62,26 @@ class Jets::Controller | |
| 60 62 | 
             
                  rest.merge(template: template)
         | 
| 61 63 | 
             
                end
         | 
| 62 64 |  | 
| 63 | 
            -
                #  | 
| 64 | 
            -
                 | 
| 65 | 
            +
                # Example usage:
         | 
| 66 | 
            +
                #
         | 
| 67 | 
            +
                #   render json: {success: true, location: add_stage(posts_path)}
         | 
| 68 | 
            +
                #
         | 
| 69 | 
            +
                def add_stage(url)
         | 
| 65 70 | 
             
                  return url unless actual_host
         | 
| 66 71 |  | 
| 67 | 
            -
                   | 
| 72 | 
            +
                  uri = URI.parse(url)
         | 
| 73 | 
            +
                  # if no location.host, we been provided a relative host
         | 
| 74 | 
            +
                  if !uri.host && actual_host
         | 
| 75 | 
            +
                    url = "/#{url}" unless url.starts_with?('/')
         | 
| 76 | 
            +
                    url = Jets::Controller::Stage.add(actual_host, url)
         | 
| 77 | 
            +
                    actual_host + url
         | 
| 78 | 
            +
                  else
         | 
| 79 | 
            +
                    url
         | 
| 80 | 
            +
                  end
         | 
| 68 81 | 
             
                end
         | 
| 69 82 |  | 
| 70 83 | 
             
                def url_for(url)
         | 
| 71 | 
            -
                   | 
| 84 | 
            +
                  add_stage(url)
         | 
| 72 85 | 
             
                end
         | 
| 73 86 |  | 
| 74 87 | 
             
                # Actual host can be headers["origin"] when cloudfront is in front.
         | 
| @@ -56,7 +56,7 @@ class <%= controller_class_name %>Controller < ApplicationController | |
| 56 56 | 
             
              def delete
         | 
| 57 57 | 
             
                @<%= orm_instance.destroy %>
         | 
| 58 58 | 
             
                if request.xhr?
         | 
| 59 | 
            -
                  render json: {success: true}
         | 
| 59 | 
            +
                  render json: {success: true, location: <%= table_name %>_path}
         | 
| 60 60 | 
             
                else
         | 
| 61 61 | 
             
                  redirect_to <%= table_name %>_path
         | 
| 62 62 | 
             
                end
         | 
| @@ -4,6 +4,25 @@ require 'aws-sdk-cloudformation' | |
| 4 4 | 
             
            class BasePathMapping
         | 
| 5 5 | 
             
              def initialize(event, stage_name)
         | 
| 6 6 | 
             
                @event, @stage_name = event, stage_name
         | 
| 7 | 
            +
                aws_config_update!
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              # Override the AWS retry settings. The aws-sdk-core has expondential backup with this formula:
         | 
| 11 | 
            +
              #
         | 
| 12 | 
            +
              #   2 ** c.retries * c.config.retry_base_delay
         | 
| 13 | 
            +
              #
         | 
| 14 | 
            +
              # So the max delay will be 2 ** 7 * 0.6 = 76.8s
         | 
| 15 | 
            +
              #
         | 
| 16 | 
            +
              # Useful links:
         | 
| 17 | 
            +
              #
         | 
| 18 | 
            +
              #   https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
         | 
| 19 | 
            +
              #   https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
         | 
| 20 | 
            +
              #
         | 
| 21 | 
            +
              def aws_config_update!
         | 
| 22 | 
            +
                Aws.config.update(
         | 
| 23 | 
            +
                  retry_limit: 7, # default: 3
         | 
| 24 | 
            +
                  retry_base_delay: 0.6, # default: 0.3
         | 
| 25 | 
            +
                )
         | 
| 7 26 | 
             
              end
         | 
| 8 27 |  | 
| 9 28 | 
             
              # Cannot use update_base_path_mapping to update the base_mapping because it doesnt
         | 
| @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            require "shotgun"
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Jets::Middleware
         | 
| 2 4 | 
             
              class DefaultStack
         | 
| 3 5 | 
             
                attr_reader :config, :app
         | 
| @@ -8,7 +10,7 @@ module Jets::Middleware | |
| 8 10 |  | 
| 9 11 | 
             
                def build_stack
         | 
| 10 12 | 
             
                  Stack.new do |middleware|
         | 
| 11 | 
            -
                    middleware.use Shotgun::Static | 
| 13 | 
            +
                    middleware.use Shotgun::Static
         | 
| 12 14 | 
             
                    middleware.use Rack::Runtime
         | 
| 13 15 | 
             
                    middleware.use Jets::Controller::Middleware::Cors if cors_enabled?
         | 
| 14 16 | 
             
                    middleware.use Rack::MethodOverride # must come before Middleware::Local for multipart post forms to work
         | 
| @@ -77,7 +77,10 @@ module Jets::UrlHelper | |
| 77 77 |  | 
| 78 78 | 
             
              def csrf_meta_tags
         | 
| 79 79 | 
             
                if protect_against_forgery?
         | 
| 80 | 
            -
                  tag("meta", name: "csrf-token", content: masked_authenticity_token).html_safe
         | 
| 80 | 
            +
                  html = tag("meta", name: "csrf-token", content: masked_authenticity_token).html_safe
         | 
| 81 | 
            +
                  html << "\n"
         | 
| 82 | 
            +
                  html << tag("meta", name: "csrf-param", content: "authenticity_token").html_safe
         | 
| 83 | 
            +
                  html
         | 
| 81 84 | 
             
                end
         | 
| 82 85 | 
             
              end
         | 
| 83 86 | 
             
            end # UrlHelper
         | 
    
        data/lib/jets/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jets
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 3.0. | 
| 4 | 
            +
              version: 3.0.15
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Tung Nguyen
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-09-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: actionmailer
         | 
| @@ -776,7 +776,6 @@ files: | |
| 776 776 | 
             
            - lib/jets/commands/templates/skeleton/spec/spec_helper.rb.tt
         | 
| 777 777 | 
             
            - lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt
         | 
| 778 778 | 
             
            - lib/jets/commands/templates/webpacker/app/javascript/packs/theme.scss.tt
         | 
| 779 | 
            -
            - lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js
         | 
| 780 779 | 
             
            - lib/jets/commands/upgrade.rb
         | 
| 781 780 | 
             
            - lib/jets/commands/upgrade/templates/bin/webpack
         | 
| 782 781 | 
             
            - lib/jets/commands/upgrade/templates/bin/webpack-dev-server
         | 
| @@ -1,90 +0,0 @@ | |
| 1 | 
            -
            // This file is automatically generated by Jets. It is used by
         | 
| 2 | 
            -
            // app/javascript/packs/application.js.
         | 
| 3 | 
            -
            //
         | 
| 4 | 
            -
            // It handles the delete and update action in an unobstrusive way.
         | 
| 5 | 
            -
            // Code could be improved and is meant to provide only a starting point.
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            $(function() {
         | 
| 8 | 
            -
              function handleAll(e) {
         | 
| 9 | 
            -
                var target = $(e.target);
         | 
| 10 | 
            -
                if (target.is('a') && target.data("method") == "delete") {
         | 
| 11 | 
            -
                  return handleDelete(e);
         | 
| 12 | 
            -
                } else if (target.attr('type') == "submit") {
         | 
| 13 | 
            -
                  return handleUpdate(e);
         | 
| 14 | 
            -
                } else {
         | 
| 15 | 
            -
                  return true;
         | 
| 16 | 
            -
                }
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                e.preventDefault();
         | 
| 19 | 
            -
              }
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              function handleDelete(e) {
         | 
| 22 | 
            -
                event.preventDefault();
         | 
| 23 | 
            -
                var link = $(e.target);
         | 
| 24 | 
            -
                var message = link.data("confirm");
         | 
| 25 | 
            -
                if (message) {
         | 
| 26 | 
            -
                  var sure = confirm(message);
         | 
| 27 | 
            -
                  if (sure) {
         | 
| 28 | 
            -
                    deleteItem(link);
         | 
| 29 | 
            -
                  } else {
         | 
| 30 | 
            -
                    console.log("Deletion cancelled");
         | 
| 31 | 
            -
                  }
         | 
| 32 | 
            -
                }
         | 
| 33 | 
            -
              }
         | 
| 34 | 
            -
             | 
| 35 | 
            -
              function handleUpdate(e) {
         | 
| 36 | 
            -
                var submit = $(e.target);
         | 
| 37 | 
            -
                var form = submit.closest('form');
         | 
| 38 | 
            -
                var url = form.attr("action");
         | 
| 39 | 
            -
                var method = $("input[name=_method]");
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                if (method.attr("value") != "put") {
         | 
| 42 | 
            -
                  return true;
         | 
| 43 | 
            -
                }
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                e.preventDefault();
         | 
| 46 | 
            -
                var data = $(form).serialize();
         | 
| 47 | 
            -
                $.ajax({
         | 
| 48 | 
            -
                   url: url,
         | 
| 49 | 
            -
                   type: 'PUT',
         | 
| 50 | 
            -
                   data: data,
         | 
| 51 | 
            -
                   dataType: "json",
         | 
| 52 | 
            -
                   success: function(response) {
         | 
| 53 | 
            -
                     window.location.href = response.location;
         | 
| 54 | 
            -
                   },
         | 
| 55 | 
            -
                   error: function(xhr, textStatus, errorThrown) {
         | 
| 56 | 
            -
                     console.log('Error!  Status = ' + xhr.status);
         | 
| 57 | 
            -
                   },
         | 
| 58 | 
            -
                   complete: function(data) {
         | 
| 59 | 
            -
                     console.log("data %o", data);
         | 
| 60 | 
            -
                   }
         | 
| 61 | 
            -
                });
         | 
| 62 | 
            -
              }
         | 
| 63 | 
            -
             | 
| 64 | 
            -
              function deleteItem(link) {
         | 
| 65 | 
            -
                var node = link.closest('.jets-element-to-delete');
         | 
| 66 | 
            -
                node.hide(); // immediately hide element
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                var resource = link.attr("href");
         | 
| 69 | 
            -
                var token = $('meta[name=csrf-token]').attr('content');
         | 
| 70 | 
            -
                var data = { authenticity_token: token };
         | 
| 71 | 
            -
                var request = $.ajax({
         | 
| 72 | 
            -
                  url: resource,
         | 
| 73 | 
            -
                  method: "DELETE",
         | 
| 74 | 
            -
                  data: data,
         | 
| 75 | 
            -
                  dataType: "json"
         | 
| 76 | 
            -
                });
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                request.done(function(msg) {
         | 
| 79 | 
            -
                  console.log("msg %o", msg)
         | 
| 80 | 
            -
                  node.remove();
         | 
| 81 | 
            -
                });
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                request.fail(function(jqXHR, textStatus) {
         | 
| 84 | 
            -
                  console.log("textStatus %o", textStatus)
         | 
| 85 | 
            -
                  node.show(); // in the event of a failure re-display the node
         | 
| 86 | 
            -
                });
         | 
| 87 | 
            -
              }
         | 
| 88 | 
            -
             | 
| 89 | 
            -
              $('body').click(handleAll)
         | 
| 90 | 
            -
            });
         |