Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@hammerstone/refine-stimulus
Advanced tools
Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.
Short description and motivation.
How to use my plugin.
Add this line to your application's Gemfile:
gem "refine-rails"
And then execute:
$ bundle
Or install it yourself as:
$ gem install refine-rails
Installing the JavaScript package:
$ yarn add @hammerstone/refine-stimulus
Also, make sure that your project uses jquery
and binds it as window.$
. Required for catching events dispatched by select2
dropdowns.
Also note that there's currently a bug with esbuild and stimulus 3.0 compatibility.
Where you normally import your Stimulus controllers, add the following lines:
// import { Application } from "stimulus"
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus"
// window.Stimulus = Application.start()
Stimulus.load(refineControllers)
If loading in Bullet Train,the load command is
application.load(refineControllers)
To manually register (or extend or provide your own replacement for) each Stimulus controller:
// import { Application } from "stimulus"
import {
AddController,
DefaultsController,
DeleteController,
FormController,
StateController,
StoredFilterController,
UpdateController
} from "@hammerstone/refine-stimulus"
// window.Stimulus = Application.start()
Stimulus.register('refine--add', AddController)
Stimulus.register('refine--defaults', DefaultsController)
Stimulus.register('refine--delete', DeleteController)
Stimulus.register('refine--form', FormController)
Stimulus.register('refine--state', StateController)
Stimulus.register('refine--stored-filter', StoredFilterController)
Stimulus.register('refine--update', UpdateController)
Contribution directions go here.
From this repo's directory:
# install dependencies
$ yarn
# prepare for having a symbolic link to this directory
$ yarn link
# build and update as you work on the javascript
$ yarn build --watch
From the directory of the project including this package:
# create a symbolic link in node_modules/ to this package
yarn link @hammerstone/refine-stimulus
Running yarn
again from your project's directory will revert back to the published version of the package on npm.
Note: Because of a weird behavior in how yarn link
works, you might have to make sure the project including this package includes a few of this package's dependencies (e.g. lodash, stimulus, etc)
yarn build
. This will prepare the different javascript outputsyarn pack
. This will create a new .tgz
file for the new versionyarn publish <tgz filename> --new-version <version number in package.json>
*.tgz
fileAdd ruby gem
source "https://yourAPIKey@gem.fury.io/hammerstonedev" do
gem "refine-rails"
end
Installing the JavaScript package:
$ yarn add @hammerstone/refine-stimulus
In app/javascript/controllers/index.js
add
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus"
application.load(refineControllers)
# Hammerstone routes
namespace :hammerstone do
resource :refine_blueprint, only: [:show, :update, :create]
put "update_stable_id", to: "refine_blueprints#update_stable_id"
namespace :refine do
resources :stored_filters, only: [:create, :index, :show, :new, :update, :edit] do
get "editor", on: :collection
end
end
end
Add helper file (why isn't this coming through in the gem)?
Add necessary methods to account/application_controller
fastest - replace account/application controller with below
class Account::ApplicationController < ApplicationController
include Account::Controllers::Base
def ensure_onboarding_is_complete
# First check that Bullet Train doesn't have any onboarding steps it needs to enforce.
return false unless super
# Most onboarding steps you'll add should be skipped if the user is adding a team or accepting an invitation ...
unless adding_team? || accepting_invitation?
# So, if you have new onboarding steps to check for an enforce, do that here:
end
# Finally, if we've gotten this far, then onboarding appears to be complete!
true
end
def child_filter_class
# e.g. `Scaffolding::CompletelyConcrete::TangibleThingsFilter`
self.class.name.gsub(/^Account::/, "").gsub(/Controller$/, "Filter").constantize
rescue NameError => _
nil
end
def apply_filter(current_scope = nil)
if child_filter_class.present?
@stored_filter = nil
# @stored_filter = Hammerstone::Refine::StoredFilter.find_by(id: stored_filter_id)
@stable_id = stable_id
@refine_filter = if stable_id
Hammerstone::Refine::Stabilizers::UrlEncodedStabilizer.new.from_stable_id(id: stable_id, initial_query: @parent_object.send(@child_collection))
elsif @stored_filter
@stored_filter.refine_filter
else
# e.g. `Scaffolding::CompletelyConcrete::TangibleThingsFilter`
child_filter_class.new([], @parent_object.send(@child_collection))
end
# e.g. `@tangible_things = @refine_filter.get_query`
# TODO We should also make it the expectation at a framework level that when we do this, we also update some type
# of generically named instance variable like @child_collection, except right now that's just a symbol. The idea
# here is that any other "plugins" or magic behavior like this should compound and play well with each other.
instance_variable_set(children_instance_variable_name, @refine_filter.get_query)
# This takes a current scope from tab, etc and merges it in
instance_variable_set(children_instance_variable_name, children_instance_variable.merge(current_scope)) if current_scope
end
end
def filter_params
# The filter can come in as a stored_filter_id (database stabilized) or a stable_id (url encoded)
params.permit(:filter, :stable_id, :blueprint, :conditions, :clauses, :name, :tab, :site_id, :workspace_id, :product_id, :q, :stored_filter_id)
end
def stored_filter_id
filter_params[:stored_filter_id]
end
def stable_id
filter_params[:stable_id]
end
def children_instance_variable_name
# e.g. `tangible_things`
"@" + self.class.name.gsub(/^Account::/, "").gsub(/Controller$/, "").split("::").last.underscore
end
def children_instance_variable
instance_variable_get(children_instance_variable_name)
end
end
Or individually add these methods to account/application_controller.rb
child_filter_class
(extracts the filter class name)apply_filter
- include stored id if desired (not included for workshop, only stable id)def filter_params
def stable_id
def children_instance_variable_name
def children_instance_variable
Add ApplicationFilter
class
Handle javascript
filter_link_controller
to enable/disable the Apply buttonsearch_filter_controller
(or different controller) to respond to javascript events (force page reload for simplicity at this point) - add back in the stored filter stuff for a BT integration (removed for workshop)stored_filter.rb
(only if using stored filters)<%= render partial: 'shared/filter_builder_dropdown' %>
_loading.html.erb or an equivalent
Add filter_builder_dropdown
or appropriate controller to respond to eventsapply_filter
from the index action of the controller you want to usefilters/modelnameplural_filter.rb
and inherit from ApplicationFilter
2.0.0 2022-07-24
FAQs
Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.
The npm package @hammerstone/refine-stimulus receives a total of 78 weekly downloads. As such, @hammerstone/refine-stimulus popularity was classified as not popular.
We found that @hammerstone/refine-stimulus demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.