Compare commits

..

6 Commits

Author SHA1 Message Date
547b151ee2 2.0.11 2020-10-09 10:05:26 +00:00
9855311739 fix(core): update 2020-10-09 10:05:26 +00:00
1453abcd5f 2.0.10 2020-07-08 02:15:14 +00:00
99afb573cd fix(core): update 2020-07-08 02:15:14 +00:00
94360ff1da 2.0.9 2020-06-25 23:40:30 +00:00
3fd2075c26 fix(core): update 2020-06-25 23:40:29 +00:00
5 changed files with 6852 additions and 862 deletions

7654
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webrequest", "name": "@pushrocks/webrequest",
"version": "2.0.8", "version": "2.0.11",
"private": false, "private": false,
"description": "securely request from browsers", "description": "securely request from browsers",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -14,18 +14,19 @@
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.69", "@gitzone/tsbundle": "^1.0.72",
"@gitzone/tstest": "^1.0.33", "@gitzone/tstest": "^1.0.38",
"@pushrocks/smartexpress": "^3.0.72", "@pushrocks/smartexpress": "^3.0.73",
"@pushrocks/tapbundle": "^3.2.1", "@pushrocks/tapbundle": "^3.2.7",
"@types/node": "^14.0.14", "@types/node": "^14.0.19",
"node-fetch": "^2.6.0",
"tslint": "^6.1.2", "tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.9", "@pushrocks/smartdelay": "^2.0.9",
"@pushrocks/smartenv": "^4.0.10" "@pushrocks/smartenv": "^4.0.10",
"@pushrocks/smartjson": "^4.0.5",
"node-fetch": "^2.6.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@ -38,5 +39,8 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

16
test/test.browser.ts Normal file
View File

@ -0,0 +1,16 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as webrequest from '../ts/index';
tap.test('first test', async tools => {
const done = tools.defer();
const response = await new webrequest.WebRequest().request([
'https://lossless.com'
], {
method: 'GET'
}).catch(e => {
done.resolve();
});
await done.promise;
});
tap.start();

View File

@ -21,7 +21,9 @@ export class WebRequest {
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
method: 'GET' method: 'GET'
}); });
return response.json(); const responseText = await response.text();
const responseResult = plugins.smartjson.parse(responseText);
return responseResult;
} }
/** /**
@ -29,10 +31,12 @@ export class WebRequest {
*/ */
public async postJson(urlArg: string, requestBody?: any) { public async postJson(urlArg: string, requestBody?: any) {
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
body: JSON.stringify(requestBody), body: plugins.smartjson.stringify(requestBody),
method: 'POST' method: 'POST'
}); });
return response.json(); const responseText = await response.text();
const responseResult = plugins.smartjson.parse(responseText);
return responseResult;
} }
/** /**
@ -40,10 +44,12 @@ export class WebRequest {
*/ */
public async putJson(urlArg: string, requestBody?: any) { public async putJson(urlArg: string, requestBody?: any) {
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
body: JSON.stringify(requestBody), body: plugins.smartjson.stringify(requestBody),
method: 'PUT' method: 'PUT'
}); });
return response.json(); const responseText = await response.text();
const responseResult = plugins.smartjson.parse(responseText);
return responseResult;
} }
/** /**
@ -53,7 +59,9 @@ export class WebRequest {
const response: Response = await this.request(urlArg, { const response: Response = await this.request(urlArg, {
method: 'GET' method: 'GET'
}); });
return response.json(); const responseText = await response.text();
const responseResult = plugins.smartjson.parse(responseText);
return responseResult;
} }
/** /**
@ -122,7 +130,6 @@ export class WebRequest {
}; };
const finalResponse: Response = await doRequest(allUrls[usedUrlIndex]); const finalResponse: Response = await doRequest(allUrls[usedUrlIndex]);
console.log(finalResponse);
return finalResponse; return finalResponse;
} }
} }

View File

@ -1,4 +1,5 @@
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
import * as smartenv from '@pushrocks/smartenv'; import * as smartenv from '@pushrocks/smartenv';
import * as smartjson from '@pushrocks/smartjson';
export { smartdelay, smartenv }; export { smartdelay, smartenv, smartjson };