Skip to content

Commit

Permalink
Parcel module
Browse files Browse the repository at this point in the history
  • Loading branch information
qertis committed Apr 5, 2024
1 parent 416bf07 commit 2ac80e0
Show file tree
Hide file tree
Showing 4 changed files with 3,462 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
node_modules/
dist/
.parcel-cache
21 changes: 9 additions & 12 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ const VERSION = '2.0';
* @param {object} obj.body - body
* @param {object} [obj.auth] - basic auth
* @param {string} [obj.signature] - verification Ed25519 signatures
* @param {boolean} [obj.dev] - development
* @param {object} [app] - Express JS Application
* @returns {Promise<*>}
*/
export default async ({
export default async({
url,
body,
headers = {},
auth,
jwt,
signature,
dev = false,
}, app) => {
if (dev) {
if ('production' !== process.env.NODE_ENV) {
if (!app) {
return Promise.reject({
jsonrpc: VERSION,
Expand Down Expand Up @@ -61,7 +59,12 @@ export default async ({
headers: parameters.headers,
body,
})
.then(response => response.body);
.then(response => response.body)
.catch(e => ({
jsonrpc: VERSION,
error: { code: -32603, message: e.message },
id: null,
}))
}

const fheaders = new Headers()
Expand All @@ -74,13 +77,7 @@ export default async ({
fheaders.append('Authorization', 'Bearer ' + jwt);
}
if (auth && auth.user && auth.pass) {
const basicAuth = 'Basic ' +
Buffer.from(
auth.user +
':' +
auth.pass,
).toString('base64');
fheaders.set('Authorization', basicAuth);
fheaders.set('Authorization', btoa(auth.user + ':' + auth.pass));
}
const parameters = {
jsonrpc: VERSION,
Expand Down
Loading

0 comments on commit 2ac80e0

Please sign in to comment.