Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/jsc/modules/linkedjsdomwrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,56 @@
* limitations under the License.
**/


if (typeof Error.captureStackTrace !== 'function') {
Error.captureStackTrace = function(targetObject, constructorOpt) {
Comment thread
gurpreet319 marked this conversation as resolved.
try {
var stack = new Error().stack;
if (stack && targetObject) {
var lines = stack.split('\n');
targetObject.stack = lines.slice(1).join('\n');
}
if (typeof console !== 'undefined' && typeof console.log === 'function') {
var ctorName = (constructorOpt && constructorOpt.name) ? constructorOpt.name : 'unknown';
console.log('Error.captureStackTrace called for ' + ctorName + ' (polyfilled no-op, previously would have thrown and hung the fetch promise)');

if (targetObject && targetObject.message) {
console.log('message: ' + targetObject.message);
}
if (targetObject && targetObject.type) {
console.log('type: ' + targetObject.type);
}
console.log('stack:\n' + (targetObject && targetObject.stack ? targetObject.stack : stack));
}
Comment thread
gurpreet319 marked this conversation as resolved.
} catch (e) {
}
};
}

(function ppGuardGetOwnPropertySymbols() {
if (typeof Object.getOwnPropertySymbols !== 'function') {
return;
}
var originalGetOwnPropertySymbols = Object.getOwnPropertySymbols;
if (originalGetOwnPropertySymbols.__ppGuarded) {
return;
}
var guarded = function(obj) {
if (obj === undefined || obj === null) {
try {
if (typeof console !== 'undefined' && typeof console.log === 'function') {
console.log('Object.getOwnPropertySymbols called with ' + obj + ', returning [] instead of throwing');
Comment thread
gurpreet319 marked this conversation as resolved.
}
} catch (e) {
}
return [];
}
return originalGetOwnPropertySymbols(obj);
};
guarded.__ppGuarded = true;
Object.getOwnPropertySymbols = guarded;
})();

LinkedJSDOM = LinkedJSDOMLib;
function JSDOM(html)
{
Expand Down Expand Up @@ -46,6 +96,8 @@ catch(e)
XMLHttpRequest = window.XMLHttpRequest;
HTMLElement = window.HTMLElement;
window.location = {"href":"", "host":"127.0.0.1", "protocol":"http"}
Image = window.Image;


//below all are undefined
/*
Expand Down
103 changes: 74 additions & 29 deletions src/jsc/modules/node-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var callBind = __webpack_require__(870);

var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));

Check failure on line 23 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with '0BSD, Apache-2.0, MIT (and more)' file licenses found (6832 lines) Location: https://github.com/Azure-Samples/communication-services-web-chat-hero/blob/1.17.0/Server/dist/server.js#L59247 Component: pkg:github/azure-samples/communication-services-web-chat-hero@1.17.0 Download: https://github.com/Azure-Samples/communication-services-web-chat-hero/archive/refs/tags/1.17.0.tar.gz

module.exports = function callBoundIntrinsic(name, allowMissing) {
var intrinsic = GetIntrinsic(name, !!allowMissing);
Expand Down Expand Up @@ -330,7 +330,7 @@
};


/***/ }),

Check failure on line 333 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'MIT, Apache-2.0, Protobuf (and more)' file licenses found (4351 lines) Location: https://github.com/actions/setup-node/blob/v6.1.0/dist/cache-save/index.js#L53494 Component: pkg:github/actions/setup-node@v6.1.0 Download: https://github.com/actions/setup-node/archive/refs/tags/v6.1.0.tar.gz

/***/ 437:
/***/ ((module) => {
Expand Down Expand Up @@ -1031,7 +1031,7 @@
//MADANA HACK
//var zlib = _interopDefault(require('zlib'));

// Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js

Check failure on line 1034 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'MIT' component license found (1753 lines) Location: lib/index.js (link unavailable) Component license file: /LICENSE.md (link unavailable) Component: pkg:npm/node-fetch@2.6.10 Download: https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.10.tgz

Check failure on line 1034 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'MIT' component license found (1756 lines) Location: lib/index.js (link unavailable) Component license file: /LICENSE.md (link unavailable) Component: pkg:npm/node-fetch@2.6.13 Download: https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.13.tgz

Check failure on line 1034 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with '0BSD' file license found (3807 lines) Location: dist/tearex.js (link unavailable) Component: pkg:npm/tearex@0.1.0 Download: https://registry.npmjs.org/tearex/-/tearex-0.1.0.tgz

Check failure on line 1034 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'BSD-3-Clause, MIT' file licenses found (3773 lines) Location: https://github.com/AmadeusITGroup/otter/blob/v8.0.24/tools/github-actions/get-npm-tag/packaged-action/index.js#L1349 Component: pkg:github/amadeusitgroup/otter@v8.0.24 Download: https://github.com/AmadeusITGroup/otter/archive/refs/tags/v8.0.24.tar.gz

Check failure on line 1034 in src/jsc/modules/node-fetch.js

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID Detected License Issue

Snippet with 'ISC' component license found (3940 lines) Location: dist/index.js (link unavailable) Component license file: /package.json (link unavailable) Component: pkg:npm/gptshell@0.0.7 Download: https://registry.npmjs.org/gptshell/-/gptshell-0.0.7.tgz

// fix for "Readable" isn't a named export issue
const Readable = Stream.Readable;
Expand Down Expand Up @@ -1188,6 +1188,44 @@
// fix an issue where "PassThrough" isn't a named export for node <10
const PassThrough = Stream.PassThrough;

function isStreamLike(body) {
return !!body
&& typeof body.on === 'function'
&& (typeof body.pipe === 'function' || typeof body.once === 'function');
Comment thread
gurpreet319 marked this conversation as resolved.
}

function getErrorReason(err) {
if (!err) {
return 'unknown error';
}

if (typeof err === 'string') {
return err;
}

if (err.message) {
return err.message;
}

if (err.description) {
return err.description;
}

if (err.reason) {
return err.reason;
}

if (err.code !== undefined) {
return 'code: ' + err.code;
}

try {
return JSON.stringify(err);
} catch (e) {
return String(err);
}
}

/**
* Body mixin
*
Expand Down Expand Up @@ -1219,7 +1257,7 @@
} else if (ArrayBuffer.isView(body)) {
// body is ArrayBufferView
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
} else if (body instanceof Stream) ; else {
} else if (body instanceof Stream || isStreamLike(body)) ; else {
// none of the above
// coerce to string then buffer
//body = Buffer.from(String(body));
Expand All @@ -1234,7 +1272,7 @@
this.size = size;
this.timeout = timeout;

if (body instanceof Stream) {
if (body instanceof Stream || isStreamLike(body)) {
body.on('error', function (err) {
const error = err.name === 'AbortError' ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, 'system', err);
_this[INTERNALS].error = error;
Expand Down Expand Up @@ -1289,8 +1327,12 @@
var _this2 = this;

return consumeBody.call(this).then(function (buffer) {
var text = buffer.toString();
if (text.trim() === '') {
return {};
}
Comment thread
gurpreet319 marked this conversation as resolved.
try {
return JSON.parse(buffer.toString());
return JSON.parse(text);
} catch (err) {
return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
}
Expand Down Expand Up @@ -1390,7 +1432,7 @@
}

// istanbul ignore if: should never happen
if (!(body instanceof Stream)) {
if (!(body instanceof Stream) && !isStreamLike(body)) {
return Body.Promise.resolve(Buffer.alloc(0));
}

Expand Down Expand Up @@ -1419,7 +1461,7 @@
reject(err);
} else {
// other errors, such as incorrect content-encoding
reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, 'system', err));
reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${getErrorReason(err)}`, 'system', err));
}
});

Expand All @@ -1428,6 +1470,10 @@
return;
}

if (!Buffer.isBuffer(chunk)) {
chunk = Buffer.from(chunk);
}

if (_this4.size && accumBytes + chunk.length > _this4.size) {
abort = true;
reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, 'max-size'));
Expand Down Expand Up @@ -1564,6 +1610,9 @@
// check that body is a stream and not form-data object
// note: we can't clone the form-data object without having it as a dependency
if (body instanceof Stream && typeof body.getBoundary !== 'function') {
if (typeof PassThrough !== 'function') {
throw new Error('cannot clone body stream: PassThrough is not available in this runtime');
Comment thread
gurpreet319 marked this conversation as resolved.
}
// tee instance body
p1 = new PassThrough();
p2 = new PassThrough();
Expand Down Expand Up @@ -2444,6 +2493,7 @@

// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
const PassThrough$1 = Stream.PassThrough;
const hasPassThrough$1 = typeof PassThrough$1 === 'function';

const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
const orig = new URL$1(original).hostname;
Expand Down Expand Up @@ -2527,17 +2577,15 @@
clearTimeout(reqTimeout);
}

if (request.timeout) {
req.once('socket', function (socket) {
reqTimeout = setTimeout(function () {
reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
finalize();
}, request.timeout);
});
}
if (request.timeout) {
reqTimeout = setTimeout(function () {
reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
finalize();
}, request.timeout);
}

req.on('error', function (err) {
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
reject(new FetchError(`request to ${request.url} failed, reason: ${getErrorReason(err)}`, 'system', err));

if (response && response.body) {
destroyStream(response.body, err);
Expand Down Expand Up @@ -2678,15 +2726,8 @@
}
}

//MADANA HACK
let body = undefined;
// prepare response
res.once('data', function (data) {
body = data;
});
res.once('end', function () {
if (signal) signal.removeEventListener('abort', abortAndFinalize);
//let body = res.pipe(new PassThrough$1());
if (signal) signal.removeEventListener('abort', abortAndFinalize);
let body = hasPassThrough$1 ? res.pipe(new PassThrough$1()) : res;
Comment thread
gurpreet319 marked this conversation as resolved.

const response_options = {
url: request.url,
Expand All @@ -2709,7 +2750,7 @@
// 3. no Content-Encoding header
// 4. no content response (204)
// 5. content not modified response (304)
if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
response = new Response(body, response_options);
resolve(response);
return;
Expand Down Expand Up @@ -2740,6 +2781,12 @@

// for deflate
if (codings == 'deflate' || codings == 'x-deflate') {
if (!hasPassThrough$1) {
body = body.pipe(zlib.createInflate());
response = new Response(body, response_options);
resolve(response);
return;
}
// handle the infamous raw deflate response from old servers
// a hack for old IIS and Apache servers
const raw = res.pipe(new PassThrough$1());
Expand Down Expand Up @@ -2776,11 +2823,9 @@
console.warn(`[DEBUG] Content-Encoding '${codings}' detected but zlib not available for decompression`);
}
}
// otherwise, use response as-is
response = new Response(body, response_options);
console.log(response);
resolve(response);
});
// otherwise, use response as-is
response = new Response(body, response_options);
resolve(response);
});

writeToStream(req, request);
Expand Down
Loading
Loading