@accordproject/concerto-util
Advanced tools
Comparing version 3.19.2-20240924185024 to 3.19.2-20240926173500
@@ -17,7 +17,4 @@ /* | ||
const axios = require('axios'); | ||
const url = require('url'); | ||
/** | ||
* Loads Files from an HTTP(S) URL using the axios library. | ||
* Loads Files from an HTTP(S) URL using fetch. | ||
* @class | ||
@@ -47,3 +44,3 @@ * @private | ||
/** | ||
* Load a File from a URL and return it | ||
* Load a text File from a URL and return it | ||
* @param {string} requestUrl - the url to get | ||
@@ -53,21 +50,23 @@ * @param {object} options - additional options | ||
*/ | ||
load(requestUrl, options) { | ||
async load(requestUrl, options) { | ||
if (!options) { | ||
options = { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'text/plain', | ||
} | ||
}; | ||
} | ||
if(!options) { | ||
options = {}; | ||
console.log(requestUrl); | ||
const response = await fetch(requestUrl, options); | ||
if (!response.ok) { | ||
throw new Error(`HTTP request failed with status: ${response.status}`); | ||
} | ||
const request = JSON.parse(JSON.stringify(options)); | ||
request.url = requestUrl; | ||
request.method = 'get'; | ||
request.responseType = 'text'; | ||
return axios(request) | ||
.then((response) => { | ||
let parsedUrl = url.parse(requestUrl); | ||
// external Files have a name that starts with '@' | ||
// (so that they are identified as external when an archive is read back in) | ||
const name = '@' + (parsedUrl.host + parsedUrl.pathname).replace(/\//g, '.'); | ||
return this.processFile(name, response.data); | ||
}); | ||
const text = await response.text(); | ||
const url = new URL(requestUrl); | ||
// external Files have a name that starts with '@' | ||
// (so that they are identified as external when an archive is read back in) | ||
const name = '@' + (url.host + url.pathname).replace(/\//g, '.'); | ||
return this.processFile(name, text); | ||
} | ||
@@ -74,0 +73,0 @@ } |
@@ -20,5 +20,2 @@ /* | ||
const colors = require('colors/safe'); | ||
const jsonColorize = require('json-colorizer'); | ||
/** | ||
@@ -38,34 +35,6 @@ * Default levels for the npm configuration. | ||
/** | ||
* Default levels for the npm configuration. | ||
* @type {Object} | ||
*/ | ||
const colorMap = { | ||
error: 'red', | ||
warn: 'yellow', | ||
info: 'green', | ||
verbose: 'cyan', | ||
debug: 'blue', | ||
silly: 'magenta' | ||
}; | ||
const timestamp = () => (new Date()).toLocaleTimeString(); | ||
const colorize = level => colors[colorMap[level]](level.toUpperCase()); | ||
/** | ||
* Helper function to test if a string is a stringified version of a JSON object | ||
* @param {string} str - the input string to test | ||
* @returns {boolean} - true iff the string can be parsed as JSON | ||
* @private | ||
*/ | ||
const isJson = (str) => { | ||
try { | ||
return (JSON.parse(str) && !!str); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Helper function to color and format JSON objects | ||
* Helper function to format JSON objects | ||
* @param {any} obj - the input obj to prettify | ||
@@ -76,5 +45,2 @@ * @returns {any} - the prettified object | ||
const prettifyJson = (obj) => { | ||
if(typeof obj === 'object' || isJson(obj)) { | ||
return jsonColorize(obj, { pretty: true, colors }); | ||
} | ||
return obj; | ||
@@ -113,3 +79,3 @@ }; | ||
stream( | ||
`${timestamp()} - ${colorize(mutatedLevel)}:`, | ||
`${timestamp()} - ${mutatedLevel}:`, | ||
...data | ||
@@ -116,0 +82,0 @@ .map(obj => obj instanceof Error ? `${obj.message}\n${obj.stack}`: obj) |
{ | ||
"name": "@accordproject/concerto-util", | ||
"version": "3.19.2-20240924185024", | ||
"version": "3.19.2-20240926173500", | ||
"description": "Utilities for Concerto Modeling Language", | ||
"homepage": "https://github.com/accordproject/concerto", | ||
"engines": { | ||
"node": ">=16", | ||
"npm": ">=8" | ||
"node": ">=18", | ||
"npm": ">=10" | ||
}, | ||
"main": "index.js", | ||
"browser": "dist/concerto-util.js", | ||
"browser": { | ||
"main": "dist/concerto-util.js", | ||
"fs": false, | ||
"path": false | ||
}, | ||
"typings": "types/index.d.ts", | ||
@@ -50,14 +54,11 @@ "scripts": { | ||
"mocha": "10.0.0", | ||
"moxios": "0.4.0", | ||
"node-polyfill-webpack-plugin": "2.0.1", | ||
"nyc": "15.1.0", | ||
"tmp-promise": "3.0.2", | ||
"typescript": "4.6.3" | ||
"typescript": "4.6.3", | ||
"undici": "^6.19.8" | ||
}, | ||
"dependencies": { | ||
"@supercharge/promise-pool": "1.7.0", | ||
"axios": "1.7.4", | ||
"colors": "1.4.0", | ||
"debug": "4.3.4", | ||
"json-colorizer": "2.2.2", | ||
"slash": "3.0.0" | ||
@@ -64,0 +65,0 @@ }, |
export = HTTPFileLoader; | ||
/** | ||
* Loads Files from an HTTP(S) URL using the axios library. | ||
* Loads Files from an HTTP(S) URL using fetch. | ||
* @class | ||
@@ -23,3 +23,3 @@ * @private | ||
/** | ||
* Load a File from a URL and return it | ||
* Load a text File from a URL and return it | ||
* @param {string} requestUrl - the url to get | ||
@@ -26,0 +26,0 @@ * @param {object} options - additional options |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
1
71942
42
1934
- Removedaxios@1.7.4
- Removedcolors@1.4.0
- Removedjson-colorizer@2.2.2
- Removedansi-styles@3.2.1(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.4(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcolors@1.4.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.1(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedjson-colorizer@2.2.2(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedsupports-color@5.5.0(transitive)