hx-ext-amz-content-sha256 1.0.0 → 1.0.2
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/README.md +4 -0
- package/min.js +1 -0
- package/package.json +2 -2
- /package/{amz-content-sha256.js → main.js} +0 -0
package/README.md
CHANGED
|
@@ -35,6 +35,10 @@ This issue can occur when using Lambda Function URLs behind CloudFront, as expla
|
|
|
35
35
|
|
|
36
36
|
_Example_:
|
|
37
37
|
|
|
38
|
+
```html
|
|
39
|
+
<script defer src="https://unpkg.com/hx-ext-amz-content-sha256/min.js"></script>
|
|
40
|
+
```
|
|
41
|
+
|
|
38
42
|
```html
|
|
39
43
|
<form hx-post="/your-api-endpoint" hx-ext="amz-content-sha256">
|
|
40
44
|
<input type="text" name="example" value="test" />
|
package/min.js
ADDED
|
@@ -0,0 +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=new URLSearchParams(a).toString(),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
|
File without changes
|