requestjs-rails 0.0.9 → 0.0.11
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/app/assets/javascripts/requestjs.js +23 -6
- data/lib/requestjs/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad5960e6459e419a6a684ebc12194003f4b19f83b984004c5a62205ea761ea5
|
4
|
+
data.tar.gz: 1f1d45bd1e64fda7a075641e00fd78a97f84606ee0843b3663be143a9896295f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a55c0defd7b2890825932f7d53f01d6d6388bc4ce8c8bf4949da772a4e4bb8712a4378feae12c0fb75fb1afc3b8221ae32f60ace6f373533cbe962298978eb60
|
7
|
+
data.tar.gz: a5eb76765f8a41f810d65dc2742138191b37ab7e3bf5bc561cbcd5f706cb3791cc5ca211e4c1be761e2b400fdb5007cd0fcfd0e32088792f05f436e9a1d476ef
|
@@ -105,7 +105,7 @@ function stringEntriesFromFormData(formData) {
|
|
105
105
|
function mergeEntries(searchParams, entries) {
|
106
106
|
for (const [name, value] of entries) {
|
107
107
|
if (value instanceof window.File) continue;
|
108
|
-
if (searchParams.has(name)) {
|
108
|
+
if (searchParams.has(name) && !name.includes("[]")) {
|
109
109
|
searchParams.delete(name);
|
110
110
|
searchParams.set(name, value);
|
111
111
|
} else {
|
@@ -133,7 +133,8 @@ class FetchRequest {
|
|
133
133
|
if (response.unauthenticated && response.authenticationURL) {
|
134
134
|
return Promise.reject(window.location.href = response.authenticationURL);
|
135
135
|
}
|
136
|
-
|
136
|
+
const responseStatusIsTurboStreamable = response.ok || response.unprocessableEntity;
|
137
|
+
if (responseStatusIsTurboStreamable && response.isTurboStream) {
|
137
138
|
await response.renderTurboStream();
|
138
139
|
}
|
139
140
|
return response;
|
@@ -143,23 +144,36 @@ class FetchRequest {
|
|
143
144
|
headers[key] = value;
|
144
145
|
this.options.headers = headers;
|
145
146
|
}
|
147
|
+
sameHostname() {
|
148
|
+
if (!this.originalUrl.startsWith("http:")) {
|
149
|
+
return true;
|
150
|
+
}
|
151
|
+
try {
|
152
|
+
return new URL(this.originalUrl).hostname === window.location.hostname;
|
153
|
+
} catch (_) {
|
154
|
+
return true;
|
155
|
+
}
|
156
|
+
}
|
146
157
|
get fetchOptions() {
|
147
158
|
return {
|
148
159
|
method: this.method.toUpperCase(),
|
149
160
|
headers: this.headers,
|
150
161
|
body: this.formattedBody,
|
151
162
|
signal: this.signal,
|
152
|
-
credentials:
|
163
|
+
credentials: this.credentials,
|
153
164
|
redirect: this.redirect
|
154
165
|
};
|
155
166
|
}
|
156
167
|
get headers() {
|
157
|
-
|
168
|
+
const baseHeaders = {
|
158
169
|
"X-Requested-With": "XMLHttpRequest",
|
159
|
-
"X-CSRF-Token": this.csrfToken,
|
160
170
|
"Content-Type": this.contentType,
|
161
171
|
Accept: this.accept
|
162
|
-
}
|
172
|
+
};
|
173
|
+
if (this.sameHostname()) {
|
174
|
+
baseHeaders["X-CSRF-Token"] = this.csrfToken;
|
175
|
+
}
|
176
|
+
return compact(Object.assign(baseHeaders, this.additionalHeaders));
|
163
177
|
}
|
164
178
|
get csrfToken() {
|
165
179
|
return getCookie(metaContent("csrf-param")) || metaContent("csrf-token");
|
@@ -219,6 +233,9 @@ class FetchRequest {
|
|
219
233
|
get redirect() {
|
220
234
|
return this.options.redirect || "follow";
|
221
235
|
}
|
236
|
+
get credentials() {
|
237
|
+
return this.options.credentials || "same-origin";
|
238
|
+
}
|
222
239
|
get additionalHeaders() {
|
223
240
|
return this.options.headers || {};
|
224
241
|
}
|
data/lib/requestjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: requestjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Lauxen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: 6.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.
|
27
|
-
description:
|
26
|
+
version: 6.1.0
|
27
|
+
description:
|
28
28
|
email: marcelolauxen16@gmail.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -46,7 +46,7 @@ homepage: https://github.com/marcelolx/requestjs-rails
|
|
46
46
|
licenses:
|
47
47
|
- MIT
|
48
48
|
metadata: {}
|
49
|
-
post_install_message:
|
49
|
+
post_install_message:
|
50
50
|
rdoc_options: []
|
51
51
|
require_paths:
|
52
52
|
- lib
|
@@ -61,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
65
|
-
signing_key:
|
64
|
+
rubygems_version: 3.4.19
|
65
|
+
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: A tiny Fetch API wrapper that allows you to make http requests without need
|
68
68
|
to handle to send the CSRF Token on every request
|