Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rails/request.js

Package Overview
Dependencies
Maintainers
9
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rails/request.js - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

__tests__/fetch_request.js

18

package.json
{
"name": "@rails/request.js",
"version": "0.0.5",
"version": "0.0.6",
"description": "A tiny Fetch API wrapper that allows you to make http requests without need to handle to send the CSRF Token on every request",
"main": "./src/index.js",
"main": "./dist/requestjs.js",
"module": "./src/index.js",

@@ -21,7 +21,17 @@ "repository": "https://github.com/rails/request.js",

"scripts": {
"lint": "standard src"
"lint": "standard src",
"build": "rollup -c",
"test": "jest"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.15.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"babel-jest": "^27.1.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^27.0.6",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2",
"standard": "^16.0.3"
}
},
"dependencies": {}
}

@@ -7,2 +7,8 @@ # Rails Request.JS

## Asset Pipeline
Install the [requestjs-rails](https://github.com/rails/requestjs-rails) gem and follow the step described there.
## Webpacker
### npm

@@ -127,2 +133,35 @@ ```

#### Before and after hooks
Wrap the request `Promise` with your own code. Just pure and simple JavaScript like this:
```javascript
import { FetchRequest } from "@rails/request.js"
import { navigator } from "@hotwired/turbo"
function showProgressBar() {
navigator.delegate.adapter.progressBar.setValue(0)
navigator.delegate.adapter.progressBar.show()
}
function hideProgressBar() {
navigator.delegate.adapter.progressBar.setValue(1)
navigator.delegate.adapter.progressBar.hide()
}
export function withProgress(request) {
showProgressBar()
return request.then((response) => {
hideProgressBar()
return response
})
}
export function get(url, options) {
const request = new FetchRequest("get", url, options)
return withProgress(request.perform())
}
```
## Response

@@ -129,0 +168,0 @@

@@ -9,3 +9,3 @@ import { FetchResponse } from './fetch_response'

this.options = options
this.originalUrl = url
this.originalUrl = url.toString()
}

@@ -30,3 +30,3 @@

if (response.ok && response.isTurboStream) {
response.renderTurboStream()
await response.renderTurboStream()
}

@@ -89,3 +89,3 @@

case 'json':
return 'application/json'
return 'application/json, application/vnd.api+json'
default:

@@ -120,3 +120,3 @@ return '*/*'

get url () {
return this.originalUrl.split('?')[0] + this.query
return (this.originalUrl.split('?')[0]).split('#')[0] + this.query
}

@@ -123,0 +123,0 @@

@@ -22,2 +22,6 @@ export class FetchResponse {

get unprocessableEntity () {
return this.statusCode === 422
}
get authenticationURL () {

@@ -46,3 +50,3 @@ return this.response.headers.get('WWW-Authenticate')

get json () {
if (this.contentType.match(/^application\/json/)) {
if (this.contentType.match(/^application\/.*json$/)) {
return this.responseJson || (this.responseJson = this.response.json())

@@ -65,3 +69,3 @@ }

if (window.Turbo) {
window.Turbo.renderStreamMessage(await this.text)
await window.Turbo.renderStreamMessage(await this.text)
} else {

@@ -68,0 +72,0 @@ console.warn('You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc