@pushrocks/webrequest
Advanced tools
Comparing version 1.0.7 to 2.0.0
@@ -5,14 +5,15 @@ /** | ||
export declare class WebRequest { | ||
getJson(urlArg: string | string[], requestBody?: any): Promise<any>; | ||
/** | ||
* gets json | ||
* postJson | ||
*/ | ||
getJson(url: string | string[]): Promise<void>; | ||
postJson(urlArg: string, requestBody?: any): Promise<any>; | ||
/** | ||
* postJson | ||
* put js | ||
*/ | ||
postJson(): void; | ||
putJson(urlArg: string, requestBody?: any): Promise<any>; | ||
/** | ||
* put js | ||
*/ | ||
putJson(): void; | ||
deleteJson(urlArg: string, requestBody?: any): Promise<any>; | ||
/** | ||
@@ -24,3 +25,3 @@ * | ||
body?: any; | ||
}): Promise<any>; | ||
}): Promise<Response>; | ||
} |
@@ -16,16 +16,47 @@ "use strict"; | ||
class WebRequest { | ||
getJson(urlArg, requestBody) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
}); | ||
} | ||
/** | ||
* gets json | ||
* postJson | ||
*/ | ||
getJson(url) { | ||
return __awaiter(this, void 0, void 0, function* () { }); | ||
postJson(urlArg, requestBody) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
}); | ||
} | ||
/** | ||
* postJson | ||
* put js | ||
*/ | ||
postJson() { } | ||
putJson(urlArg, requestBody) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
}); | ||
} | ||
/** | ||
* put js | ||
*/ | ||
putJson() { } | ||
deleteJson(urlArg, requestBody) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
}); | ||
} | ||
/** | ||
@@ -46,3 +77,4 @@ * | ||
const requestHistory = []; // keep track of the request history | ||
const doHistoryCheck = (// check history for a | ||
const doHistoryCheck = ( | ||
// check history for a | ||
historyEntryTypeArg) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -59,3 +91,3 @@ requestHistory.push(historyEntryTypeArg); | ||
} | ||
if (numOfHistoryType > (2 * allUrls.length * usedUrlIndex)) { | ||
if (numOfHistoryType > 2 * allUrls.length * usedUrlIndex) { | ||
usedUrlIndex++; | ||
@@ -82,2 +114,3 @@ } | ||
yield doHistoryCheck(response.status.toString()); | ||
// tslint:disable-next-line: no-return-await | ||
return yield doRequest(allUrls[usedUrlIndex]); | ||
@@ -88,3 +121,3 @@ } | ||
console.log(finalResponse); | ||
return JSON.parse(yield finalResponse.text()); | ||
return finalResponse; | ||
}); | ||
@@ -94,2 +127,2 @@ } | ||
exports.WebRequest = WebRequest; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsZ0RBQWdEO0FBRWhEOztHQUVHO0FBQ0gsTUFBYSxVQUFVO0lBQ3JCOztPQUVHO0lBQ0csT0FBTyxDQUFDLEdBQXNCOzhEQUFHLENBQUM7S0FBQTtJQUV4Qzs7T0FFRztJQUNILFFBQVEsS0FBSSxDQUFDO0lBRWI7O09BRUc7SUFDSCxPQUFPLEtBQUksQ0FBQztJQUVaOztPQUVHO0lBQ0csT0FBTyxDQUNYLE1BQXlCLEVBQ3pCLFVBR0M7O1lBRUQsSUFBSSxPQUFpQixDQUFDO1lBQ3RCLElBQUksWUFBWSxHQUFHLENBQUMsQ0FBQztZQUVyQix3QkFBd0I7WUFDeEIsSUFBSSxLQUFLLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxFQUFFO2dCQUN6QixPQUF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sTUFBTSxjQUFjLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDO29CQUNqRCw0Q0FBNEM7b0JBQzVDLE9BQU8sTUFBTSxTQUFTLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUM7aUJBQy9DO1lBQ0gsQ0FBQyxDQUFBLENBQUM7WUFFRixNQUFNLGFBQWEsR0FBYSxNQUFNLFNBQVMsQ0FBQyxNQUFNLENBQUMsWUFBWSxDQUFDLENBQUMsQ0FBQztZQUN0RSxPQUFPLENBQUMsR0FBRyxDQUFDLGFBQWEsQ0FBQyxDQUFDO1lBQzNCLE9BQU8sYUFBYSxDQUFDO1FBQ3ZCLENBQUM7S0FBQTtDQUNGO0FBL0dELGdDQStHQyJ9 |
@@ -5,2 +5,2 @@ "use strict"; | ||
exports.smartdelay = smartdelay; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2VicmVxdWVzdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvd2VicmVxdWVzdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsb0RBQW9EO0FBR2xELGdDQUFVIn0= | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2VicmVxdWVzdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvd2VicmVxdWVzdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsb0RBQW9EO0FBRTNDLGdDQUFVIn0= |
@@ -5,3 +5,13 @@ { | ||
"npmAccessLevel": "public" | ||
}, | ||
"gitzone": { | ||
"module": { | ||
"githost": "gitlab.com", | ||
"gitscope": "pushrocks", | ||
"gitrepo": "webrequest", | ||
"shortDescription": "securely request from browsers", | ||
"npmPackagename": "@pushrocks/webrequest", | ||
"license": "MIT" | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "@pushrocks/webrequest", | ||
"version": "1.0.7", | ||
"version": "2.0.0", | ||
"private": false, | ||
@@ -22,8 +22,18 @@ "description": "securely request from browsers", | ||
"node-fetch": "^2.3.0", | ||
"tslint": "^5.11.0", | ||
"tslint-config-prettier": "^1.15.0" | ||
"tslint": "^5.17.0", | ||
"tslint-config-prettier": "^1.18.0" | ||
}, | ||
"dependencies": { | ||
"@pushrocks/smartdelay": "^2.0.2" | ||
} | ||
}, | ||
"files": [ | ||
"ts/*", | ||
"ts_web/*", | ||
"dist/*", | ||
"dist_web/*", | ||
"assets/*", | ||
"cli.js", | ||
"npmextra.json", | ||
"readme.md" | ||
] | ||
} |
@@ -7,11 +7,31 @@ import * as plugins from './webrequest.plugins'; | ||
export class WebRequest { | ||
public async getJson(urlArg: string | string[], requestBody?: any) { | ||
const response: Response = await this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
} | ||
/** | ||
* gets json | ||
* postJson | ||
*/ | ||
async getJson(url: string | string[]) {} | ||
public async postJson(urlArg: string, requestBody?: any) { | ||
const response: Response = await this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
} | ||
/** | ||
* postJson | ||
* put js | ||
*/ | ||
postJson() {} | ||
public async putJson(urlArg: string, requestBody?: any) { | ||
const response: Response = await this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
} | ||
@@ -21,3 +41,9 @@ /** | ||
*/ | ||
putJson() {} | ||
public async deleteJson(urlArg: string, requestBody?: any) { | ||
const response: Response = await this.request(urlArg, { | ||
body: requestBody, | ||
method: 'GET' | ||
}); | ||
return response.json(); | ||
} | ||
@@ -33,3 +59,3 @@ /** | ||
} | ||
) { | ||
): Promise<Response> { | ||
let allUrls: string[]; | ||
@@ -47,3 +73,4 @@ let usedUrlIndex = 0; | ||
const doHistoryCheck = async ( // check history for a | ||
const doHistoryCheck = async ( | ||
// check history for a | ||
historyEntryTypeArg: string | ||
@@ -53,6 +80,4 @@ ) => { | ||
if (historyEntryTypeArg === '429') { | ||
console.log('got 429, so waiting a little bit.') | ||
await plugins.smartdelay.delayFor( | ||
Math.floor(Math.random() * (2000 - 1000 +1)) + 1000 | ||
); // wait between 1 and 10 seconds | ||
console.log('got 429, so waiting a little bit.'); | ||
await plugins.smartdelay.delayFor(Math.floor(Math.random() * (2000 - 1000 + 1)) + 1000); // wait between 1 and 10 seconds | ||
} | ||
@@ -64,3 +89,3 @@ | ||
} | ||
if (numOfHistoryType > (2 * allUrls.length * usedUrlIndex)) { | ||
if (numOfHistoryType > 2 * allUrls.length * usedUrlIndex) { | ||
usedUrlIndex++; | ||
@@ -75,3 +100,3 @@ } | ||
} | ||
const response = await fetch(urlToUse, { | ||
@@ -90,2 +115,3 @@ method: optionsArg.method, | ||
await doHistoryCheck(response.status.toString()); | ||
// tslint:disable-next-line: no-return-await | ||
return await doRequest(allUrls[usedUrlIndex]); | ||
@@ -96,5 +122,5 @@ } | ||
const finalResponse: Response = await doRequest(urlArg[usedUrlIndex]); | ||
console.log(finalResponse) | ||
return JSON.parse(await finalResponse.text()); | ||
console.log(finalResponse); | ||
return finalResponse; | ||
} | ||
} |
import * as smartdelay from '@pushrocks/smartdelay'; | ||
export { | ||
smartdelay | ||
} | ||
export { smartdelay }; |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
16148
1
27
10
273