Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
ActiveFacet is a Rails plugin that enables custom as_json serialization intended for APIs. It is designed for speed, and is magnitudes of order faster than jbuilder.
The framework supports:
Add this line to your application's Gemfile:
gem 'active_facet'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_facet
And then execute:
$ rails g active_facet:install
To add an initializer to your application.
Parent.limit(2).as_json(af_opts: {
version: "2.3.8",
cache_force: true,
fields: [:basic, :extended, { children: [:minimal, :extension] }]
field_overrides: {
parent: [:id, :children, :foo, :bar],
child: [:fizz, :buzz]
},
filters: {
single_parent: true,
with_children_parent: 3,
active: :disabled
}
})
# =>
[ {
id: 1,
created_at: 2343242342,
updated_at: "2014-03-23 00:23:32",
weight: 2432252,
children: [ {
fizz: 'care bear'
}, {
fizz: 'hello',
buzz: 'world'
} ]
}, {
id: 2,
created_at: 2343242777,
updated_at: "2014-04-24 01:34:25",
children: [ {
fizz: 'tamato'
} ]
}
}
All options are optional
Version of serializer to marshal resources with. Defaults to:
"1.0"
Force serializers to ignore cached documents. Defaults to:
false
Attributes to marshal. See Field Sets. Defaults to:
:basic
Attributes to marshal, by resource type. See Field Sets. Defaults to:
{}
Filters to apply when marshalling associations. See Field Sets. Defaults to:
{}
class ParentSerializer
include ActiveFacet::Serializer::Base
# TRANSFORMS
# Transforms rename attributes and apply custom serializers to attributes data.
# Renames parent.kid_trackings to json['trackings'] on parent.as_json...
transform :trackings, from: :kid_trackings
# Renames json['trackings'] to parent.kid_trackings on parent.from_hash...:
transform :trackings, to: :kid_trackings
# Renames parent.kid_trackings to json['trackings'] on parent.as_json... & parent.from_hash...
transform :trackings, as: :kid_trackings
# Converts json['created_at'] with TimeCustomAttributeSerializer on parent.as_json... & parent.from_hash...
transform :created_at, with: :time
# Renames json['created_at'] to parent.data['weight'] on parent.as_json... & parent.from_hash...
transform :weight, within: :data
# Renames json['weighed'] to parent.data['weighed_at'] using TimeCustomAttributeSerializer converter on parent.as_json... & parent.from_hash...
transform :weighed, within: :data, with: :time, as: :wieghed_at
# EXTENSIONS
# Extensions decorate the json response when attribute data is not directly accessible from the resource.
# Decorates json['free_shipping_minimum'] on parent.as_json...
extension :free_shipping_minimum
# FIELD SETS
# Field sets indicate the desired fields to serialize for a given resource type.
# Field sets can be aliased, and reference aliases, recursively.
# Field sets can reference Field Sets defined for ActiveRecord Association resource types in a hierarchical structure
# NOTE:: make sure to define :basic and :minimal Field Sets for all resources
# :basic is implicitely added to all Field Sets that do not inclue :minimal during serialization
# Arrays map to collections
expose :timestamps, as: [:id, :created_at, :updated_at]
expose :basic, as: [:timestamps, :name]
# Hashes map to relations and the Field Sets declared on the relation
expose :deep, as: { trackings: :basic }
# Composite structures can be formed from Symbols, Arrays, and Hashes
expose :deep_basic, as: [:timestamps, :basic, { trackings: [:basic, :extended] }]
# EXPOSE_TIMESTAMPS
# expose_timestamps is equivalent to
# transform :created_at, with: :time
# transform :updated_at, with: :time
# expose :timestamps, as: [:id, :created_at, :updated_at]
expose_timestamps
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rspec spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment. To work with an interactive prompt including a dummy host application, run bin/rails c
or rails c
from the spec/dummy directory.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
To push or update an unreleased version, without pushing the .gem
file, run bin/update_version
.
To configure a host application to use a local version of the gem without modifying the host application's Gemfile run from the root directory of the host application bundle config local.active_facet /path/to/local/git/repository
To unconfigure a local version of the gem, run bundle config --delete local.active_facet
Available at https://github.com/honest/active_facet/blob/master/ROADMAP.md
Bug reports and pull requests are welcome on GitHub at https://github.com/honest/active_facet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that active_facet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.