Skip to content

Commit

Permalink
Merge branch 'baseline' of https://github.com/bahrus/be-reformable in…
Browse files Browse the repository at this point in the history
…to baseline
  • Loading branch information
bahrus committed Nov 17, 2024
1 parent fd456a1 commit 07d12ae
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ This is also supported:
```


## Support for headers and body [WIP]
## Support for headers and body

Hardcoded:

Expand Down Expand Up @@ -140,7 +140,7 @@ To indicate that a header is optional, add a question mark at the end of the key
> Other components / enhancements that leverage this enhancement, and actually perform the fetch should consider use of [be-hashing-out](https://github.com/bahrus/be-hashing-out) or some other security mechanism if there's any sense of danger that justifies adding that security check.

## Support for emitting "fetch-ready" event only after a button click [TODO]:
## Support for emitting "fetch-ready" event only after a button click [Untested]:

```html
<link id=newton-microservice rel=preconnect href=https://newton.now.sh/ >
Expand Down
13 changes: 8 additions & 5 deletions be-reformable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BeReformable extends BE {
ro: true
},
resolvedBaseURL: {ro: true},
headers: {},
headerFields: {},
fetchOptions: {},
isFetchReady: {ro: true},
Expand Down Expand Up @@ -114,18 +115,18 @@ class BeReformable extends BE {
* @type {BodyInit | undefined}
*/
let body;
switch(method.toLowerCase()){
switch(method.toUpperCase()){
case '':
case 'get':
case 'delete':
case 'GET':
case 'DELETE':
if(enhancedElement.method.toLowerCase() === 'get'){

const queryString = new URLSearchParams(formData).toString();
url += '?' + queryString
}
break;
case 'put':
case 'post':
case 'PUT':
case 'POST':
body = formData;
break;
}
Expand All @@ -137,10 +138,12 @@ class BeReformable extends BE {
headers,
body
};
console.log({fetchOptions});

if(headerFields !== undefined){
const {getHeaderFieldVals} = await import('./getHeaderFieldVals.js');
const headers = await getHeaderFieldVals(self);
console.log({headers});
if(fetchOptions.headers === undefined) {
fetchOptions.headers = headers;
}else{
Expand Down
11 changes: 9 additions & 2 deletions demo/NewtonMicroservice/GlobalThis.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
.weave({
baseURL: "globalThis://newton-microservice/href"
})
.into('qmywdO1vr0SwyuIe4fvzxQ');
.into('qmywdO1vr0SwyuIe4fvzxQ')
.andWeave({
myCustomHeader: 'goodbye'
})
.into('rPpwNLcYsUOjFcg+N8lmOA');
</script>
<form id=testForm be-reformable='{
"...": "qmywdO1vr0SwyuIe4fvzxQ",
"path": "api/v2/:operation/:expression",
"headerFields": ["#myHeader"]
"headerFields": ["#myHeader"],
"headers": {
"...": "rPpwNLcYsUOjFcg+N8lmOA"
}
}'
>
<label>
Expand Down
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
],
"types": "types.d.ts",
"dependencies": {
"be-enhanced": "0.0.150",
"be-hive": "0.0.230",
"be-enhanced": "0.0.151",
"be-hive": "0.0.231",
"mount-observer": "0.0.39",
"trans-render": "0.0.856"
"trans-render": "0.0.857"
},
"devDependencies": {
"ssi-server": "0.0.1",
Expand Down

0 comments on commit 07d12ae

Please sign in to comment.