Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
This gem generates Rails URL helpers in TypeScript, which is synchronized to routes.rb
.
This is inspired by js-routes, which invents the great idea to export URL helpers to JavaScript.
In your lib/tasks/ts_routes.rake
:
namespace :ts do
TS_ROUTES_FILENAME = "javascripts/generated/routes.ts"
desc "Generate #{TS_ROUTES_FILENAME}"
task routes: :environment do
Rails.logger.info("Generating #{TS_ROUTES_FILENAME}")
source = TsRoutes.generate(
exclude: [/admin/, /debug/],
)
File.write(TS_ROUTES_FILENAME, source)
end
end
Then, execute rake ts:routes
to generate routes.ts
in your favorite path.
And you can import it in TypeScript code:
import * as Routes from './generated/routes';
console.log(Routes.entriesPath({ page: 1, per: 20 })); // => /entries?page=1&per=20
console.log(Routes.entryPath(1)); // => /entries/1
// "anchor" is a special keyword to add anchors (as Rails's does)
console.log(Routes.entryPath(1, { anchor: 'foo' })); // => /entries/1#foo
Generated URL helpers are almost compatible with Rails, but they have some restriction:
Routes.entryPath(1)
for /entries/:id
Routes.entryPath({ id })
is not allowednull
nor undefined
Routes.entyPath(null)
does not compileRoutes.entriesPath({ page: 1, per: 2 })
Here are options for TsRoutes.generate
:
name | description | default |
---|---|---|
routes | Rails routes to export | Rails.application.routes |
camel_case | naming style; doesn't change if false | true |
route_suffix | suffix for each route | "path" |
include | Array of Regexp patterns to include | nil |
exclude | Array of Regexp patterns to exclude | nil |
header | additional parts of generated files | "/* tslint:disable */" |
Note that TsRoutes.generate(options)
is a shortcut of TsRoutes::Generator.new(options).generate
.
Use Guard:
# In Guardfile
# Run `rake ts:routes` when routes.rb is updated.
guard :rake, task: 'ts:routes' do
watch(%r{config/routes\.rb$})
end
Add this line to your application's Gemfile:
gem 'ts_routes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ts_routes
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/bitjourney/ts_routes-rails.
Copyright 2017 Bit Journey, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Unknown package
We found that ts_routes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.