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 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hx-ext-amz-content-sha256",
3
- "main": "amz-content-sha256.js",
4
- "version": "1.0.0",
3
+ "main": "main.js",
4
+ "version": "1.0.2",
5
5
  "scripts": {
6
6
  "lint": "eslint test/ext test",
7
7
  "lint-fix": "eslint test/ext test --fix",
File without changes