hx-ext-amz-content-sha256 1.0.2 → 1.0.4
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.
- package/LICENSE +18 -11
- package/main.js +5 -2
- package/min.js +1 -1
- package/package.json +2 -1
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024, Felipe Gené de Faria
|
|
4
4
|
|
|
5
|
-
Permission
|
|
6
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
OR
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/main.js
CHANGED
|
@@ -45,9 +45,12 @@ htmx.defineExtension("amz-content-sha256", {
|
|
|
45
45
|
|
|
46
46
|
// Ensure the target is a valid HTMLFormElement
|
|
47
47
|
if (form instanceof HTMLFormElement) {
|
|
48
|
-
// Create a FormData object from the form, and
|
|
48
|
+
// Create a FormData object from the form, and serialize using encodeURIComponent
|
|
49
|
+
// to match HTMX's internal encoding (URLSearchParams encodes differently)
|
|
49
50
|
const formData = new FormData(form);
|
|
50
|
-
const data =
|
|
51
|
+
const data = Array.from(formData.entries())
|
|
52
|
+
.map(([k, v]) => encodeURIComponent(k) + '=' + encodeURIComponent(v))
|
|
53
|
+
.join('&');
|
|
51
54
|
|
|
52
55
|
// Calculate the SHA-256 hash of the form data
|
|
53
56
|
const sha256Hash = await this.calculateSHA256(data);
|
package/min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
htmx.defineExtension("amz-content-sha256",{init:function(){return this.RequestHashQueue={},this.calculateSHA256=async e=>{const t=(new TextEncoder).encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map((e=>e.toString(16).padStart(2,"0"))).join("")},null},onEvent:async function(e,t){switch(e){case"htmx:confirm":if("post"==t.detail.verb||"put"==t.detail.verb){t.preventDefault();const e=t.target;if(e instanceof HTMLFormElement){const a=new FormData(e),s=
|
|
1
|
+
htmx.defineExtension("amz-content-sha256",{init:function(){return this.RequestHashQueue={},this.calculateSHA256=async e=>{const t=(new TextEncoder).encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map((e=>e.toString(16).padStart(2,"0"))).join("")},null},onEvent:async function(e,t){switch(e){case"htmx:confirm":if("post"==t.detail.verb||"put"==t.detail.verb){t.preventDefault();const e=t.target;if(e instanceof HTMLFormElement){const a=new FormData(e),s=Array.from(a.entries()).map((([e,t])=>encodeURIComponent(e)+"="+encodeURIComponent(t))).join("&"),i=await this.calculateSHA256(s);this.RequestHashQueue[t.detail.path]?this.RequestHashQueue[t.detail.path].push(i):this.RequestHashQueue[t.detail.path]=[i]}t.detail.issueRequest()}break;case"htmx:configRequest":"post"!=t.detail.verb&&"put"!=t.detail.verb||this.RequestHashQueue[t.detail.path].length>0&&(t.detail.headers["x-amz-content-sha256"]=this.RequestHashQueue[t.detail.path].pop())}}});
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hx-ext-amz-content-sha256",
|
|
3
3
|
"main": "main.js",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint test/ext test",
|
|
7
7
|
"lint-fix": "eslint test/ext test --fix",
|
|
8
8
|
"format": "eslint --fix test/ext test",
|
|
9
9
|
"test": "mocha-chrome test/index.html"
|
|
10
10
|
},
|
|
11
|
+
"license": "MIT",
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
13
14
|
"url": "git+https://github.com/felipegenef/amz-content-sha256.git"
|