Fixing some bugs and updating dependencies

This commit is contained in:
Fabian 2019-07-05 14:25:50 +02:00
parent 4b7c9ec6cd
commit 38b2cd8fa4
5 changed files with 206 additions and 1283 deletions

1433
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@hibas123/secure-file-wrapper",
"version": "2.4.0",
"version": "2.5.0",
"main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT",
@ -12,18 +12,18 @@
"test": "mocha lib/test.js"
},
"dependencies": {
"@hibas123/utils": "^2.0.0",
"cross-fetch": "^3.0.1",
"@hibas123/utils": "^2.1.0",
"cross-fetch": "^3.0.4",
"uuid": "^3.3.2"
},
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/mocha": "^5.2.6",
"@types/node": "^11.11.6",
"@types/node-fetch": "^2.1.7",
"@types/uuid": "^3.4.4",
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.12",
"@types/node-fetch": "^2.3.7",
"@types/uuid": "^3.4.5",
"chai": "^4.1.2",
"mocha": "^6.0.2",
"typescript": "^3.3.4000"
"mocha": "^6.1.4",
"typescript": "^3.5.2"
}
}
}

View File

@ -84,8 +84,10 @@ function statusParser(res: Response) {
}
}
export type JWTCallback = (err: Error | null | string, jwt: string) => void;
export default class SecureFileWrapper {
private _jwtObservableServer: Observable<(jwt: string) => void> = new Observable();
private _jwtObservableServer: Observable<JWTCallback> = new Observable();
jwtObservable = this._jwtObservableServer.getPublicApi();
private jwt: string;
@ -103,10 +105,18 @@ export default class SecureFileWrapper {
public async getJWT() {
if (!this.auth_lock.locked) {
let lock = await this.auth_lock.getLock();
this._jwtObservableServer.send((jwt: string) => {
this.jwt = jwt;
lock.release();
});
await new Promise((yes, no) => {
this._jwtObservableServer.send((err: Error | null | string, jwt: string) => {
if (err) {
this.jwt = undefined;
no(err);
}
else {
this.jwt = jwt;
yes();
}
});
}).finally(() => lock.release())
}
await this.auth_lock.getLock().then(lock => lock.release())
@ -232,4 +242,9 @@ export default class SecureFileWrapper {
async restore(id: string, version: string) {
await this.makeRequest(`/files/${id}/history/${version}/restore`, "PUT", {});
}
async clean(id: string, val: number | Date): Promise<void> {
let query = typeof val === "number" ? { count: val } : { date: val.toISOString() };
return this.makeRequest(`/files/${id}/history/clean`, "PUT", query);
}
}

View File

@ -167,7 +167,7 @@ function test(sf: SecureFile) {
describe("SecureFile Tests", function () {
let sf = new SecureFile("http://localhost:3004");
sf.jwtObservable.subscribe((callback) => {
callback("TESTJWT");
callback(null, "TESTJWT");
})
test(sf)
})

View File

@ -1,9 +1,12 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"target": "es6",
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
"module": "commonjs",
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true,
/* Generates corresponding '.d.ts' file. */
"lib": [
"es6",
"dom"